Skip to content
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

Is there a server that would produce both an edit and a command in a single CodeAction? #2002

Open
bstaletic opened this issue Aug 13, 2024 · 8 comments
Labels
info-needed Issue requires more information from poster

Comments

@bstaletic
Copy link
Contributor

I am updating my client's code action support.
I am unsure how to implement code actions with mixed edit and command in them.
Having a server to test against would be very useful.
If there is such a server, knowing how to trigger this use case would also be appreciated.

@bstaletic
Copy link
Contributor Author

Another question is:

In the "mixed code action" case, do clients have to apply the edit, send didChange notification(s) and only then execute the command?
Or can clients agreggate the edit with the changes that executing the command produces and only then actually apply?

@HighCommander4
Copy link

Clangd doesn't currently use both an edit and a command, but a potential use case for this is discussed in the conversation starting at clangd/clangd#1367 (comment).

@dbaeumer
Copy link
Member

If you have both a edit and a command, first the edit should be applied, including sending out change notifications and then the command should be applied.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Aug 13, 2024
@puremourning
Copy link

If you have both a edit and a command, first the edit should be applied, including sending out change notifications and then the command should be applied.

What is the purpose of this complex feature? What use cases is it for?

@dbaeumer
Copy link
Member

  • historical reasons
  • to trigger API commands if the client supports them (this is client specific)
  • to let the server know about the execution of a code action in case there needs to be some follow-up work.

@HighCommander4
Copy link

To add to the above, clangd's use case is deferring the expensive computation of a text edit to after a completion item has been selected (so that the computation only has to be done for the selected proposal, not all offered proposals).

@DanTup
Copy link
Contributor

DanTup commented Sep 4, 2024

The Dart LSP server sometimes does this when the edits are inlined (because they were already computed), so that the server knows that the action was invoked (for ex. if analytics are enabled, metrics on the number of times each action is used can be collected):

{
	"command": {
		"arguments": [
			{
				"action": "dart.assist.add.typeAnnotation"
			}
		],
		"command": "dart.logAction",
		"title": "Log Action"
	},
	"diagnostics": [],
	"edit": {
		"documentChanges": [/*...*/]
	},
	"kind": "refactor.add.typeAnnotation",
	"title": "Add type annotation"
}

If you want to test with it, this can be triggered by having the code a = 1; in a .dart file and sending a CodeAction request on the a to get the Add type annotation" action. The Dart LSP server is part of the Dart SDK and started with dart language-server`.

@bstaletic
Copy link
Contributor Author

I have managed to implement this kind of "mixed" code actions.
@DanTup Thanks for pointing me in the Dart direction.
@dbaeumer Thaks for clarifying the client expectation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants