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
Related
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?
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.
I'm creating an extension to add support for a custom language on VS Code and I'm struggling on providing Signature Help because I can't seem to find a way to tell what signature I should show the user unless I manually parse the entire document to find out what is expected.
My question is, does VS Code API provides some way for me to tell the function/etc where the user is when the provider is invoked or do I have to parse the document manually so I can find it by myself?
I'm using the "direct implementation" way (without language servers), if that matters.
I hope my question is clear, thanks in advance.
The obvious way is written in Working with the HTML preview, to use some link, so how to send data to the base running program without clicking links? I want to make some seamless extension between editor and previewer.
A few possible ways:
Open a local communications channel between your extension and the page. The extension could setup a simple server for example that the webview hits. This is best if you have lots of data to send or need to support more complex scenarios.
Inside the webview, you can instead post a message simulating a click with a command. Here's what VSCode's built-in markdown extension does for example:
window.parent.postMessage({
command: 'did-click-link',
data: `command:_markdown.revealLine?${encodeURIComponent(JSON.stringify(args))}`
}, 'file://');
The second approach is pretty hacky but it works well to just trigger events every so often.
We are also considering a better API for this. Please let us know if you have any thoughts or suggestions for this
I use org mode to store shortcuts for my projects. Such org files contain mostly links which I create using org-insert-link. But sometimes the simple link is not sufficient so I have to use lisp functions. This works fine but it does not look very nice.
Is there a way to create a link which would call a lisp function?
you can define new "link types" in org-mode with the function org-add-link-type to which you tell what elisp function you want to call for a particular protocol. So, in your case, you could define new protocols for "http-ie" and "load-xml-dirs" and write wrapper functions to process the parameters right. Then you would write your links as normal org links, but with a protocol prefix.
The example from the documentation page is quite straightforward I guess, let me know if it's not enough.