This is an archive of the discontinued LLVM Phabricator instance.

[clangd] SelectionTree treats TranslationUnitDecl consistently with other containers.
ClosedPublic

Authored by sammccall on Jul 22 2019, 10:07 AM.

Details

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Jul 22 2019, 10:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2019, 10:07 AM
hokein added inline comments.Jul 23 2019, 1:13 AM
clang-tools-extra/clangd/Selection.h
100 ↗(On Diff #211138)

I think it would be nice to mention "what means no selection" (TUDecl with partial)?

And it seems that we are missing some documentation describing the selection tree behavior on the preprocessor elements e.g. #incl^ude, header guard.

clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
47 ↗(On Diff #211138)

we'll get a TUDecl if the whole file is selected, however this tweak doesn't want to traversal the whole TU (otherwise we will generate highlighting tokens for #included files), we only interested in the top level decls of the main file.

clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
38 ↗(On Diff #211138)

Is the N->Parent intended? this seems like we'd exclude the TUDecl?

sammccall updated this revision to Diff 211458.Jul 24 2019, 3:35 AM

Reverted commonAncestor() back to a pointer, return null if ancestor is TUDecl.

sammccall marked 3 inline comments as done.Jul 24 2019, 3:39 AM
sammccall added inline comments.
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
47 ↗(On Diff #211138)

Right! We discussed this further offline, and came to the conclusions that:

  • traversing the whole TU is undesirable almost always
  • it's already possible to get the whole TU from commonAncestor today (by selecting multiple top-level decls), and there are resulting bugs
  • returning null instead of TU from commonAncestor() is a safer default
clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
38 ↗(On Diff #211138)

This is obsolete now, but was useful to flag: it's exactly the type of question that tweaks shouldn't have to worry about by default.

sammccall updated this revision to Diff 211459.Jul 24 2019, 3:42 AM
sammccall marked 3 inline comments as done.

doc selectiontree's interactions with preprocessor

hokein accepted this revision.Jul 24 2019, 3:53 AM

looks good!

This revision is now accepted and ready to land.Jul 24 2019, 3:53 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2019, 5:14 AM