[PATCH] D54303: [clangd] Don't treat top-level decls as "local" if they are from the preamble.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 9 05:05:35 PST 2018
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ioeric.
These get passed to HandleTopLevelDecl() if they happen to have been
deserialized for any reason. We don't want to treat them as part of the
main file.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D54303
Files:
clangd/ClangdUnit.cpp
unittests/clangd/ClangdUnitTests.cpp
Index: unittests/clangd/ClangdUnitTests.cpp
===================================================================
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -257,6 +257,20 @@
}
}
+TEST(ClangdUnitTest, TopLevelDecls) {
+ TestTU TU;
+ TU.HeaderCode = R"(
+ int header1();
+ int header2;
+ )";
+ TU.Code = "int main();";
+ auto AST = TU.build();
+ ASSERT_EQ(AST.getLocalTopLevelDecls().size(), 1u);
+ NamedDecl *ND = dyn_cast<NamedDecl>(AST.getLocalTopLevelDecls().front());
+ ASSERT_TRUE(ND);
+ ASSERT_EQ("main", ND->getNameAsString());
+}
+
} // namespace
} // namespace clangd
} // namespace clang
Index: clangd/ClangdUnit.cpp
===================================================================
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -57,6 +57,9 @@
bool HandleTopLevelDecl(DeclGroupRef DG) override {
for (Decl *D : DG) {
+ if (D->isFromASTFile())
+ continue;
+
// ObjCMethodDecl are not actually top-level decls.
if (isa<ObjCMethodDecl>(D))
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54303.173303.patch
Type: text/x-patch
Size: 1077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181109/29e3083d/attachment.bin>
More information about the cfe-commits
mailing list