- Activation Events - package.json
activationEvents.onLanguage
activationEvents.onCommand
activationEvents.workspaceContains
activationEvents.*
- Next Steps
- Common Questions
Activation Events - package.json
Extensions are activated lazily in VS Code. As a result you need to provide VS Code with context as to when your extension should be activated. We support the following activation events:
onLanguage:${language}
onCommand:${command}
workspaceContains:${toplevelfilename}
*
We also provide an overview of the package.json
extension manifest and the minimum required fields.
activationEvents.onLanguage
This activation event is emitted and interested extensions will be activated whenever a file that resolves to a certain language gets opened.
...
"activationEvents": [
"onLanguage:python"
]
...
activationEvents.onCommand
This activation event is emitted and interested extensions will be activated whenever a command is being invoked:
...
"activationEvents": [
"onCommand:extension.sayHello"
]
...
activationEvents.workspaceContains
This activation event is emitted and interested extensions will be activated whenever a folder is opened and the folder contains a top-level file.
...
"activationEvents": [
"workspaceContains:.editorconfig"
]
...
activationEvents.*
This activation event is emitted and interested extensions will be activated whenever VS Code starts up. To ensure a great end user experience, please use this activation event in your extension only when no other activation events combination works in your use-case.
...
"activationEvents": [
"*"
]
...
Note: An extension can listen to multiple activation events, and that is preferable to listening to
"*"
.Note: An extension must export an
activate()
function from its main module and it will be invoked only once by VS Code when any of the specified activation events is emitted. Also, an extension should export adeactivate()
function from its main module to perform cleanup tasks on VS Code shutdown.
Next Steps
To learn more about VS Code extensibility model, try these topic:
- Extension Manifest File - VS Code package.json extension manifest file reference
- Contribution Points - VS Code contribution points reference
Common Questions
Nothing yet