- vscode-api
- vscode namespace API
- env
- extensions
- languages
- window
- workspace
- CancellationToken" level="3">CancellationToken
- CancellationTokenSource" level="3">CancellationTokenSource
- CharacterPair" level="3">CharacterPair
- CodeActionContext" level="3">CodeActionContext
- CodeActionProvider" level="3">CodeActionProvider
- CodeLens" level="3">CodeLens
- CodeLensProvider" level="3">CodeLensProvider
- Command" level="3">Command
- CommentRule" level="3">CommentRule
- CompletionItem" level="3">CompletionItem
- CompletionItemKind" level="3">CompletionItemKind
- CompletionItemProvider" level="3">CompletionItemProvider
- CompletionList" level="3">CompletionList
- DecorationOptions" level="3">DecorationOptions
- DecorationRenderOptions" level="3">DecorationRenderOptions
- Definition" level="3">Definition
- DefinitionProvider" level="3">DefinitionProvider
- Diagnostic" level="3">Diagnostic
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 inpackage.json
to make a command show inthe command palette. - keybinding - Use the
keybindings
-section inpackage.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
.
commands.registerCommand('extension.sayHello', () => {
window.showInformationMessage('Hello World!');
});
Second, bind the command identfier to a title under which it will show in the palette (package.json
).
{
"contributes": {
"commands": [{
"command": "extension.sayHello",
"title": "Hello World"
}]
}
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.
Parameter | Description |
---|---|
command: string | Identifier of the command to execute. |
…rest: any[] | Parameters passed to the command function. |
Returns | Description |
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.
Parameter | Description |
---|---|
filterInternal?: boolean | Set true to not see internal commands (starting with an underscore) |
Returns | Description |
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.
Parameter | Description |
---|---|
command: string | A unique identifier for the command. |
callback: (args: any[]) => any | A command handler function. |
thisArg?: any | The this context used when invoking the handler function. |
Returns | Description |
Disposable | Disposable 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.
Parameter | Description |
---|---|
command: string | A unique identifier for the command. |
callback: (textEditor: TextEditor, edit: TextEditorEdit) => void | A command handler function with access to an editor and an edit. |
thisArg?: any | The this context used when invoking the handler function. |
Returns | Description |
Disposable | Disposable 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.
export function activate(context: vscode.ExtensionContext) {
let api = {
sum(a, b) {
return a + b;
},
mul(a, b) {
return a * b;
}
};
// 'export' public api-surface
return api;
}
When depending on the API of another extension add an extensionDependency
-entryto package.json
, and use the getExtension-functionand the exports-property, like below:
let mathExt = extensions.getExtension('genius.math');
let importedApi = mathExt.exports;
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
.
Parameter | Description |
---|---|
extensionId: string | An extension identifier. |
Returns | Description |
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
.
Parameter | Description |
---|---|
extensionId: string | An extension identifier. |
Returns | Description |
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.
languages.registerHoverProvider('javascript', {
provideHover(document, position, token) {
return new Hover('I am a hover!');
}
});
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.
Parameter | Description |
---|---|
name?: string | The name of the collection. |
Returns | Description |
DiagnosticCollection | A new diagnostic collection. |
</a>getLanguages(): Thenable<string[]></span>
Return the identifiers of all known languages.
Returns | Description |
---|---|
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) When selector is an array, return the maximum individual result.
(2) When selector is a string match that against the [languageId](#TextDocument.languageId).
(2.1) When both are equal score is `10`,
(2.2) When the selector is `*` score is `5`,
(2.3) Else score is `0`.
(3) When selector is a [filter](#DocumentFilter) every property must score higher `0`. Iff the score is the sum of the following:
(3.1) When [language](#DocumentFilter.language) is set apply rules from #2, when `0` the total score is `0`.
(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`.
(3.3) When [pattern](#Document.pattern) is set
(3.3.1) pattern eqauls the [uri](#TextDocument.uri)-fsPath add `10` to the score,
(3.3.1) if the pattern matches as glob-pattern add `5` to the score,
(3.3.1) the total score is `0`
Parameter | Description |
---|---|
selector: DocumentSelector | A document selector. |
document: TextDocument | A text document. |
Returns | Description |
number | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: CodeActionProvider | A code action provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: CodeLensProvider | A code lens provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: CompletionItemProvider | A completion provider. |
…triggerCharacters: string[] | Trigger completion when the user types one of the characters, like . or : . |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: DefinitionProvider | A definition provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: DocumentFormattingEditProvider | A document formatting edit provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: DocumentHighlightProvider | A document highlight provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: DocumentRangeFormattingEditProvider | A document range formatting edit provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: DocumentSymbolProvider | A document symbol provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: HoverProvider | A hover provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: OnTypeFormattingEditProvider | An on type formatting edit provider. |
firstTriggerCharacter: string | A character on which formatting should be triggered, like } . |
…moreTriggerCharacter: string[] | More trigger characters. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: ReferenceProvider | A reference provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: RenameProvider | A rename provider. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
selector: DocumentSelector | A selector that defines the documents this provider is applicable to. |
provider: SignatureHelpProvider | A signature help provider. |
…triggerCharacters: string[] | Trigger signature help when the user types one of the characters, like , or ( . |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
provider: WorkspaceSymbolProvider | A workspace symbol provider. |
Returns | Description |
Disposable | A disposable that unregisters this provider when being disposed. |
</a>setLanguageConfiguration(language: string, configuration: LanguageConfiguration): Disposable</span>
Set a language configuration for a language.
Parameter | Description |
---|---|
language: string | A language identifier like typescript . |
configuration: LanguageConfiguration | Language configuration. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
name: string | Human-readable string which will be used to represent the channel in the UI. |
Returns | Description |
OutputChannel |
</a>createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem</span>
Creates a status bar item.
Parameter | Description |
---|---|
alignment?: StatusBarAlignment | The alignment of the item. |
priority?: number | The priority of the item. Higher values mean the item should be shown more to the left. |
Returns | Description |
StatusBarItem | A new status bar item. |
</a>createTextEditorDecorationType(options: DecorationRenderOptions): TextEditorDecorationType</span>
Create a TextEditorDecorationType that can be used to add decorations to text editors.
Parameter | Description |
---|---|
options: DecorationRenderOptions | Rendering options for the decoration type. |
Returns | Description |
TextEditorDecorationType | A 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.
Parameter | Description |
---|---|
text: string | The message to show, support icon subtitution as in status bar items. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
text: string | The message to show, support icon subtitution as in status bar items. |
hideAfterTimeout: number | Timeout in milliseconds after which the message will be disposed. |
Returns | Description |
Disposable | A 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.
Parameter | Description |
---|---|
text: string | The 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. |
Returns | Description |
Disposable | A disposable which hides the status bar message. |
</a>showErrorMessage(message: string, …items: string[]): Thenable<string></span>
Show an error message.
- see - showInformationMessage
Parameter | Description |
---|---|
message: string | The message to show. |
…items: string[] | A set of items that will be rendered as actions in the message. |
Returns | Description |
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.
- see - showInformationMessage
Parameter | Description |
---|---|
message: string | The message to show. |
…items: T[] | A set of items that will be rendered as actions in the message. |
Returns | Description |
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.
Parameter | Description |
---|---|
message: string | The message to show. |
…items: string[] | A set of items that will be rendered as actions in the message. |
Returns | Description |
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.
- see - showInformationMessage
Parameter | Description |
---|---|
message: string | The message to show. |
…items: T[] | A set of items that will be rendered as actions in the message. |
Returns | Description |
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.
Parameter | Description |
---|---|
options?: InputBoxOptions | Configures the behavior of the input box. |
Returns | Description |
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.
Parameter | Description |
---|---|
items: string[] | Thenable<string[]> | An array of strings, or a promise that resolves to an array of strings. |
options?: QuickPickOptions | Configures the behavior of the selection list. |
Returns | Description |
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.
Parameter | Description |
---|---|
items: T[] | Thenable<T[]> | An array of items, or a promise that resolves to an array of items. |
options?: QuickPickOptions | Configures the behavior of the selection list. |
Returns | Description |
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.
Parameter | Description |
---|---|
document: TextDocument | A text document to be shown. |
column?: ViewColumn | A view column in which the editor should be shown. The default is the one, other valuesare adjusted to be Min(column, columnCount + 1). |
preserveFocus?: boolean | When true the editor will not take focus. |
Returns | Description |
Thenable<TextEditor> | A promise that resolves to an editor. |
</a>showWarningMessage(message: string, …items: string[]): Thenable<string></span>
Show a warning message.
- see - showInformationMessage
Parameter | Description |
---|---|
message: string | The message to show. |
…items: string[] | A set of items that will be rendered as actions in the message. |
Returns | Description |
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.
- see - showInformationMessage
Parameter | Description |
---|---|
message: string | The message to show. |
…items: T[] | A set of items that will be rendered as actions in the message. |
Returns | Description |
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.
Parameter | Description |
---|---|
edit: WorkspaceEdit | A workspace edit. |
Returns | Description |
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.
Parameter | Description |
---|---|
pathOrUri: string | Uri | A path or uri. When a uri is given its fsPath is used. |
Returns | Description |
string | A 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.
Parameter | Description |
---|---|
globPattern: string | A glob pattern that is applied to the names of created, changed, and deleted files. |
ignoreCreateEvents?: boolean | Ignore when files have been created. |
ignoreChangeEvents?: boolean | Ignore when files have been changed. |
ignoreDeleteEvents?: boolean | Ignore when files have been deleted. |
Returns | Description |
FileSystemWatcher | A 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)
Parameter | Description |
---|---|
include: string | A glob pattern that defines the files to search for. |
exclude: string | A glob pattern that defines files and folders to exclude. |
maxResults?: number | An upper-bound for the result. |
token?: CancellationToken | A token that can be used to signal cancellation to the underlying search engine. |
Returns | Description |
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
.
Parameter | Description |
---|---|
section?: string | A dot-separated identifier. |
Returns | Description |
WorkspaceConfiguration | The 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.
Parameter | Description |
---|---|
uri: Uri | Identifies the resource to open. |
Returns | Description |
Thenable<TextDocument> | A promise that resolves to a document. |
</a>openTextDocument(fileName: string): Thenable<TextDocument></span>
A short-hand for openTextDocument(Uri.file(fileName))
.
- see - openTextDocument
Parameter | Description |
---|---|
fileName: string | A name of a file on disk. |
Returns | Description |
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.
Parameter | Description |
---|---|
scheme: string | The uri-scheme to register for. |
provider: TextDocumentContentProvider | A content provider. |
Returns | Description |
Disposable | A disposable that unregisters this provider when being disposed. |
</a>saveAll(includeUntitled?: boolean): Thenable<boolean></span>
Save all dirty files.
Parameter | Description |
---|---|
includeUntitled?: boolean | Also save files that have been created during this session. |
Returns | Description |
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.
Returns | Description |
---|---|
void |
</a>dispose(): void</span>
Dispose object and free resources. Will call cancel.
Returns | Description |
---|---|
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.
Parameter | Description |
---|---|
document: TextDocument | The document in which the command was invoked. |
range: Range | The range for which the command was invoked. |
context: CodeActionContext | Context carrying additional information. |
token: CancellationToken | A cancellation token. |
Returns | Description |
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.
Parameter | Description |
---|---|
range: Range | The range to which this code lens applies. |
command?: Command | The command associated to this code lens. |
Returns | Description |
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.
Parameter | Description |
---|---|
document: TextDocument | The document in which the command was invoked. |
token: CancellationToken | A cancellation token. |
Returns | Description |
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.
Parameter | Description |
---|---|
codeLens: CodeLens | code lens that must be resolved. |
token: CancellationToken | A cancellation token. |
Returns | Description |
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.
- see - commands.registerCommand.
</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 /
</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.
- see - CompletionItemProvider.provideCompletionItems
- see - CompletionItemProvider.resolveCompletionItem
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.
Parameter | Description |
---|---|
label: string | The label of the completion. |
Returns | Description |
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
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.
Parameter | Description |
---|---|
document: TextDocument | The document in which the command was invoked. |
position: Position | The position at which the command was invoked. |
token: CancellationToken | A cancellation token. |
Returns | Description |
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.
Parameter | Description |
---|---|
item: CompletionItem | A completion item currently active in the UI. |
token: CancellationToken | A cancellation token. |
Returns | Description |
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.
Parameter | Description |
---|---|
items?: CompletionItem[] | The completion items. |
isIncomplete?: boolean | The list is not complete. |
Returns | Description |
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.
Parameter | Description |
---|---|
document: TextDocument | The document in which the command was invoked. |
position: Position | The position at which the command was invoked. |
token: CancellationToken | A cancellation token. |
Returns | Description |
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.