vscode-api

vscode namespace API

commands

Namespace for dealing with commands. In short, a command is a function with aunique identifier. The function is sometimes also called command handler.

Commands can be added to the editor using the registerCommandand registerTextEditorCommand functions. Commandscan be executed manually or from a UI gesture. Those are:

  • palette - Use the commands-section in package.json to make a command show inthe command palette.
  • keybinding - Use the keybindings-section in package.json to enablekeybindingsfor your extension.Commands from other extensions and from the editor itself are accessible to an extension. However,when invoking an editor command not all argument types are supported.

This is a sample that registers a command handler and adds an entry for that command to the palette. Firstregister a command handler with the identfier extension.sayHello.

  1. commands.registerCommand('extension.sayHello', () => {
  2. window.showInformationMessage('Hello World!');
  3. });

Second, bind the command identfier to a title under which it will show in the palette (package.json).

  1. {
  2. "contributes": {
  3. "commands": [{
  4. "command": "extension.sayHello",
  5. "title": "Hello World"
  6. }]
  7. }

Functions

</a>executeCommand<T>(command: string, …rest: any[]): Thenable<T></span>

Executes the command denoted by the given command identifier.

When executing an editor command not all types are allowed tobe passed as arguments. Allowed are the primitive types string, boolean,number, undefined, and null, as well as classes defined in this API.There are no restrictions when executing commands that have been contributedby extensions.

ParameterDescription
command: stringIdentifier of the command to execute.
…rest: any[]Parameters passed to the command function.
ReturnsDescription
Thenable<T>A thenable that resolves to the returned value of the given command. undefined whenthe command handler function doesn't return anything.

</a>getCommands(filterInternal?: boolean): Thenable<string[]></span>

Retrieve the list of all available commands. Commands starting an underscore aretreated as internal commands.

ParameterDescription
filterInternal?: booleanSet true to not see internal commands (starting with an underscore)
ReturnsDescription
Thenable<string[]>Thenable that resolves to a list of command ids.

</a>registerCommand(command: string, callback: (args: any[]) => any, thisArg?: any): Disposable</span>

Registers a command that can be invoked via a keyboard shortcut,a menu item, an action, or directly.

Registering a command with an existing command identifier twicewill cause an error.

ParameterDescription
command: stringA unique identifier for the command.
callback: (args: any[]) => anyA command handler function.
thisArg?: anyThe this context used when invoking the handler function.
ReturnsDescription
DisposableDisposable which unregisters this command on disposal.

</a>registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit) => void, thisArg?: any): Disposable</span>

Registers a text editor command that can be invoked via a keyboard shortcut,a menu item, an action, or directly.

Text editor commands are different from ordinary commands asthey only execute when there is an active editor when the command is called. Also, thecommand handler of an editor command has access to the active editor and to anedit-builder.

ParameterDescription
command: stringA unique identifier for the command.
callback: (textEditor: TextEditor, edit: TextEditorEdit) => voidA command handler function with access to an editor and an edit.
thisArg?: anyThe this context used when invoking the handler function.
ReturnsDescription
DisposableDisposable which unregisters this command on disposal.

env

Namespace describing the environment the editor runs in.

Variables

</a>language: string</span>

Represents the preferred user-language, like de-CH, fr, or en-US.

  • readonly

</a>machineId: string</span>

A unique identifier for the computer.

  • readonly

</a>sessionId: string</span>

A unique identifier for the current session.Changes each time the editor is started.

  • readonly

extensions

Namespace for dealing with installed extensions. Extensions are representedby an extension-interface which allows to reflect on them.

Extension writers can provide APIs to other extensions by returning their API publicsurface from the activate-call.

  1. export function activate(context: vscode.ExtensionContext) {
  2. let api = {
  3. sum(a, b) {
  4. return a + b;
  5. },
  6. mul(a, b) {
  7. return a * b;
  8. }
  9. };
  10. // 'export' public api-surface
  11. return api;
  12. }

When depending on the API of another extension add an extensionDependency-entryto package.json, and use the getExtension-functionand the exports-property, like below:

  1. let mathExt = extensions.getExtension('genius.math');
  2. let importedApi = mathExt.exports;
  3. console.log(importedApi.mul(42, 1));

Variables

</a>all: Extension<any>[]</span>

All extensions currently known to the system.

Functions

</a>getExtension(extensionId: string): Extension<any></span>

Get an extension by its full identifier in the form of: publisher.name.

ParameterDescription
extensionId: stringAn extension identifier.
ReturnsDescription
Extension<any>An extension or undefined.

