This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Untangle Hover from XRefs, move into own file.
ClosedPublic

Authored by sammccall on Nov 16 2019, 8:06 AM.

Details

Summary

This is mostly mechanical, with a few exceptions:

  • getDeducedType moved into AST.h where it belongs. It now takes ASTContext instead of ParsedAST, and avoids using the preprocessor.
  • hover now uses SelectionTree directly rather than via getDeclAtPosition helper
  • hover on 'auto' used to find the decl that contained the 'auto' and use that to set Kind and documentation for the hover result. Now we use targetDecl() to find the decl matching the deduced type instead. This changes tests, e.g. 'variable' -> class for auto on lambdas. I think this is better, but the motivation was to avoid depending on the internals of DeducedTypeVisitor. This functionality is removed from the visitor.

Diff Detail

Event Timeline

sammccall created this revision.Nov 16 2019, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2019, 8:06 AM
sammccall updated this revision to Diff 229696.Nov 16 2019, 8:10 AM

Include omitted files

Build result: pass - 60143 tests passed, 0 failed and 729 were skipped.
Log files: console-log.txt, CMakeCache.txt

Build result: pass - 60143 tests passed, 0 failed and 729 were skipped.
Log files: console-log.txt, CMakeCache.txt

@kuhnel: I think the premerge guards bot is acting up here: the first snapshot was definitely broken (missing files).
And even the second the ninja logs don't show building the new files. I think it might just be building the tree without patching? The console log shows errors around the arc patch step, and suspiciously few details about the patch being applied.

kadircet added inline comments.Nov 18 2019, 2:45 AM
clang-tools-extra/clangd/Hover.cpp
375

nit: SM.getFileOffset(SourceLocationBeg) ?

375

why not just expose getDeclAtPosition in AST.h ?

clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
80

nit: while there, maybe get rid of braces as well?

clang-tools-extra/clangd/unittests/ASTTests.cpp
13

unintended newline ?

sammccall marked 4 inline comments as done.Nov 18 2019, 12:55 PM
sammccall added inline comments.
clang-tools-extra/clangd/Hover.cpp
375

nit: SM.getFileOffset(SourceLocationBeg) ?

I was deliberately trying to avoid using the "rewind token" logic where it's not needed. We've had bugs with it before, as well as with selectiontree, and composing them unneccesarily is harder to debug.

why not just expose getDeclAtPosition in AST.h ?

I don't think it's better than the expanded form - it's just plugging a couple of functions together, and the choices it makes (flattening SourceLocation into an offset, the DeclRelationSet, only looking at the common ancestor and nothing higher up) aren't obvious.

It also privileges decls over other types of things (e.g. the followup patch looks for Exprs in the selection tree to show their values, and that couldn't happen if it was hidden behind getDeclAtPosition)

clang-tools-extra/clangd/unittests/ASTTests.cpp
13

intended (subproject vs clang) but dosen't seem to match local style. removed

sammccall marked an inline comment as done.

address comments

kadircet accepted this revision.Nov 19 2019, 1:40 AM
kadircet added inline comments.
clang-tools-extra/clangd/Hover.cpp
375

I was deliberately trying to avoid using the "rewind token" logic where it's not needed. We've had bugs with it before, as well as with selectiontree, and composing them unneccesarily is harder to debug.

Sounds good, I was worried about performing this conversion twice, but I suppose it should be OK for hover's performance.

381

nit: Unused

This revision is now accepted and ready to land.Nov 19 2019, 1:40 AM
kuhnel removed a subscriber: kuhnel.Nov 19 2019, 3:29 AM
This revision was automatically updated to reflect the committed changes.