This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Retain main file fixes attached to diags from preamble
ClosedPublic

Authored by kadircet on Mar 23 2022, 7:34 AM.

Details

Summary

Clangd ignores fixits if the diagnsotics is outside the main file (e.g.
a note on a declaration from a header), but the fix might still be inside the
main file (e.g. change the function call).

This patch changes the logic to retain fixes that touch main file, if the
diagnostic owning them is still inside main file, even if they are attached to a
note outside the main file.

Diff Detail

Event Timeline

kadircet created this revision.Mar 23 2022, 7:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2022, 7:34 AM
kadircet requested review of this revision.Mar 23 2022, 7:34 AM
sammccall accepted this revision.Mar 23 2022, 9:04 AM
sammccall added inline comments.
clang-tools-extra/clangd/Diagnostics.cpp
68

update comment: Fixes are only added if the fix or diagnostics is in the main file.

705–706

I think this can now be inlined to the one place it's used

724

Note that this may still miss some cases, e.g. if we had a diagnostic inside a template instantiation with a fix in the current file. tryMoveToMainFile has not been called yet, so LastDiag->InsideMainFile would be false.

I don't have a great idea about what to do about this, nor does it seem that important...

This revision is now accepted and ready to land.Mar 23 2022, 9:04 AM
kadircet updated this revision to Diff 417873.Mar 24 2022, 3:38 AM
kadircet marked 2 inline comments as done.
  • Get rid of redundant local variable
  • Update comment around assumptions about main file-ness inside toLSPDiag.
clang-tools-extra/clangd/Diagnostics.cpp
68

as discussed offline, this is still the case and it isn't an or but an and, i.e. we preserve a fix if it's in the main file AND the primary diagnostic we'll attach it to is also inside the main file.