[clangd] Don't treat top-level decls as "local" if they are from the preamble.
Summary: 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. Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54303 llvm-svn: 346503
This commit is contained in:
parent
f3cae3ab4c
commit
9ac2f7a1f8
|
@ -57,6 +57,9 @@ public:
|
|||
|
||||
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;
|
||||
|
|
|
@ -257,6 +257,28 @@ Bar* bar;
|
|||
}
|
||||
}
|
||||
|
||||
MATCHER_P(DeclNamed, Name, "") {
|
||||
if (NamedDecl *ND = dyn_cast<NamedDecl>(arg))
|
||||
if (ND->getName() == Name)
|
||||
return true;
|
||||
if (auto *Stream = result_listener->stream()) {
|
||||
llvm::raw_os_ostream OS(*Stream);
|
||||
arg->dump(OS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST(ClangdUnitTest, TopLevelDecls) {
|
||||
TestTU TU;
|
||||
TU.HeaderCode = R"(
|
||||
int header1();
|
||||
int header2;
|
||||
)";
|
||||
TU.Code = "int main();";
|
||||
auto AST = TU.build();
|
||||
EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace clangd
|
||||
} // namespace clang
|
||||
|
|
Loading…
Reference in New Issue