This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Remove redundant emptiness check in cross ref calculation for includes.
ClosedPublic

Authored by VitaNuo on Jul 18 2023, 8:48 AM.

Diff Detail

Event Timeline

VitaNuo created this revision.Jul 18 2023, 8:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 8:48 AM
VitaNuo requested review of this revision.Jul 18 2023, 8:48 AM
VitaNuo added a subscriber: usaxena95.
usaxena95 added inline comments.Jul 18 2023, 12:10 PM
clang-tools-extra/clangd/XRefs.cpp
1361–1362

Sorry for the confusion. This looks intentional and somewhat valuable for unused headers. We could fix this on clang-review's end as discussed on the internal patch. We should also add a comment here explaining the rationale behind returning no refs in such cases.

(The check below certainly looks redundant though and could be removed).

kadircet added inline comments.Jul 19 2023, 12:19 AM
clang-tools-extra/clangd/XRefs.cpp
1365

i guess this patch is not needed anymore, but one comment about this behaviour in clangd as well (no action needed in this patch)

why are we providing the reference to the include line itself? in other interactions we do that for the sake of completeness (e.g. if you trigger xrefs on a reference, seeing the declaration/definition location is useful) but usually the result under the cursor is not so interesting, especially in this case. the include line itself is drastically different than the nature of other references, the user can only see the include, if they triggered the xrefs on the include line itself and not when they trigger it on the symbol. also that ref doesn't count if there's no symbols used?

FWIW I am not sure if that's a useful interaction. What was the rationale here exactly? It might be useful to always emit this reference, but also append provider to the refs list in the other direction as well (that way the results will be coherent again)

VitaNuo retitled this revision from [clangd] Make an include always refer to itself. Background: clang-review expects all referents to have definition, declaration or reference(s). to [clangd] Remove redundant emptiness check in cross ref calculation for includes..Jul 19 2023, 1:25 AM
VitaNuo updated this revision to Diff 541882.Jul 19 2023, 1:29 AM
VitaNuo marked 2 inline comments as done.

Remove only one of the checks.

VitaNuo accepted this revision.Jul 19 2023, 1:30 AM
VitaNuo added inline comments.
clang-tools-extra/clangd/XRefs.cpp
1361–1362

Yeah you're right the second check is redundant (probably an artefact of some unfinished refactoring). I will land this patch with the redundant check removed.

1365

I think the rationale was that it provides more clarity in the VS Code UI. If you look back at the prototype image in the internal design doc, the references list always looks like a dropdown list with the containing file (in this case main file only) as title. In case of normal references, it shows the same symbol in different contexts, and it makes sense intuitively. In case of includes, it looks like a forest of unconnected symbols and might look like a bug to a user. IIRC that's the reason we initially agreed to add clarity by adding the include line itself.

This revision is now accepted and ready to land.Jul 19 2023, 1:30 AM
This revision was landed with ongoing or failed builds.Jul 19 2023, 1:33 AM
This revision was automatically updated to reflect the committed changes.