Skip to content

Example: adding a refactor action

ZacNugent edited this page Jul 1, 2020 · 1 revision

Adding a 'split to joinpath' action

codeAction requests get called at the current cursors position and are processed in two steps by the server:

  1. Can we do anything here? If so, send the client (editor) a list of exciting things I can do.

(Then, if the user selects some option.)

  1. Do that cool (?) thing.. This takes some parameters: what do you want do, where do you want to do it (file, position within file) and sends back the relevant edits to the document.

Step 1

In this instance I would have thought this is simple - we only want to offer this if the cursor is currently on (x represents the current thing under the cursor) a string (or perhaps a string that includes path separators). This would be relevant.

Step 2

We should then be in the position of needing to create a function that creates a LanguageServer.WorkspaceEdit to send back to the client, much like this does (but even simpler).

Conclusion

So step 1 needs an additional branch added to textDocument_codeAction_request to alert the client of the availability of the action (as appropriate). It also needs the ability to respond to the request to carry out that action in workspace_executeCommand_request and an appropriate function to do the actual work. The client also needs to be told about this command at startup https://github.com/julia-vscode/LanguageServer.jl/blob/master/src/requests/init.jl#L26.

Clone this wiki locally