-
Notifications
You must be signed in to change notification settings - Fork 81
Example: adding a refactor action
codeAction requests get called at the current cursors position and are processed in two steps by the server:
- 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.)
- 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.
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.
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).
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.