This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Selection handles CXXBaseSpecifier
ClosedPublic

Authored by njames93 on Jan 22 2021, 6:44 AM.

Details

Summary

Selection now includes the virtual and access modifier as part of their range for cxx base specifiers.

Diff Detail

Event Timeline

njames93 created this revision.Jan 22 2021, 6:44 AM
njames93 requested review of this revision.Jan 22 2021, 6:44 AM
njames93 updated this revision to Diff 318523.Jan 22 2021, 7:34 AM

Update FindTargets to fix symbol renaming on a CXXBaseSpecifier.
Add test to ensure rename wont trigger on a CXXBaseSpecifier.

nridge added a subscriber: nridge.Jan 24 2021, 12:26 AM
njames93 added inline comments.Jan 24 2021, 6:49 AM
clang-tools-extra/clangd/unittests/SelectionTests.cpp
272–283

Is this good behaviour, or should Foo selection resolve as a RecordTypeLoc, That is the behaviour previously observed for these 2 cases. And instead have CXXBaseSpecifier as its parent selection?

sammccall added inline comments.Jan 25 2021, 1:27 AM
clang-tools-extra/clangd/Selection.cpp
496

can we not use traverseNode here, rather than repeating?

clang-tools-extra/clangd/unittests/SelectionTests.cpp
272–283

Yes, this should be a typeloc with the CXXBaseSpecifier as its parent, unless there's a really compelling reason to make an exception.

Two main reasons:

  • it matches RecursiveASTVisitor's idea of the tree shape, which people mostly understand. If we diverge, it'll be a special case we need to remember and so potentially a source of bugs.
  • This allows code that handles types generically to work with fewer special cases. (I do like the FindTarget change though - it seems reasonable to allow go-to-def on e.g. the public keyword) It still preserves flexibility if we want to handle types as base-specifiers specially (we can examine the parent)
clang/lib/AST/ASTTypeTraits.cpp
196

nice, thanks!
We should probably have a test for this (in ASTTypeTraitsTest.cpp there's a simple pattern to follow for sourcerange)

njames93 marked 2 inline comments as done.Jan 25 2021, 2:23 AM
njames93 added inline comments.
clang-tools-extra/clangd/Selection.cpp
496

Yeah, especially now I'm changing it to actually traverse :)

clang-tools-extra/clangd/unittests/SelectionTests.cpp
272–283

OK, funnily enough that change to find target was to fix renaming when the recordtypeloc was removed from the selection. That change will be redundant if i fix that, but do you still want it in here?

clang/lib/AST/ASTTypeTraits.cpp
196

Not really trivial as there is no matcher for cxxBaseSpecifier. Annoyingly its my fault there isn't one.

njames93 updated this revision to Diff 318930.Jan 25 2021, 2:24 AM
njames93 marked 2 inline comments as done.

Update behaviour to keep RecordTypeLoc seletion.

sammccall accepted this revision.Jan 25 2021, 2:28 AM

(I don't see a new snapshot but LG with the traverseNode change)

clang-tools-extra/clangd/unittests/SelectionTests.cpp
272–283

Up to you, but I'd lean towards keeping it and adding a FindTarget test for struct S : ^private T or so, which is the visible change.

clang/lib/AST/ASTTypeTraits.cpp
196

Oh, I've been down this rabbithole recently... clangd support for attrs -> DynTypedNode support for Attr -> matchers for use in tests -> matchers get complicated...

Let's not block on this (and I need to revive my attr patch that got too big...)

This revision is now accepted and ready to land.Jan 25 2021, 2:28 AM
njames93 marked 2 inline comments as done.Jan 25 2021, 2:40 AM
njames93 added inline comments.
clang-tools-extra/clangd/unittests/SelectionTests.cpp
272–283

I think I should remove it, then add it back in a follow up. It was needed to fix a issue in here that was then resolved in here.

njames93 updated this revision to Diff 318933.Jan 25 2021, 2:42 AM
njames93 marked an inline comment as done.

Remove FindTarget to instead add in a follow up patch.
Side note, Think I'll wait til after tomorrow to land this, unsure if the changes will break anything elsewhere.

This revision was automatically updated to reflect the committed changes.