-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
How to register a command and run it in one step? #476
Comments
The 2-step process is just a quirk from the fact the playground tries to make it possible to call a command from any server, without knowing up front what those commands are called. Assuming that your command does not require any arguments, you should be able to replace the value of pygls/.vscode/extensions/pygls-playground/package.json Lines 29 to 32 in a40a3c3
with the id of your custom command (the string you pass to However, if your command does take arguments or you need to process the return value in any way then I don't think you can avoid writing some TS! 😅 |
Coming back to this after one month! I haven't tried this yet. We are working on a visual component and currently exploring if it's possible to add interaction between a webview and the LSP. I have been thinking there is two possible ways:
|
There are generic I use them to send a few custom messages to
It's also possible to setup a web socket connection with a pygls powered server Yes, it's more complicated than routing the message via VSCode's Webview API, but it does open the door to the webview working with editors other than VSCode. |
Thanks for giving some pointer. I tried to implement this today and using the The request looks like this in the client (it's hard coded now as I just want to test if this mechanism works) lsClient?.sendRequest("textDocument/definition",
{
"textDocument": {
"uri": "file:///Users/Nok_Lam_Chan/dev/kedro/tmp/spaceflights/src/spaceflights/pipelines/data_science/pipeline.py"
},
"position": {
"line": 11,
"character": 29
}
}
); I register this function in a command so I can invoke it with the UI. export async function sendDefinitionRequest(lsClient: LanguageClient | undefined) {
lsClient?.sendRequest("textDocument/definition",
... After that, the server respond with the correct response but the cursor didn't move.
Do I need to handle the response from the client side or is that something VSCode take care of automatically? |
The command is mainly for testing, it mimics when I do For now I am using the |
Yes, you would need to handle the response as using To be honest... I don't know what the "right" way to call
Maybe I'm reading too much into your example, but from the gif it looks like you might want to implement the |
@alcarney Adding symbol would be interesting but I don't think it's suitable in this case. The idea in mind is to embedded this into webview and triggering the Go to Definition from the graph. So the command is temporary for testing just because it is handy to trigger it manually. It won't be needed once we integrate it properly.
This is the logic that I was looking for, but at the end I implemented a simple one just to get started. It roughly looks like this. if (result && result.length > 0) {
const location = result[0];
const uri: vscode.Uri = vscode.Uri.parse(location.uri);
const range = location.range;
vscode.window.showTextDocument(uri,
{
selection: range,
viewColumn: vscode.ViewColumn.One,
}
);
Since you mentioned symbol, is there any example that I can look into. Right now the LSP do the analysis on the demand, I think I will need to build these symbols with cache. |
There is the example Other than that you could go through some of the servers in Implementations.md and see if/how they handle it |
We actually implemented a custom command that that a
|
I found this section in the docs: https://pygls.readthedocs.io/en/v0.10.2/pages/advanced_usage.html#commands
The entrypoint is registered in the playground:
pygls/.vscode/extensions/pygls-playground/package.json
Lines 29 to 32 in a40a3c3
While this works fine, it involves two steps to execute a command:
Is there a way to combine these into 1 step? The alternative is using the VSCode API directly https://code.visualstudio.com/api/extension-guides/command, but it has some downside:
It seems like this is possible by modifying
pygls/.vscode/extensions/pygls-playground/src/extension.ts
Lines 244 to 248 in a40a3c3
The text was updated successfully, but these errors were encountered: