1

I am writing an LSP server and vscode client and there is a server-side CodeAction that I wish the user to be able to invoke at any time when their cursor is in a text file.

I can see how I can define custom codeactions on the server side, but I just don't know how to expose them on the client side.

e.g. imagine I want the action "CrAzYcAsE at point", I want that to show up as an option in the menu when the user right-clicks anywhere in the file (and I want them to be able to bind this to a key combination if they wish, perhaps even having a default).

In many ways this is the reverse of Is there a way to execute a custom action through the CodeAction request?

I suspect that the answer may be to define a custom Command as per https://code.visualstudio.com/api/references/vscode-api#commands but that doesn't give any examples of a Command that calls the LSP's CodeAction endpoint.

Note that I cannot implement this as a CodeAction "quickfix", since only the user knows when it is relevant to call the action. Registering a quickfix would mean that the yellow question mark would show up on all lines for the user, which would be super distracting for the user.

rioV8
  • 24,506
  • 3
  • 32
  • 49
fommil
  • 5,757
  • 8
  • 41
  • 81

1 Answers1

1

Are you trying to allow the user to trigger a ‘codeActionRequest’ for a specific ‘codeActionKind’ from a Contect menu?

I know you can add context menu items via the contributes section of ‘package.json’. Currently the only way I can think of doing this is registering a custom command in the client that would trigger call the built in code action feature with specific arguments.

I would love to know a better way that doesn’t require client implementation in typescript, if you’ve figured out a way already.