Event When Grammar First Used


#1

I would like my package to activate when someone first uses the grammar provided by the language-go package. In essence, when a user first opens a .go file, or changes the grammar in an existing file to go, I want my package (go-plus) to activate.

Is there an existing event that I could use in activationEvents that would match this scenario? Currently, go-plus does not have activationEvents, and takes 55ms to activate.


#2

This is one of those cases activationEvents doesn’t really cover well. I’d suggest taking a look at the way I initialize my tabs-to-spaces package. Basically, I load the main CoffeeScript file with no activationEvents … but all it does is register a couple commands and an event listener. The functions that are called by those commands and event listener then load the rest of the package on first use. If none of the commands or event listeners are called … then you never incur 99% of the overhead of the package.

It’s a pretty simple system once you get the idea. Let me know if you have questions …


#3

Yeah, that’s almost what I’m doing now as well. I could slim down the things that occur during activation further and hopefully shave off a bit of time, but everything that is long running during activation is currently asynchronous.


#4

I guess you could use the DisplayBuffer::onDidChangeGrammar event and test the current grammar to detect when a go file is opened.