emmetio / emmet-atom

Emmet support for Atom
MIT License
763 stars 181 forks source link

Use editor.getGrammar().scopeName instead of editor.getGrammar().name #376

Open timkelty opened 8 years ago

timkelty commented 8 years ago

It seems unfortunate to use .name, as that is only the top-level name.

For instance, I recently discovered emmet expansion was broken in a source.css.postcss scope. If emmet used the scopeName, which would be source.css.postcss instead of just name, which is just, postcss it wouldn't have to make exceptions for each sub-scope.

https://github.com/emmetio/emmet-atom/blob/master/lib/editor-proxy.coffee#L203-L204

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29178299-use-editor-getgrammar-scopename-instead-of-editor-getgrammar-name?utm_campaign=plugin&utm_content=tracker%2F535900&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F535900&utm_medium=issues&utm_source=github).
timkelty commented 8 years ago

Another example of this:

  1. You're in a Markdown file
  2. Within that, you are in a code block, with html formatting, which changes the scope to: source.gfm markup.code.html.gfm source.html.basic
  3. At this point anything scoped to source.html.basic should work, but Emmet expansions don't work because it is only targeting the grammar "name", not the scope.
timkelty commented 8 years ago

This seems related: https://github.com/emmetio/emmet-atom/pull/43

More reference: https://discuss.atom.io/t/why-do-so-many-packages-ignore-scope-and-only-use-grammar-name/24724

sergeche commented 8 years ago

Within that, you are in a code block, with html formatting, which changes the scope to: source.gfm markup.code.html.gfm source.html.basic

editor.getGrammar().scopeName won’t help here because editor.getGrammar() returns root grammar, not context one (which should be retrieved with editor.scopeDescriptorForBufferPosition().getScopesArray()

timkelty commented 8 years ago

Thanks, @sergeche

victorwpbastos commented 7 years ago

This would fix #325 for vue files.