1

I want to initiate a user action from Visual studio code. which would read the current opened text document, extract a piece of code by some kind of UI action (a custom button, or through CodeAction if possible), send it to the server using the Language Server Protocol, does some work and returns some output back to client.

I've read the Language Server Protocol specifications for CodeAction but its normally used only for quickfixes and refactoring, can i use it for any other custom action? If so, how?

Mansoor
  • 11
  • 2

1 Answers1

1

Code actions can invoke arbitrary client-side commands when they're executed:

export interface CodeAction {
    [...]

    /**
     * A command this code action executes. If a code action
     * provides an edit and a command, first the edit is
     * executed and then the command.
     */
    command?: Command;
}

You can register new commands using the vscode.commands namespace.

[...] send it to the server using the Language Server Protocol, does some work and returns some output back to client

For this part, you can use custom methods to send data back and forth between the language server and the VSCode extension:


Both of these things of course make your language server much less compatible with clients other than VSCode. Are you sure you need client-side logic for this?

Gama11
  • 31,714
  • 9
  • 78
  • 100
  • Well i want to send code to the Language server, and then do some manipulation, which then generates a Control Flow Graph (in dot language) as string , which then i want to render using the webview api, so as my language server is written in F# and doesn't use the built in functionality from the vscode-language server npm package, i am not sure how i would do all of the that on the server-side and in F#, couldn't find any related information regarding this on the internet, so i thought the simpler way would be to send the output back to the client and then generate the WebView. – Mansoor Aug 19 '19 at 11:25
  • It shouldn't matter too much what language a language server is written in, you should still be able to call custom methods. Unless you're using some API that has abstracted all that away and doesn't let you access the communication layer... – Gama11 Aug 19 '19 at 11:48