-
Notifications
You must be signed in to change notification settings - Fork 29.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add when clause context for language at active cursor #107989
Comments
+1 for this feature. |
I hope you upvoted the issue above, otherwise your +1 won't count and will only have been 'noise'. |
This feature is relevant to "literate programming" notebook formats like R Markdown and Weave.jl. The embedded language is specified with the markdown code-block syntax.
|
Can you provide some use-cases for this when clauses? |
In addition to the "literate programming" I mentioned above embedding languages in Markdown, reStructuredText, or LaTeX, there is also embedding HTML or SQL in ES6. The syntax highlighting and keybindings would be available for editing, formatting, and executing the embedded code with the appropriate language server and compiler/interpreter. |
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 I doubt a handler that triggers when <script type="r">print("Hello World!")</script> In that case, the when clause should probably rather be |
A very practical use case is JSX/TSX files.
Currently, I have two key bindings: one for bracket-matching, and one for HTML/JSX tag-matching. However, when both syntaxes are present in the same file, [
// Unset default key binding
{
"key": "shift+cmd+\\",
"command": "-editor.action.jumpToBracket",
"when": "editorTextFocus"
},
// Key binding for brackets
{
"key": "alt+cmd+m",
"command": "editor.action.jumpToBracket",
"when": "editorTextFocus"
},
// Key binding for JSX tags specifically
{
"key": "alt+cmd+b",
"command": "highlight-matching-tag.selectPairContents",
"when": "editorLangId == 'handlebars' || editorLangId == 'html' || editorLangId == 'jsx-tags' || editorLangId == 'svelte' || editorLangId == 'xml'"
}
] The only workaround I've found is to assign separate key bindings: one for bracket-matching, and another for tag-matching. But of course, this is not ideal because of the added cognitive overhead in remembering which key binding to use. Therefore, it would be very helpful if VS Code a |
This is to work around an issue where a VS Code key binding can be scoped to the current language ID of the editor, but not the current language ID at the cursor. This makes working in JSX/TSX files more annoying. For more information, see: <microsoft/vscode#107989 (comment)>
I 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 thecontributes.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 thewhen
clause.The text was updated successfully, but these errors were encountered: