I'm trying to understand the extension activation routine and maybe someone can help me.
In the file package.json
there is the activationEvents
node, where I define when the extension will be activated (e.g. when executing a command via onCommand
). See help
From code documentation of the sample extension, I understand that the extension will only be activated on the very first execution of the command.
What happens when I define multiple commands in the extension? I would register all the commands in the activate
function and add them to the activationEvents
:
"activationEvents": [
"onCommand:extension.testCommand1",
"onCommand:extension.testCommand2",
"onCommand:extension.testCommand3"
],
Will the activate
function only be called once when any of the commands was executed the very first time? Or will it call the function for the first execution of extension.testCommand1
, extension.testCommand2
and extension.testCommand3
(--> three times)?
I'm also writing a language server and would like to put everything in the same extension. Is this possible or do I need to create two additional extensions (client and server)?
To answer your first question, it will be called exactly one time, only when the first activation event occurs. If you're interested in verifying this yourself, set the activation events in package.json
to:
"activationEvents": [
"onLanguage:js",
"onLanguage:python",
"onLanguage:ruby"
],
Then set a breakpoint in the activation method in your extension, press F5 to start debugging, and change the language mode via the command palette to js, python, and ruby. You'll see that the break-point is only hit the first time.
Regarding your second question, it probably depends on what your language service needs to do. If you want to do something as complex as the typescript language service, you might need both. If you want to make something that lints, provides hover tips, or more, but isn't quite as complex as typescript, you can do it one extension.
I'm personally following the example of the php service for my language extension. The team did a good job with it and the features are well separated and easy to understand. You can view the source of the php service here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With