Textmate scopes in custom hover-provider for vscode extension - visual-studio-code

I've created a custom language extension for my own script language. I've written a tmlanguage file to tokenize my script and do custom highlighting. I created a hover-provider that currently only shows the word that is hovered for testing the provider itself. I want to react on the textmate scopes of the current position in this hover, like the vs code Developer tool "Inspect Editor Token and Scopes" does.
At the end I want to react to one particular scope whose value I want to read and show a corresponding image of this value in the hover.
Fore example a line in my script could look like:
setImage(dic_1/dic_2/testImg)
Now I want to show the image that correlates with the path in the brackets if I hover over it.
I tried to find something in the documentation (https://code.visualstudio.com/api/references/vscode-api#languages) if there is something that would help me but couldn't see anything related.
I tried to ask ChatGPT for help after he suggested "possible internal and not public available methods" it suggested to create a custom hover provider with the help of the library "oniguruma" and tokenize the document again.
However, this feels a bit like an overkill. If vscode has a internal tool that does return the textmate scopes I would guess there is a easy way to access those tokens.
I found this thread (Is there a way to find the textmate scope from within my VSCode extension language functions?) but I don't rally understand why I need to write another parser.
Is there any way to access this textmate scopes in a hover-provider?

Related

Custom syntax highlighting in VSCode Extension

I am currently trying to develop a VSCode extension that provides support for a new language. Static syntax highlighting should be provided by a TextMate file, additional semantic highlighting by a language server. Both of those use - for now - custom token types. The language server works nicely with Monaco and a corresponding Monarch syntax specification. With Monaco, I can set a theme manually via monaco.editor.defineTheme and provide rules for my custom tokens via rules: [{token:'my.tokentype', foreground:...}], and as a result, I get syntax highlighting the way I want, and the rules work for both Monarch-defined tokens and semantic tokens.
Now I want to do the same for VSCode. The TextMate grammar and the language server provide textmate token types and semantic token types respectively, and I now want to provide (themable) default styles for my token types in my extension, but I can't for the life of me figure out how to make VSCode highlight a document in my language based on my token types. Using the tokens and scopes inspector, I can see that the tokens in my document are assigned the right "textmate scope" or "semantic token type".
Now, how can my extension style those tokens? I have found the colors contribution point, but that can only provide colors (not additional styling like italic etc) and I have no idea how to assign those colors to my token types...
the only way I got VSCode to highlight anything is by using the semanticTokenTypes contribution point and declaring a default superType, but of course in that case, it will use the highlighting associated with that superType, not anything provided by my extension...

Display a result of debugger's step as an inline text

For my debugger extension I'd like to implement a functionality from the following image where a step can ask a debugger client to show an inlined text with the result of the step.
I've read the DAP documentation thoroughly but still don't have a clue how this can be implemented or if it's even possible to implement. What request or event do I have to implement?
By the way, how is this function of debbuger client called?
With vscode v1.54, see Inline value provider
Today the Show Inline Values feature of VS Code's debugger is based on
a generic implementation in VS Code core, and doesn't provide
customizability through settings or extensibility via extensions. As a
consequence, it is not a perfect fit for all languages and sometimes
shows incorrect values because it doesn't understand the underlying
source language. For this reason, we are working on an extension API
that allows to replace the built-in implementation completely or to
replace parts of the implementation with custom code.
In this milestone we've made a first implementation of the proposed
API available.
And much more at the first link including sample code. So vscode is adding a true API for inline values rather than depending on Decorations anymore.

How can I add these code completion features my VSCode extension?

I'm in the process of creating a VSCode extension to do code completion for an existing Lua API.
I'm having a bit of trouble achieving the following (examples are JavaScript):
I've been looking for examples and tutorials but haven't come up with much. I assume I may need to do a fair amount of string processing, around the current cursor position, to get enough data to lookup the appropriate documentation (which I stored in an array of json objects). But presently I don't know how to get the meta-data dialog to show when entering parameters.
P.S. I have reviewed the official extension samples.
Your screenshots show two VS Code features:
The first screenshot shows a hover / quick info. It is used to display information about the current word the user is hovering over. To add a hover, your extension should implement and register a HoverProvider
The second screenshot shows parameter hints / signature help. It displays information to the user as they complete a function call. To add signature help, your extension should implement and register a SignatureHelpProvider
In both cases, how you implement the functionality is entirely up to your extension. Most language extensions maintain a structural representation of the file (such as an AST) and use this to provide hover and signature help info.
You can also either implement your extension as a direct VS Code extension or using the language server protocol (which works across editors). See VS Code's Language Extensions Overview for more information about developing a language extension and why you may want to consider the Language Server Protocol

How do I theme links in VSCode?

I am building a VSCode theme.
Currently im trying to change the behaviour for links, but I can't find the right setting. In my current theme file, there is no statement in tokenColors that seems to change anything. There is also no fontStyle: "underline" or something similar, yet a link like http://www.google.com is underlined.
I looked at it with the built in developer inspector (Developer: Inspect TM Scopes), but it only says:
string.quoted.docstring.multi.python
source.python
Where does the underline setting come from? How do I change the format for links?
There are two types of underlined links:
Link parsed from grammars. These would have a foo.link.language type scope
Links detected by a link detector
For links in the grammar, you can theme the link scope as normal.
You cannot directly theme links that come from the link detector. The "editorLink.activeForeground" ui theme property lets you theme the link when it is active, but you cannot theme a non-active link if it does not have a grammar scope associated with it.
For python specifically, the grammar likely need to be updated to parse the links. This can be done either by modifying the grammar or with an injection grammar

How to embed DSL keyword highlighting and code completion into application

I am creating custom DSL with groovy for purpose of creating rules (for rule engine). My target audience will be non-programmers.
Something like this:
when user visit page "test" within 5.days
then assign campaign 200
I would like to provide my users with at least some kind of text box where they will be able to create rules using the DSL. To make it simple and professional I am looking for a third party component to help me with the task of keywords highlighting and code completion. I read about groovy DSL descriptor but apparently thry working only inside eclipse IDE. Is there any way to incorporate required functionality into my application?
You have a bunch of code editor to put in your projects. Check the wiki http://en.wikipedia.org/wiki/Comparison_of_JavaScript-based_source_code_editors.
You can see a great example: Console Plugin source code