question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add when clause context for language at active cursor

See original GitHub issue

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 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:open
  • Created 3 years ago
  • Reactions:38
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gjsjohnmurraycommented, Oct 4, 2020

+1 for this feature.

I hope you upvoted the issue above, otherwise your +1 won’t count and will only have been ‘noise’.

0reactions
hedietcommented, Oct 20, 2021

The syntax highlighting

But what does syntax highlighting have to do with the requested feature?

keybindings would be available for editing, formatting, and executing the embedded code

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 hypothetical editorLangIdAtCursor == 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:

<script type="r">print("Hello World!")</script>

In that case, the when clause should probably rather be editorLangId == r || (editorLangId == markdown && editorLangIdAtCursor == r).

Read more comments on GitHub >

github_iconTop Results From Across the Web

when clause contexts | Visual Studio Code Extension API
when clause contexts. Visual Studio Code sets various context keys and specific values depending on what elements are visible and active in the...
Read more >
How do I use the cursorMove command in an extension so ...
I see two options: cursorMove 's are relative to the current position. Not to an absolute position as I think you know.
Read more >
Explicit Cursor Declaration and Definition
An explicit cursor is a named pointer to a private SQL area that stores information for processing a specific query or DML statement—typically, ......
Read more >
PL/SQL - Cursors - Tutorialspoint
In this chapter, we will discuss the cursors in PL/SQL. Oracle creates a memory area, known as the context area, for processing an...
Read more >
Reopening a Select or Function Cursor - HCL Product Documentation
The database server evaluates the values that are specified in the USING clause of the OPEN statement only when it opens a Select...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found