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:

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.

  1. ...
  2. "activationEvents": [
  3. "onLanguage:python"
  4. ]
  5. ...

activationEvents.onCommand

This activation event is emitted and interested extensions will be activated whenever a command is being invoked:

  1. ...
  2. "activationEvents": [
  3. "onCommand:extension.sayHello"
  4. ]
  5. ...

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.

  1. ...
  2. "activationEvents": [
  3. "workspaceContains:.editorconfig"
  4. ]
  5. ...

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.

  1. ...
  2. "activationEvents": [
  3. "*"
  4. ]
  5. ...

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 a deactivate() 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:

Common Questions

Nothing yet