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

Code action request from problems view includes additional diagnostics #161331

Open
suzmue opened this issue Sep 20, 2022 · 2 comments
Open

Code action request from problems view includes additional diagnostics #161331

suzmue opened this issue Sep 20, 2022 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-code-actions Editor inplace actions (Ctrl + .) error-list Problems view help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@suzmue
Copy link
Contributor

suzmue commented Sep 20, 2022

Does this issue occur when all extensions are disabled?: No

  • VS Code Version: 1.71.1
  • OS Version: macOS Monterey version 12.6

Steps to Reproduce:

  1. Have a project that has multiple diagnostics for the same range and where each diagnostic has a suggested fix.
  2. Open the problems view and hover over one of the diagnostics to get the code actions for that diagnostic.

I would expect to see the code action just for that diagnostic, not all diagnostics in the same range. The LSP textDocument/codeAction request includes all of the diagnostics in that range as the context for the codeAction request, not just the selected one in the problems view.

For example, the two diagnostics below have the same line. Getting the quick fixes for one diagnostic, will send a request with both diagnostics included in the context:

Params: {"textDocument":{"uri":"file:///Users/suzmue/govulncheck-study/module5/go.mod"},"range":{"start":{"line":5,"character":1},"end":{"line":5,"character":32}},"context":{"diagnostics":[{"range":{"start":{"line":5,"character":1},"end":{"line":5,"character":32}},"message":"github.com/tidwall/gjson can be upgraded","severity":3,"source":"upgrade available"},{"range":{"start":{"line":5,"character":1},"end":{"line":5,"character":32}},"message":"Vulnerability found:\nA maliciously crafted path can cause Get and other query functions\nto consume excessive amounts of CPU and time.","code":"GO-2021-0265","codeDescription":{"href":"https://pkg.go.dev/vuln/GO-2021-0265"},"severity":2,"source":"vulncheck"}],"triggerKind":2}}

Screen Shot 2022-09-20 at 1 44 50 PM

@mjbvz mjbvz added bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities editor-code-actions Editor inplace actions (Ctrl + .) labels Sep 20, 2022
@mjbvz mjbvz added this to the Backlog milestone Dec 5, 2022
@mjbvz mjbvz added the error-list Problems view label Dec 5, 2022
@DanTup
Copy link
Contributor

DanTup commented Jan 13, 2023

@mjbvz can you confirm how this is intended to work? It seems to me like there are two ways of fixing this:

  1. when opening the code actions list from a diagnostic, VS Code only includes that diagnostic in the list sent to the server (and the server filters)
  2. VS Code filters the list of code actions to only those that have a diagnostic matching the one that's been clicked on

It's not clear to me which is correct. The first one seems to be what's described above, but that makes me wonder why CodeActions would have a diagnostics collection at all. If it's not intended to be used here, what is it for?

@mjbvz
Copy link
Collaborator

mjbvz commented Jan 17, 2023

I think both would fix the issue (and we may want to do both).

I think the first fix is the more important one because it would let extensions / language servers avoid computing code actions for unrelated diagnostics. However the second fix may also be needed for misbehaving extensions that ignore the diagnostics on the code action request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug editor-code-actions Editor inplace actions (Ctrl + .) error-list Problems view help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

4 participants