</a>getExtension<T>(extensionId: string): Extension<T></span>

Get an extension its full identifier in the form of: publisher.name.

ParameterDescription
extensionId: stringAn extension identifier.
ReturnsDescription
Extension<T>An extension or undefined.

languages

Namespace for participating in language-specific editor features,like IntelliSense, code actions, diagnostics etc.

Many programming languages exist and there is huge variety in syntaxes, semantics, and paradigms. Despite that, featureslike automatic word-completion, code navigation, or code checking have become popular across different tools for differentprogramming languages.

The editor provides an API that makes it simple to provide such common features by having all UI and actions already in place andby allowing you to participate by providing data only. For instance, to contribute a hover all you have to do is provide a functionthat can be called with a TextDocument and a Position returning hover info. The rest, like tracking themouse, positioning the hover, keeping the hover stable etc. is taken care of by the editor.

  1. languages.registerHoverProvider('javascript', {
  2. provideHover(document, position, token) {
  3. return new Hover('I am a hover!');
  4. }
  5. });

Registration is done using a document selector which is either a language id, like javascript ora more complex filter like { language: 'typescript', scheme: 'file' }. Matching a document against sucha selector will result in a score that is used to determine if and how a provider shall be used. Whenscores are equal the provider that came last wins. For features that allow full arity, like hover,the score is only checked to be >0, for other features, like IntelliSense thescore is used for determining the order in which providers are asked to participate.

Functions

</a>createDiagnosticCollection(name?: string): DiagnosticCollection</span>

Create a diagnostics collection.

ParameterDescription
name?: stringThe name of the collection.
ReturnsDescription
DiagnosticCollectionA new diagnostic collection.

</a>getLanguages(): Thenable<string[]></span>

Return the identifiers of all known languages.

ReturnsDescription
Thenable<string[]>Promise resolving to an array of identifier strings.

</a>match(selector: DocumentSelector, document: TextDocument): number</span>

Compute the match between a document selector and a document. Valuesgreater than zero mean the selector matches the document. The more individual matches a selectorand a document have, the higher the score is. These are the abstract rules given a selector:

  1. (1) When selector is an array, return the maximum individual result.
  2. (2) When selector is a string match that against the [languageId](#TextDocument.languageId).
  3. (2.1) When both are equal score is `10`,
  4. (2.2) When the selector is `*` score is `5`,
  5. (2.3) Else score is `0`.
  6. (3) When selector is a [filter](#DocumentFilter) every property must score higher `0`. Iff the score is the sum of the following:
  7. (3.1) When [language](#DocumentFilter.language) is set apply rules from #2, when `0` the total score is `0`.
  8. (3.2) When [scheme](#Document.scheme) is set and equals the [uri](#TextDocument.uri)-scheme add `10` to the score, else the total score is `0`.
  9. (3.3) When [pattern](#Document.pattern) is set
  10. (3.3.1) pattern eqauls the [uri](#TextDocument.uri)-fsPath add `10` to the score,
  11. (3.3.1) if the pattern matches as glob-pattern add `5` to the score,
  12. (3.3.1) the total score is `0`
ParameterDescription
selector: DocumentSelectorA document selector.
document: TextDocumentA text document.
ReturnsDescription
numberA number >0 when the selector matches and 0 when the selector does not match.

</a>registerCodeActionsProvider(selector: DocumentSelector, provider: CodeActionProvider): Disposable</span>

Register a code action provider.

Multiple providers can be registered for a language. In that case providers are asked inparallel and the results are merged. A failing provider (rejected promise or exception) willnot cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: CodeActionProviderA code action provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerCodeLensProvider(selector: DocumentSelector, provider: CodeLensProvider): Disposable</span>

Register a code lens provider.

Multiple providers can be registered for a language. In that case providers are asked inparallel and the results are merged. A failing provider (rejected promise or exception) willnot cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: CodeLensProviderA code lens provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerCompletionItemProvider(selector: DocumentSelector, provider: CompletionItemProvider, …triggerCharacters: string[]): Disposable</span>

Register a completion provider.

Multiple providers can be registered for a language. In that case providers are sortedby their score and groups of equal score are sequentially asked forcompletion items. The process stops when one or many providers of a group return aresult. A failing provider (rejected promise or exception) will not fail the wholeoperation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: CompletionItemProviderA completion provider.
…triggerCharacters: string[]Trigger completion when the user types one of the characters, like . or :.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerDefinitionProvider(selector: DocumentSelector, provider: DefinitionProvider): Disposable</span>

Register a definition provider.

Multiple providers can be registered for a language. In that case providers are asked inparallel and the results are merged. A failing provider (rejected promise or exception) willnot cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: DefinitionProviderA definition provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerDocumentFormattingEditProvider(selector: DocumentSelector, provider: DocumentFormattingEditProvider): Disposable</span>

Register a formatting provider for a document.

Multiple providers can be registered for a language. In that case providers are sortedby their score and the result of best-matching provider is used. Failureof the selected provider will cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: DocumentFormattingEditProviderA document formatting edit provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerDocumentHighlightProvider(selector: DocumentSelector, provider: DocumentHighlightProvider): Disposable</span>

Register a document highlight provider.

Multiple providers can be registered for a language. In that case providers are sortedby their score and groups sequentially asked for document highlights.The process stops when a provider returns a non-falsy or non-failure result.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: DocumentHighlightProviderA document highlight provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerDocumentRangeFormattingEditProvider(selector: DocumentSelector, provider: DocumentRangeFormattingEditProvider): Disposable</span>

Register a formatting provider for a document range.

Multiple providers can be registered for a language. In that case providers are sortedby their score and the result of best-matching provider is used. Failureof the selected provider will cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: DocumentRangeFormattingEditProviderA document range formatting edit provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerDocumentSymbolProvider(selector: DocumentSelector, provider: DocumentSymbolProvider): Disposable</span>

Register a document symbol provider.

Multiple providers can be registered for a language. In that case providers are asked inparallel and the results are merged. A failing provider (rejected promise or exception) willnot cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: DocumentSymbolProviderA document symbol provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerHoverProvider(selector: DocumentSelector, provider: HoverProvider): Disposable</span>

Register a hover provider.

Multiple providers can be registered for a language. In that case providers are asked inparallel and the results are merged. A failing provider (rejected promise or exception) willnot cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: HoverProviderA hover provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerOnTypeFormattingEditProvider(selector: DocumentSelector, provider: OnTypeFormattingEditProvider, firstTriggerCharacter: string, …moreTriggerCharacter: string[]): Disposable</span>

Register a formatting provider that works on type. The provider is active when the user enables the setting editor.formatOnType.

Multiple providers can be registered for a language. In that case providers are sortedby their score and the result of best-matching provider is used. Failureof the selected provider will cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: OnTypeFormattingEditProviderAn on type formatting edit provider.
firstTriggerCharacter: stringA character on which formatting should be triggered, like }.
…moreTriggerCharacter: string[]More trigger characters.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerReferenceProvider(selector: DocumentSelector, provider: ReferenceProvider): Disposable</span>

Register a reference provider.

Multiple providers can be registered for a language. In that case providers are asked inparallel and the results are merged. A failing provider (rejected promise or exception) willnot cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: ReferenceProviderA reference provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerRenameProvider(selector: DocumentSelector, provider: RenameProvider): Disposable</span>

Register a reference provider.

Multiple providers can be registered for a language. In that case providers are sortedby their score and the result of best-matching provider is used. Failureof the selected provider will cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: RenameProviderA rename provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerSignatureHelpProvider(selector: DocumentSelector, provider: SignatureHelpProvider, …triggerCharacters: string[]): Disposable</span>

Register a signature help provider.

Multiple providers can be registered for a language. In that case providers are sortedby their score and the result of best-matching provider is used. Failureof the selected provider will cause a failure of the whole operation.

ParameterDescription
selector: DocumentSelectorA selector that defines the documents this provider is applicable to.
provider: SignatureHelpProviderA signature help provider.
…triggerCharacters: string[]Trigger signature help when the user types one of the characters, like , or (.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>registerWorkspaceSymbolProvider(provider: WorkspaceSymbolProvider): Disposable</span>

Register a workspace symbol provider.

Multiple providers can be registered for a language. In that case providers are asked inparallel and the results are merged. A failing provider (rejected promise or exception) willnot cause a failure of the whole operation.

ParameterDescription
provider: WorkspaceSymbolProviderA workspace symbol provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>setLanguageConfiguration(language: string, configuration: LanguageConfiguration): Disposable</span>

Set a language configuration for a language.

ParameterDescription
language: stringA language identifier like typescript.
configuration: LanguageConfigurationLanguage configuration.
ReturnsDescription
DisposableA disposable that unsets this configuration.

window

Namespace for dealing with the current window of the editor. That is visibleand active editors, as well as, UI elements to show messages, selections, andasking for user input.

Variables

</a>activeTextEditor: TextEditor</span>

The currently active editor or undefined. The active editor is the onethat currently has focus or, when none has focus, the one that has changedinput most recently.

</a>visibleTextEditors: TextEditor[]</span>

The currently visible editors or an empty array.

Events

</a>onDidChangeActiveTextEditor: Event<TextEditor></span>

An event which fires when the active editorhas changed.

</a>onDidChangeTextEditorOptions: Event<TextEditorOptionsChangeEvent></span>

An event which fires when the options of an editor have changed.

</a>onDidChangeTextEditorSelection: Event<TextEditorSelectionChangeEvent></span>

An event which fires when the selection in an editor has changed.

</a>onDidChangeTextEditorViewColumn: Event<TextEditorViewColumnChangeEvent></span>

An event which fires when the view column of an editor das changed.

Functions

</a>createOutputChannel(name: string): OutputChannel</span>

Create a new output channel with the given name.

ParameterDescription
name: stringHuman-readable string which will be used to represent the channel in the UI.
ReturnsDescription
OutputChannel

</a>createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem</span>

Creates a status bar item.

ParameterDescription
alignment?: StatusBarAlignmentThe alignment of the item.
priority?: numberThe priority of the item. Higher values mean the item should be shown more to the left.
ReturnsDescription
StatusBarItemA new status bar item.

</a>createTextEditorDecorationType(options: DecorationRenderOptions): TextEditorDecorationType</span>

Create a TextEditorDecorationType that can be used to add decorations to text editors.

ParameterDescription
options: DecorationRenderOptionsRendering options for the decoration type.
ReturnsDescription
TextEditorDecorationTypeA new decoration type instance.

</a>setStatusBarMessage(text: string): Disposable</span>

Set a message to the status bar. This is a short hand for the more powerfulstatus bar items.

ParameterDescription
text: stringThe message to show, support icon subtitution as in status bar items.
ReturnsDescription
DisposableA disposable which hides the status bar message.

</a>setStatusBarMessage(text: string, hideAfterTimeout: number): Disposable</span>

Set a message to the status bar. This is a short hand for the more powerfulstatus bar items.

ParameterDescription
text: stringThe message to show, support icon subtitution as in status bar items.
hideAfterTimeout: numberTimeout in milliseconds after which the message will be disposed.
ReturnsDescription
DisposableA disposable which hides the status bar message.

</a>setStatusBarMessage(text: string, hideWhenDone: Thenable<any>): Disposable</span>

Set a message to the status bar. This is a short hand for the more powerfulstatus bar items.

ParameterDescription
text: stringThe message to show, support icon subtitution as in status bar items.
hideWhenDone: Thenable<any>Thenable on which completion (resolve or reject) the message will be disposed.
ReturnsDescription
DisposableA disposable which hides the status bar message.

</a>showErrorMessage(message: string, …items: string[]): Thenable<string></span>

Show an error message.

ParameterDescription
message: stringThe message to show.
…items: string[]A set of items that will be rendered as actions in the message.
ReturnsDescription
Thenable<string>A thenable that resolves to the selected item or undefined when being dismissed.

</a>showErrorMessage<T extends MessageItem>(message: string, …items: T[]): Thenable<T></span>

Show an error message.

ParameterDescription
message: stringThe message to show.
…items: T[]A set of items that will be rendered as actions in the message.
ReturnsDescription
Thenable<T>A thenable that resolves to the selected item or undefined when being dismissed.

</a>showInformationMessage(message: string, …items: string[]): Thenable<string></span>

Show an information message to users. Optionally provide an array of items which will be presented asclickable buttons.

ParameterDescription
message: stringThe message to show.
…items: string[]A set of items that will be rendered as actions in the message.
ReturnsDescription
Thenable<string>A thenable that resolves to the selected item or undefined when being dismissed.

</a>showInformationMessage<T extends MessageItem>(message: string, …items: T[]): Thenable<T></span>

Show an information message.

ParameterDescription
message: stringThe message to show.
…items: T[]A set of items that will be rendered as actions in the message.
ReturnsDescription
Thenable<T>A thenable that resolves to the selected item or undefined when being dismissed.

</a>showInputBox(options?: InputBoxOptions): Thenable<string></span>

Opens an input box to ask the user for input.

The returned value will be undefined if the input box was canceled (e.g. pressing ESC). Otherwise thereturned value will be the string typed by the user or an empty string if the user did not typeanything but dismissed the input box with OK.

ParameterDescription
options?: InputBoxOptionsConfigures the behavior of the input box.
ReturnsDescription
Thenable<string>A promise that resolves to a string the user provided or to undefined in case of dismissal.

</a>showQuickPick(items: string[] | Thenable<string[]>, options?: QuickPickOptions): Thenable<string></span>

Shows a selection list.

ParameterDescription
items: string[] | Thenable<string[]>An array of strings, or a promise that resolves to an array of strings.
options?: QuickPickOptionsConfigures the behavior of the selection list.
ReturnsDescription
Thenable<string>A promise that resolves to the selection or undefined.

</a>showQuickPick<T extends QuickPickItem>(items: T[] | Thenable<T[]>, options?: QuickPickOptions): Thenable<T></span>

Shows a selection list.

ParameterDescription
items: T[] | Thenable<T[]>An array of items, or a promise that resolves to an array of items.
options?: QuickPickOptionsConfigures the behavior of the selection list.
ReturnsDescription
Thenable<T>A promise that resolves to the selected item or undefined.

</a>showTextDocument(document: TextDocument, column?: ViewColumn, preserveFocus?: boolean): Thenable<TextEditor></span>

Show the given document in a text editor. A column can be providedto control where the editor is being shown. Might change the active editor.

ParameterDescription
document: TextDocumentA text document to be shown.
column?: ViewColumnA view column in which the editor should be shown. The default is the one, other valuesare adjusted to be Min(column, columnCount + 1).
preserveFocus?: booleanWhen true the editor will not take focus.
ReturnsDescription
Thenable<TextEditor>A promise that resolves to an editor.

</a>showWarningMessage(message: string, …items: string[]): Thenable<string></span>

Show a warning message.

ParameterDescription
message: stringThe message to show.
…items: string[]A set of items that will be rendered as actions in the message.
ReturnsDescription
Thenable<string>A thenable that resolves to the selected item or undefined when being dismissed.

</a>showWarningMessage<T extends MessageItem>(message: string, …items: T[]): Thenable<T></span>

Show a warning message.

ParameterDescription
message: stringThe message to show.
…items: T[]A set of items that will be rendered as actions in the message.
ReturnsDescription
Thenable<T>A thenable that resolves to the selected item or undefined when being dismissed.

workspace

Namespace for dealing with the current workspace. A workspace is the representationof the folder that has been opened. There is no workspace when just a file but not afolder has been opened.

The workspace offers support for listening to fsevents and for finding files. Both perform well and run _outside_the editor-process so that they should be always used instead of nodejs-equivalents.

Variables

</a>rootPath: string</span>

The folder that is open in VS Code. undefined when no folderhas been opened.

  • readonly

</a>textDocuments: TextDocument[]</span>

All text documents currently known to the system.

  • readonly

Events

</a>onDidChangeConfiguration: Event<void></span>

An event that is emitted when the configuration changed.

</a>onDidChangeTextDocument: Event<TextDocumentChangeEvent></span>

An event that is emitted when a text document is changed.

</a>onDidCloseTextDocument: Event<TextDocument></span>

An event that is emitted when a text document is disposed.

</a>onDidOpenTextDocument: Event<TextDocument></span>

An event that is emitted when a text document is opened.

</a>onDidSaveTextDocument: Event<TextDocument></span>

An event that is emitted when a text document is saved to disk.

Functions

</a>applyEdit(edit: WorkspaceEdit): Thenable<boolean></span>

Make changes to one or many resources as defined by the givenworkspace edit.

When applying a workspace edit, the editor implements an 'all-or-nothing'-strategy,that means failure to load one document or make changes to one document will causethe edit to be rejected.

ParameterDescription
edit: WorkspaceEditA workspace edit.
ReturnsDescription
Thenable<boolean>A thenable that resolves when the edit could be applied.

</a>asRelativePath(pathOrUri: string | Uri): string</span>

Returns a path that is relative to the workspace root.

When there is no workspace root or when the pathis not a child of that folder, the input is returned.

ParameterDescription
pathOrUri: string | UriA path or uri. When a uri is given its fsPath is used.
ReturnsDescription
stringA path relative to the root or the input.

</a>createFileSystemWatcher(globPattern: string, ignoreCreateEvents?: boolean, ignoreChangeEvents?: boolean, ignoreDeleteEvents?: boolean): FileSystemWatcher</span>

Creates a file system watcher.

A glob pattern that filters the file events must be provided. Optionally, flags to ignore certainkinds of events can be provided. To stop listening to events the watcher must be disposed.

ParameterDescription
globPattern: stringA glob pattern that is applied to the names of created, changed, and deleted files.
ignoreCreateEvents?: booleanIgnore when files have been created.
ignoreChangeEvents?: booleanIgnore when files have been changed.
ignoreDeleteEvents?: booleanIgnore when files have been deleted.
ReturnsDescription
FileSystemWatcherA new file system watcher instance.

</a>findFiles(include: string, exclude: string, maxResults?: number, token?: CancellationToken): Thenable<Uri[]></span>

Find files in the workspace.

  • sample - findFiles('∕*.js', '∕node_modules∕**', 10)
ParameterDescription
include: stringA glob pattern that defines the files to search for.
exclude: stringA glob pattern that defines files and folders to exclude.
maxResults?: numberAn upper-bound for the result.
token?: CancellationTokenA token that can be used to signal cancellation to the underlying search engine.
ReturnsDescription
Thenable<Uri[]>A thenable that resolves to an array of resource identifiers.

</a>getConfiguration(section?: string): WorkspaceConfiguration</span>

Get a configuration object.

When a section-identifier is provided only that part of the configurationis returned. Dots in the section-identifier are interpreted as child-access,like { myExt: { setting: { doIt: true }}} and getConfiguration('myExt.setting.doIt') === true.

ParameterDescription
section?: stringA dot-separated identifier.
ReturnsDescription
WorkspaceConfigurationThe full workspace configuration or a subset.

</a>openTextDocument(uri: Uri): Thenable<TextDocument></span>

Opens the denoted document from disk. Will return early if thedocument is already open, otherwise the document is loaded and theopen document-event fires.The document to open is denoted by the uri. Two schemes are supported:

file: A file on disk, will be rejected if the file does not exist or cannot be loaded, e.g. 'file:///Users/frodo/r.ini'.untitled: A new file that should be saved on disk, e.g. 'untitled:/Users/frodo/new.js'. The language will be derived from the file name.

Uris with other schemes will make this method return a rejected promise.

ParameterDescription
uri: UriIdentifies the resource to open.
ReturnsDescription
Thenable<TextDocument>A promise that resolves to a document.

</a>openTextDocument(fileName: string): Thenable<TextDocument></span>

A short-hand for openTextDocument(Uri.file(fileName)).

ParameterDescription
fileName: stringA name of a file on disk.
ReturnsDescription
Thenable<TextDocument>A promise that resolves to a document.

</a>registerTextDocumentContentProvider(scheme: string, provider: TextDocumentContentProvider): Disposable</span>

Register a text document content provider.

Only one provider can be registered per scheme.

ParameterDescription
scheme: stringThe uri-scheme to register for.
provider: TextDocumentContentProviderA content provider.
ReturnsDescription
DisposableA disposable that unregisters this provider when being disposed.

</a>saveAll(includeUntitled?: boolean): Thenable<boolean></span>

Save all dirty files.

ParameterDescription
includeUntitled?: booleanAlso save files that have been created during this session.
ReturnsDescription
Thenable<boolean>A thenable that resolves when the files have been saved.

CancellationToken" class="reference-link">CancellationToken

A cancellation token is passed to an asynchronous or long runningoperation to request cancellation, like cancelling a requestfor completion items because the user continued to type.

To get an instance of a CancellationToken use aCancellationTokenSource.

Properties

</a>isCancellationRequested: boolean</span>

Is true when the token has been cancelled, false otherwise.

</a>onCancellationRequested: Event<any></span>

An event which fires upon cancellation.

CancellationTokenSource" class="reference-link">CancellationTokenSource

A cancellation source creates and controls a cancellation token.

Properties

</a>token: CancellationToken</span>

The cancellation token of this source.

Methods

</a>cancel(): void</span>

Signal cancellation on the token.

ReturnsDescription
void

</a>dispose(): void</span>

Dispose object and free resources. Will call cancel.

ReturnsDescription
void

CharacterPair" class="reference-link">CharacterPair

A tuple of two characters, like a pair ofopening and closing brackets.

</a>CharacterPair: [string, string]</span>

CodeActionContext" class="reference-link">CodeActionContext

Contains additional diagnostic information about the context in whicha code action is run.

Properties

</a>diagnostics: Diagnostic[]</span>

An array of diagnostics.

  • readonly

CodeActionProvider" class="reference-link">CodeActionProvider

The code action interface defines the contract between extensions andthe light bulb feature.

A code action can be any command that is known to the system.

Methods

</a>provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): Command[] | Thenable<Command[]></span>

Provide commands for the given document and range.

ParameterDescription
document: TextDocumentThe document in which the command was invoked.
range: RangeThe range for which the command was invoked.
context: CodeActionContextContext carrying additional information.
token: CancellationTokenA cancellation token.
ReturnsDescription
Command[] | Thenable<Command[]>An array of commands or a thenable of such. The lack of a result can besignaled by returning undefined, null, or an empty array.

CodeLens" class="reference-link">CodeLens

A code lens represents a command that should be shown along withsource text, like the number of references, a way to run tests, etc.

A code lens is unresolved when no command is associated to it. For performancereasons the creation of a code lens and resolving should be done to two stages.

Constructors

</a>new CodeLens(range: Range, command?: Command): CodeLens</span>

Creates a new code lens object.

ParameterDescription
range: RangeThe range to which this code lens applies.
command?: CommandThe command associated to this code lens.
ReturnsDescription
CodeLens

Properties

</a>command: Command</span>

The command this code lens represents.

</a>isResolved: boolean</span>

true when there is a command associated.

</a>range: Range</span>

The range in which this code lens is valid. Should only span a single line.

CodeLensProvider" class="reference-link">CodeLensProvider

A code lens provider adds commands to source text. The commands will be shownas dedicated horizontal lines in between the source text.

Methods

</a>provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Thenable<CodeLens[]></span>

Compute a list of lenses. This call should return as fast as possible and ifcomputing the commands is expensive implementors should only return code lens objects with therange set and implement resolve.

ParameterDescription
document: TextDocumentThe document in which the command was invoked.
token: CancellationTokenA cancellation token.
ReturnsDescription
CodeLens[] | Thenable<CodeLens[]>An array of code lenses or a thenable that resolves to such. The lack of a result can besignaled by returning undefined, null, or an empty array.

</a>resolveCodeLens(codeLens: CodeLens, token: CancellationToken): CodeLens | Thenable<CodeLens></span>

This function will be called for each visible code lens, usually when scrolling and aftercalls to compute-lenses.

ParameterDescription
codeLens: CodeLenscode lens that must be resolved.
token: CancellationTokenA cancellation token.
ReturnsDescription
CodeLens | Thenable<CodeLens>The given, resolved code lens or thenable that resolves to such.

Command" class="reference-link">Command

Represents a reference to a command. Provides a title whichwill be used to represent a command in the UI and, optionally,an array of arguments which will be passed to the command handlerfunction when invoked.

Properties

</a>arguments?: any[]</span>

Arguments that the command handler should beinvoked with.

</a>command: string</span>

The identifier of the actual command handler.

</a>title: string</span>

Title of the command, like save.

CommentRule" class="reference-link">CommentRule

Describes how comments for a language work.

Properties

</a>blockComment?: CharacterPair</span>

The block comment character pair, like / block comment &#47;

</a>lineComment?: string</span>

The line comment token, like // this is a comment

CompletionItem" class="reference-link">CompletionItem

A completion item represents a text snippet that isproposed to complete text that is being typed.

Constructors

</a>new CompletionItem(label: string): CompletionItem</span>

Creates a new completion item.

Completion items must have at least a label which thenwill be used as insert text as well as for sorting and filtering.

ParameterDescription
label: stringThe label of the completion.
ReturnsDescription
CompletionItem

Properties

</a>detail: string</span>

A human-readable string with additional informationabout this item, like type or symbol information.

</a>documentation: string</span>

A human-readable string that represents a doc-comment.

</a>filterText: string</span>

A string that should be used when filtering a set ofcompletion items. When falsy the labelis used.

</a>insertText: string</span>

A string that should be inserted in a document when selectingthis completion. When falsy the labelis used.

</a>kind: CompletionItemKind</span>

The kind of this completion item. Based on the kindan icon is chosen by the editor.

</a>label: string</span>

The label of this completion item. By defaultthis is also the text that is inserted when selectingthis completion.

</a>sortText: string</span>

A string that should be used when comparing this itemwith other items. When falsy the labelis used.

</a>textEdit: TextEdit</span>

An edit which is applied to a document when selectingthis completion. When an edit is provided the value ofinsertText is ignored.

The range of the edit must be single-line and one the sameline completions where requested at.

CompletionItemKind" class="reference-link">CompletionItemKind

Completion item kinds.

Enumeration members

Class</span>

Color</span>

Constructor</span>

Enum</span>

Field</span>

File</span>

Function</span>

Interface</span>

Keyword</span>

Method</span>

Module</span>

Property</span>

Reference</span>

Snippet</span>

Text</span>

Unit</span>

Value</span>

Variable</span>

CompletionItemProvider" class="reference-link">CompletionItemProvider

The completion item provider interface defines the contract between extensions andthe IntelliSense.

When computing complete completion items is expensive, providers can optionally implementthe resolveCompletionItem-function. In that case it is enough to return completionitems with a label from theprovideCompletionItems-function. Subsequently,when a completion item is shown in the UI and gains focus this provider is asked to resolvethe item, like adding doc-comment or details.

Methods

</a>provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): CompletionItem[] | Thenable<CompletionItem[]> | CompletionList | Thenable<CompletionList></span>

Provide completion items for the given position and document.

ParameterDescription
document: TextDocumentThe document in which the command was invoked.
position: PositionThe position at which the command was invoked.
token: CancellationTokenA cancellation token.
ReturnsDescription
CompletionItem[] | Thenable<CompletionItem[]> | CompletionList | Thenable<CompletionList>An array of completions, a completion list, or a thenable that resolves to either.The lack of a result can be signaled by returning undefined, null, or an empty array.

</a>resolveCompletionItem(item: CompletionItem, token: CancellationToken): CompletionItem | Thenable<CompletionItem></span>

Given a completion item fill in more data, like doc-commentor details.

The editor will only resolve a completion item once.

ParameterDescription
item: CompletionItemA completion item currently active in the UI.
token: CancellationTokenA cancellation token.
ReturnsDescription
CompletionItem | Thenable<CompletionItem>The resolved completion item or a thenable that resolves to of such. It is OK to return the givenitem. When no result is returned, the given item will be used.

CompletionList" class="reference-link">CompletionList

Represents a collection of completion items to be presentedin the editor.

Constructors

</a>new CompletionList(items?: CompletionItem[], isIncomplete?: boolean): CompletionList</span>

Creates a new completion list.

ParameterDescription
items?: CompletionItem[]The completion items.
isIncomplete?: booleanThe list is not complete.
ReturnsDescription
CompletionList

Properties

</a>isIncomplete: boolean</span>

This list it not complete. Further typing should result in recomputingthis list.

</a>items: CompletionItem[]</span>

The completion items.

DecorationOptions" class="reference-link">DecorationOptions

Represents options for a specific decoration in a decoration set.

Properties

</a>hoverMessage: MarkedString | MarkedString[]</span>

A message that should be rendered when hovering over the decoration.

</a>range: Range</span>

Range to which this decoration is applied.

DecorationRenderOptions" class="reference-link">DecorationRenderOptions

Represents rendering styles for a text editor decoration.

Properties

</a>backgroundColor?: string</span>

Background color of the decoration. Use rgba() and define transparent background colors to play well with other decorations.

</a>borderColor?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>borderRadius?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>borderSpacing?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>borderStyle?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>borderWidth?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>color?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>cursor?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>dark?: ThemableDecorationRenderOptions</span>

Overwrite options for dark themes.

</a>gutterIconPath?: string</span>

An absolute path to an image to be rendered in the gutterIconPath.

</a>isWholeLine?: boolean</span>

Should the decoration be rendered also on the whitespace after the line text.Defaults to false.

</a>letterSpacing?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>light?: ThemableDecorationRenderOptions</span>

Overwrite options for light themes.

</a>outlineColor?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>outlineStyle?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>outlineWidth?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

</a>overviewRulerColor?: string</span>

The color of the decoration in the overview ruler. Use rgba() and define transparent colors to play well with other decorations.

</a>overviewRulerLane?: OverviewRulerLane</span>

The position in the overview ruler where the decoration should be rendered.

</a>textDecoration?: string</span>

CSS styling property that will be applied to text enclosed by a decoration.

Definition" class="reference-link">Definition

The definition of a symbol represented as one or many locations.For most programming languages there is only one location at which a symbol isdefined.

</a>Definition: Location | Location[]</span>

DefinitionProvider" class="reference-link">DefinitionProvider

The definition provider interface defines the contract between extensions andthe go to definitionand peek definition features.

Methods

</a>provideDefinition(document: TextDocument, position: Position, token: CancellationToken): Definition | Thenable<Definition></span>

Provide the definition of the symbol at the given position and document.

ParameterDescription
document: TextDocumentThe document in which the command was invoked.
position: PositionThe position at which the command was invoked.
token: CancellationTokenA cancellation token.
ReturnsDescription
Definition | Thenable<Definition>A definition or a thenable that resolves to such. The lack of a result can besignaled by returning undefined or null.

Diagnostic" class="reference-link">Diagnostic

Represents a diagnostic, such as a compiler error or warning. Diagnostic objectsare only valid in the scope of a file.