Add when clause context for language at active cursor
See original GitHub issueI would like a new when clause context for the language ID at the active cursor position within the document. Right now, we have editorLangId
which only uses the language ID of the editor itself, but documents can have other languages embedded in them defined in the contributes.grammars
.
I’m not sure about the full extent of how the embedded language is used, but I’ve seen it used for some built-in features like language snippets and the built-in commands that toggle language comments. I can also see the language present in the inspector for the command editor.action.inspectTMScopes
. Since it’s clearly seen as useful for this built-in functionality and has implementations demonstrating how it can be used, it should also be clear that it would be useful to have access to this in the when
clause.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:38
- Comments:9 (3 by maintainers)
Top GitHub Comments
I hope you upvoted the issue above, otherwise your +1 won’t count and will only have been ‘noise’.
But what does syntax highlighting have to do with the requested feature?
I think these keybinding handlers most likely also need to understand the surrounding markdown, at least for formatting and executing the code, so I suggest to have
editorLangId == r || editorLangId == markdown
(and make the command aware of markdown) instead of some hypotheticaleditorLangIdAtCursor == r
. The only problem here is that you cannot bind multiple language-specific commands to the same key-binding, but I wonder if that really is a problem.I doubt a handler that triggers when
editorLangIdAtCursor == r
would be able to work for code that is embedded in completely arbitrary/unexpected documents, as it does not know the semantics of the outer document. For example in this case, a “toggle line comment command” would need to be aware of the outer html:In that case, the when clause should probably rather be
editorLangId == r || (editorLangId == markdown && editorLangIdAtCursor == r)
.