Order | Area | TOCTitle | ContentId | PageTitle | DateApproved | MetaDescription |
---|---|---|---|---|---|---|
3 |
extensionapi |
Contribution Points |
2F27A240-8E36-4CC2-973C-9A1D8069F83F |
Visual Studio Code Extension Contribution Points - package.json |
4/14/2016 |
To extend Visual Studio Code, your extension (plug-in) declares which of the various contribution points it is using in its package.json extension manifest file. |
This document covers the various contribution points that are defined in the package.json
extension manifest.
Contribute configuration keys that will be exposed to the user. The user will be able to set these configuration options either from User Settings or from the Workspace Settings.
When contributing configuration keys, a JSON schema describing these keys is actually contributed. This ensures the user gets great tooling support when authoring VS Code settings files.
You can read these values from your extension using vscode.workspace.getConfiguration('myExtension')
.
...
"contributes": {
"configuration": {
"type": "object",
"title": "TypeScript configuration",
"properties": {
"typescript.useCodeSnippetsOnMethodSuggest": {
"type": "boolean",
"default": false,
"description": "Complete functions with their parameter signature."
},
"typescript.tsdk": {
"type": ["string", "null"],
"default": null,
"description": "Specifies the folder path containing the tsserver and lib*.d.ts files to use."
}
}
}
}
Contribute an entry consisting of a title and a command to invoke to the Command Palette (kb(workbench.action.showCommands)
).
Note: When a command is invoked (from a key binding or from the Command Palette), VS Code will emit an
activationEvent
onCommand:${command}
.
...
"contributes": {
"commands": [{
"command": "extension.sayHello",
"title": "Hello World"
}]
}
...
Contribute a key binding rule defining what command should be invoked when the user presses a key combination. See the Key Bindings topic where key bindings are explained in detail.
Contributing a key binding will cause the Default Keyboard Shortcuts to display your rule, and every UI representation of the command will now show the key binding you have added. And, of course, when the user presses the key combination the command will be invoked.
Note: Because VS Code runs on Windows, Mac and Linux, where modifiers differ, you can use "key" to set the default key combination and overwrite it with a specific platform.
Note: When a command is invoked (from a key binding or from the Command Palette), VS Code will emit an activationEvent
onCommand:${command}
.
Defining that kbstyle(Ctrl+F1)
under Windows and Linux and kbstyle(Cmd+F1)
under Mac trigger the "extension.sayHello"
command:
...
"contributes": {
"keybindings": [{
"command": "extension.sayHello",
"key": "ctrl+f1",
"mac": "cmd+f1",
"when": "editorTextFocus"
}]
}
...
Contribute the definition of a language. This will introduce a new language or enrich the knowledge VS Code has about a language.
In this context, a language is basically a string identifier that is associated to a file (See TextDocument.getLanguageId()
).
VS Code uses three hints to determine the language a file will be associated with. Each "hint" can be enriched independently:
- the extension of the filename (
extensions
below) - the filename (
filenames
below) - the first line inside the file (
firstLine
below)
The last piece of information VS Code wants to know about a language is the aliases
property, the first item in this list will be picked as the language label (as rendered in the status bar on the right).
When a file is opened by the user, these three rules are applied and a language is determined. VS Code will then emit an activationEvent onLanguage:${language}
(e.g. onLanguage:python
for the example below)
...
"contributes": {
"languages": [{
"id": "python",
"extensions": [ ".py" ],
"aliases": [ "Python", "py" ],
"filenames": [ ... ],
"firstLine": "^#!/.*\\bpython[0-9.-]*\\b"
}]
}
Contribute a 'debug adapter' to VS Code's debugger. A debug adapter integrates VS Code with a particular debug engine. It runs in a separate process and communicates with VS Code through the VS Code debug protocol. You must provide one (or more) executables that implement the debug adapter.
...
"contributes": {
"debuggers": [{
"type": "node",
"label": "Node Debug",
"program": "./out/node/nodeDebug.js",
"runtime": "node",
"enableBreakpointsFor": { "languageIds": ["javascript", "javascriptreact"] },
"initialConfigurations": [{
...
}],
"configurationAttributes": {
...
}
}]
}
...
For a full walkthrough on how to integrate a debugger
go to Debuggers.
Contribute a TextMate grammar to a language. You must provide the language
this grammar applies to, the TextMate scopeName
for the grammar and the file path.
Note: The file containing the grammar can be in JSON (filenames ending in .json) or in XML plist format (all other files).
...
"contributes": {
"grammars": [{
"language": "shellscript",
"scopeName": "source.shell",
"path": "./syntaxes/Shell-Unix-Bash.tmLanguage"
}]
}
...
See Adding Language Colorization for instructions on using the yo code extension generator to quickly package TextMate .tmLanguage files as VS Code extensions.
Contribute a TextMate theme to VS Code. You must specify a label, whether the theme is a dark theme or a light theme (such that the rest of VS Code changes to match your theme) and the path to the file (XML plist format).
"contributes": {
"themes": [{
"label": "Monokai",
"uiTheme": "vs-dark",
"path": "./themes/Monokai.tmTheme"
}]
}
See Changing the Color Theme for instructions on using the yo code extension generator to quickly package TextMate .tmTheme files as VS Code extensions.
"contributes": {
"snippets": [{
"language": "go",
"path": "./snippets/go.json"
}]
}
Contributes a validation schema for a specific type of json
file. The url
value can be either a local path to a schema file included in the extension or a remote server URL such as a json schema store.
"contributes": {
"jsonValidation": [{
"fileMatch": ".jshintrc",
"url": "http://json.schemastore.org/jshintrc"
}]
}
To learn more about VS Code extensibility model, try these topic:
- Extension Manifest File - VS Code package.json extension manifest file reference
- Activation Events - VS Code activation events reference
Nothing yet