... if there is a match.
This is needed to that clients can can make a connection between a
diagnostic and an associated quickfix-tweak.
Ideally, quickfix-kind tweak code actions would be provided inline along
with the non-tweak fixes, but this doesn't seem easily achievable.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This is assuming a semantic connection that we don't know exists.
Without any more specific reason to draw this connection, this seems like a heuristic that could equally be applied by the client.
Is there a particular action/diagnostic pair you want this for?
This is assuming a semantic connection that we don't know exists.
Without any more specific reason to draw this connection, this seems like a heuristic that could equally be applied by the client.
The difference being that the client would have to poke around in the technically opaque Command structure to find the range.
Seems possible, but presumably there are no guarantees about the properties?
Is there a particular action/diagnostic pair you want this for?
Yes, -Wswitch/PopulateSwitch (which is the only quickfix kind of tweak at the moment).
TL;DR: I think this makes sense to add, but we should make it slightly more restrictive.
FWIW, I don't think poking in command is required: the test you're adding here is that:
- tweak kind is quickfix: tweak kind is exposed as CodeAction.kind
- diag range == params.range: both diag and params are supplied by the client
However the protocol is complicated enough here as it is without adding client-side heuristics, we should probably have the server signal them explicitly if we think they're safe.
Is there a particular action/diagnostic pair you want this for?
Yes, -Wswitch/PopulateSwitch (which is the only quickfix kind of tweak at the moment).
Yes, makes sense. I think we added the "preferred" logic as a hack.
FWIW, VSCode accepts this as associating the diagnostic with the fix, even without CodeAction.Diagnostics set.
But doing this with CodeAction.diagnostics makes at least as much sense, so let's support that.
clang-tools-extra/clangd/ClangdLSPServer.cpp | ||
---|---|---|
1002 | This loop is closely related to what you're doing (and the one above isn't). Maybe we can refactor/combine as something like: Optional<CodeAction *> OnlyFix; // nullptr means multiple fixes // ... loop over actions and set OnlyFix ... if (OnlyFix && *OnlyFix) { (*OnlyFix)->isPreferred = true; if (Diags.size() == 1 && Diags.front().range == Selection) (*OnlyFix)->diagnostics = {Diags.front()]; } Note this adds the conditions:
I think these reduce the chance of false positives. |
Formatting & logic.
clang-tools-extra/clangd/ClangdLSPServer.cpp | ||
---|---|---|
1002 | Done. Though it seems the code would work just as well with OnlyFix staying a normal pointer. Did I misunderstand something? |
clang-tools-extra/clangd/ClangdLSPServer.cpp | ||
---|---|---|
1002 | Oops, I missed the break in the loop. |
This loop is closely related to what you're doing (and the one above isn't).
Maybe we can refactor/combine as something like:
Note this adds the conditions:
I think these reduce the chance of false positives.