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

Return code actions of the source type for the current cursor position? #1554

Closed
rchl opened this issue Sep 24, 2022 · 3 comments · Fixed by #1856
Closed

Return code actions of the source type for the current cursor position? #1554

rchl opened this issue Sep 24, 2022 · 3 comments · Fixed by #1856
Milestone

Comments

@rchl
Copy link
Contributor

rchl commented Sep 24, 2022

VSCode and other editors request code actions whenever caret/selection is changed. Those requests don't specify any "kinds" in context.only. Is server expected to return code action types of the source kind in this case?

Empirical evidence shows that:

  • Many servers don't return source code actions unless explicitly asked for those using context.only: ['source'] (which happens when explicitly triggering Source actions... menu item in VSCode, for example).
  • Even if server returns source code action in that case, editor (VSCode) filters out the source kind and doesn't show in the view as an annotation or a bulb icon.

Questions:

  • Is that intention that servers don't return source code actions unless explicitly asked?
  • Is the intention that editors filter out source code actions for cases when request is made for the current caret position in the file?
  • (Bonus question) Should request for the source code actions include whole document range and all active diagnostics in the file (currently not the case in VSCode, for example)?
@dbaeumer
Copy link
Member

dbaeumer commented Oct 4, 2022

Actually this has some legacy / backwards compatibility issues :-)

At the beginning there weren't any source or refactoring code actions. Code actions were solely used to (quick) fix code, not to write / rewrite code. So if a client asks for code actions without any kind the standard quick fix code actions should be returned.

If a server returns more code actions (e.g. includes source code actions) clients are allowed to filter them to ensure UI consistency.

Is that intention that servers don't return source code actions unless explicitly asked?

As said the minimum a server needs to return are the default quick fix actions. It is allowed to return more and clients other than VS Code might do something with them. However VS Code decided to drop them

Is the intention that editors filter out source code actions for cases when request is made for the current caret position in the file?

This is up to the client to decide.

(Bonus question) Should request for the source code actions include whole document range and all active diagnostics in the file (currently not the case in VSCode, for example)?

We decided not to do this. Reason is that a server can easily compute all active diagnostics for the given file. The diagnostics provided in a code action request are hints for the server to know which errors the user currently sees. If you run a source code action (for example fixAll) this is not very useful since the server should fix all errors and not rely on what the user sees in the context.

Hope that makes sense.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Oct 4, 2022
@rchl
Copy link
Contributor Author

rchl commented Oct 4, 2022

Thank you. This makes it much clearer.

I do think that something of the effect of what you wrote below should be in the spec to make this official:

At the beginning there weren't any source or refactoring code actions. Code actions were solely used to (quick) fix code, not to write / rewrite code. So if a client asks for code actions without any kind the standard quick fix code actions should be returned.

@dbaeumer
Copy link
Member

dbaeumer commented Oct 5, 2022

Agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants