This is an archive of the discontinued LLVM Phabricator instance.

[RFC][clangd] Check if SelectionTree is complete
Needs ReviewPublic

Authored by kuganv on Sep 11 2023, 2:32 AM.

Details

Summary

clangd in the presence of compilation error can navigate to completely irrelevant destinations. This is often a problem for headers that cannot be compiled standalone. For example, go-to-def often jumps to containing namespace because the selection tree just consists of namespace (when relevant AST nodes were missing due to compilation error). This is known issue that is hard to solve without using some heuristic. One such heuristic is to check the nodes in the selection tree for the exact line match. In the absence of such match, we do not provide navigation. IMO, this is better than jumping to wrong position.

TODO:

  • This currently does not have test cases but I will add test cases based on the feedback for the heuristic.
  • Enable only when there is compilation error.

Diff Detail

Event Timeline

kuganv created this revision.Sep 11 2023, 2:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 11 2023, 2:32 AM
kuganv retitled this revision from [clangd] Check if SelectionTree is complete to [RFC][clangd] Check if SelectionTree is complete.Sep 11 2023, 2:54 AM
kuganv edited the summary of this revision. (Show Details)
kuganv updated this revision to Diff 556418.Sep 11 2023, 4:55 AM
kuganv edited the summary of this revision. (Show Details)

Rebased

kuganv edited the summary of this revision. (Show Details)Sep 11 2023, 5:08 AM
kuganv published this revision for review.Sep 11 2023, 6:29 AM
kuganv added a comment.Oct 2 2023, 5:33 AM

ping? Any thoughts. Thanks.

ArcsinX added a subscriber: ArcsinX.Nov 2 2023, 4:29 AM

One such heuristic is to check the nodes in the selection tree for the exact line match

It looks like this heuristic doesn't work well in multiline cases.
E.g.

int
f^unc() {
  return 0;
}

will give empty result with this patch applied.