-
Notifications
You must be signed in to change notification settings - Fork 846
codeAction and executeCommand #394
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
Comments
This is a tricky part of the API right now. I documented my own adventures understanding it here: #144 (comment) It sounds like you're on the right track. You can use |
@rictic Cool ill check that out. Its a little weird I think that codeAction sends over all available commands each time. I would have thought these would be pre-registered somewhere. |
@willt What do you mean by "pre-registered"? The server should only send the commands that are relevant to the selection back to the client. The server does however need to state all the commands that it supports in its What you described is exactly how it's done in my Dockerfile language server. Feel free to take a look at the server's code and the actual implementation of the analysis of the diagnostics and the commands. I don't currently support versioned edits via The light bulb issue has been brought up before. Please see microsoft/vscode#33241, microsoft/vscode#33459, and microsoft/vscode#33555. The final comment is probably what's most relevant as it is the latest update on the issue. Please also see #389 regarding the necessary work to incorporate it into the language server protocol's specification. |
@rcjsuen Thanks for a link to your code. I will check it out. Okay so are you saying when the server receives a codeAction request it would evaluate what text is selected and then decide what commands to send back to the client? If that's correct, do you know if there is a way of dynamically enabling commands in the context menu of vscode ? I know when you setup the commands in package.json you can do "when": "editorHasSelection && editorLangId == python" but I don't think you can dynamically change that can you ? |
What I don't understand is how the client is supposed to know when the "command" has finished executing. Like what if the user changes the document between "applyEdit" commands from the server? It just seems too racy. |
@willt Yes, the And no, I don't know the answer to your second question. I haven't dabbled in the art of writing VS Code extensions myself. @puremourning Right now the response to a |
Versioned edits don’t help from the user perspective. What should we do? Just refuse to apply the codeaction of it changed? What if it is partially applied? Would we even know that given the other problem of the separate channel for the actions vs the request. Ideally the API would be that the apply command request returns an array of actions to perform. That solves all the problems. |
Yes. The client should never partially apply an edit. It should be atomic.
It would be a nice feature if |
Also see #178 which suggests augmenting the |
if we don't know when the full set of edits has been delivered for a command, how is this possible? let's say the server issues two edit requests, with an arbitrary delay between them. when the client receives edit 2, let's say something has changed, but edit 1 has already been applied. Thus you have a torn command with no way for the client to protect it.
If |
If you have a set of edits that must all be applied atomically then they must be sent down as a single
A single WorkspaceEdit should be enough. Maybe that's the missing piece? A WorkspaceEdit contains any number of changes to make to any number of files, so there is no need to return an array of WorkspaceEdits. (Ok, that's not entirely true. I've lobbied in the past for the option for |
Sure. If the server is required to produce a single WorkspaceEdit and nothing else, then why can’t that be the response to the executeCommand request? Otherwise Cthulhu. |
I am closing this now that #389 is in. |
I'm trying to figure out how textDocument/codeAction and workspace/executeCommand
are supposed to work together.
I think what should happen when code is selected and a command is ran like extractMethod is as follows:
Is this correct so far? Does anything further need to happen? Document Syncing or anything ?
Thanks
The text was updated successfully, but these errors were encountered: