This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix go-to-type target location
ClosedPublic

Authored by sammccall on Jul 20 2023, 3:23 PM.

Details

Summary

Previously it'd ~always jump to the lexically first declaration, which was
often an unhelpful forward declaration.

  • consult the index for definition and preferred declaration locations (query code shared with go-to-definition)
  • when unwrapping to LSP, prefer definition to declaration This matches "go-to-definition", which is the most common go-to operation

Diff Detail

Event Timeline

sammccall created this revision.Jul 20 2023, 3:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 3:23 PM
sammccall requested review of this revision.Jul 20 2023, 3:23 PM
usaxena95 accepted this revision.Jul 21 2023, 3:58 AM
usaxena95 added inline comments.
clang-tools-extra/clangd/XRefs.cpp
347

nit: ResultIndex looks like an implementation detail of this function and the callers do not need it. SymbolID is already present as LocatedSymbol::ID so we can compute this map in this function itself.

This revision is now accepted and ready to land.Jul 21 2023, 3:58 AM
sammccall marked an inline comment as done.Jul 21 2023, 2:04 PM
sammccall added inline comments.
clang-tools-extra/clangd/XRefs.cpp
347

Nice catch! We were in fact computing all the symbol ids twice, too..

This revision was landed with ongoing or failed builds.Jul 21 2023, 2:11 PM
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.