Repository navigation
Add activationHooks + Trigger {grammar-package-name}:grammar-used Hook When A text-editor-element's Grammar Is Set - #7638
Conversation
|
👍 This is awesome. |
There was a problem hiding this comment.
Was this console.log committed by accident 👼?
There was a problem hiding this comment.
Yes, console.log shouldn't be there. This is WIP, I'm moving some stuff around and will clean up history.
{grammar-package-name}:grammar-used Command When Grammar Changes{grammar-package-name}:grammar-used Command When Grammar Changes
{grammar-package-name}:grammar-used Command When Grammar Changes{grammar-package-name}:grammar-used Command When Grammar Changes
|
Ready for review. |
|
@joefitzgerald I only want to use commands for communication from the user to Atom, not for communication from Atom to packages. I would be open to a method on text editor such as |
|
@nathansobo this is the only way we can have activationCommands kick in on first use of a grammar. This allows us to defer activation of packages that are language-specific until the first use of the grammar for that language. |
|
👎 I support a hard line that commands should be user-invoked. If this delayed activation thing is really, truly needed, I'd support baking this into core as activationGrammar in package.json or something. |
|
@joefitzgerald Got it. I wasn't fully understanding what you're trying to do here. Yeah, echoing what @thedaniel is saying, I'm worried about expanding the role of commands in this way. I see some ways forward though...
|
|
@nathansobo, @thedaniel, you make good points. Delayed activation is a simple thing to achieve for code that we control inside our activation method, by not activating any package functionality on activation but just bind a event listener for any given event we want to activate on. This doesn't work for any dynamically activated functionality like keybinds and services however. What if we could return a promise from our activation function that determined when to activate the other automatic features of our package. If we add Then delayed activation based on grammar is something like activate: ->
return new Promise resolve ->
grammerLoadOff() = atom.grammars.onGrammarLoaded (grammar) ->
if grammar == "coffeeScript"
grammerLoadOff()
@customInitialization();
resolve()It could even be a separate fuction like Keeping in mind I'm not sure if onGrammarLoaded is quite appropriate for this situation. |
|
@park9140 you don't want to activate on load of a grammar as - I believe - all grammars are loaded on startup? Core team, is that accurate? I do like the idea of allowing activate to return a promise. It would somewhat resolve #4059 also. I'm unsure how /cc @bolinfest |
A: Lines 334 to 341 in 8c2bcf3 It didn't it registered on workspaceView. So, is that really what we'd want to go back to? Or should there be something like atom.commands (i.e.atom.events)?
|
{grammar-package-name}:grammar-used Command When Grammar Changes{grammar-package-name}:grammar-used Hook When A text-editor-element's Grammar Is Set
|
OK folks, I've pivoted to a new approach that leverages |
There was a problem hiding this comment.
Seems like we shouldn't need the workspace element to be on the DOM here. Is this a leftover?
|
Everything seems pretty straightforward except where the grammar hook is being triggered and how we're going to format the string. I just want to put some thought into our scheme. I think I see where you're going with using the package-name prefix in the hook name. However, there's also the grammar scope name, and a single language package could contain multiple grammars. So we're losing a bit of information here. That said, this does lay down a nice pattern for packages to add their own hooks when we expose the activation hook API. |
I could just emit once for the package name and then again for the grammar scope name? |
I guess let's just start with the package name and see where it goes. |
- Trigger the `{grammar-package-name}:grammar-used` hook when grammar is set for tokenized-buffer
|
@nathansobo I moved the triggering of activationHooks to tokenized-buffer. Please review. |
|
Looking good. Running a build on our internal CI and giving core team members one last chance to check this out. If all goes well, will merge this afternoon. |
|
Don't forget to doc it over in atom/docs after it lands! |
Add activationHooks + Trigger `{grammar-package-name}:grammar-used` Hook When A text-editor-element's Grammar Is Set
|
@joefitzgerald Would you mind opening a PR documenting this? |
|
Thanks by the way. I really appreciate the thought you're putting into leveling up our package system. |
This PR:
activationHooksto package.json{grammar-package-name}:grammar-usedhook when a text-editor-element's grammar is setThis allows package authors to defer package activation for language-specific packages until the first use of the grammar(s) their package serves. It also leaves open the possibility to trigger other activation hooks in the future with minimal code.
/cc @kevinsawicki