[PATCH] D112712: [clangd] SelectionTree should prefer lexical declcontext
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 28 05:59:50 PDT 2021
kadircet updated this revision to Diff 383008.
kadircet edited the summary of this revision.
kadircet added a comment.
- Related https://github.com/clangd/clangd/issues/900.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112712/new/
https://reviews.llvm.org/D112712
Files:
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -739,6 +739,21 @@
EXPECT_EQ(1u, Seen) << "one tree for nontrivial selection";
}
+TEST(SelectionTest, DeclContext) {
+ llvm::Annotations Test("namespace a { void $1^foo(); } void a::$2^foo();");
+ auto AST = TestTU::withCode(Test.code()).build();
+ {
+ auto ST = SelectionTree::createRight(AST.getASTContext(), AST.getTokens(),
+ Test.point("1"), Test.point("1"));
+ EXPECT_FALSE(ST.commonAncestor()->getDeclContext().isTranslationUnit());
+ }
+ {
+ auto ST = SelectionTree::createRight(AST.getASTContext(), AST.getTokens(),
+ Test.point("2"), Test.point("2"));
+ EXPECT_TRUE(ST.commonAncestor()->getDeclContext().isTranslationUnit());
+ }
+}
+
} // namespace
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -897,7 +897,7 @@
if (CurrentNode != this)
if (auto *DC = dyn_cast<DeclContext>(Current))
return *DC;
- return *Current->getDeclContext();
+ return *Current->getLexicalDeclContext();
}
}
llvm_unreachable("A tree must always be rooted at TranslationUnitDecl.");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112712.383008.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211028/c82c2383/attachment.bin>
More information about the cfe-commits
mailing list