This revision was automatically updated to reflect the committed changes. Closed by commit rL348359: [clangd] Dont provide locations for non-existent files. (authored by kadircet, committed by ). Herald added a subscriber: llvm-commits.
Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55275/new/ https://reviews.llvm.org/D55275 Files: clang-tools-extra/trunk/clangd/AST.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Index: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp @@ -614,6 +614,18 @@ DeclURI(TestHeaderURI)))); } +TEST_F(SymbolCollectorTest, SymbolFormedByCLI) { + Annotations Header(R"( + #ifdef NAME + class $expansion[[NAME]] {}; + #endif + )"); + runSymbolCollector(Header.code(), /*Main=*/"", /*ExtraArgs=*/{"-DNAME=name"}); + EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf( + QName("name"), DeclRange(Header.range("expansion")), + DeclURI(TestHeaderURI)))); +} + TEST_F(SymbolCollectorTest, IgnoreSymbolsInMainFile) { const std::string Header = R"( class Foo {}; Index: clang-tools-extra/trunk/clangd/AST.cpp =================================================================== --- clang-tools-extra/trunk/clangd/AST.cpp +++ clang-tools-extra/trunk/clangd/AST.cpp @@ -23,9 +23,11 @@ namespace clangd { // Returns true if the complete name of decl \p D is spelled in the source code. -// This is not the case for symbols formed via macro concatenation. -// (We used to attempt to treat names spelled on the command-line this way too, -// but the preamble doesn't preserve the required information). +// This is not the case for: +// * symbols formed via macro concatenation, the spelling location will +// be "<scratch space>" +// * symbols controlled and defined by a compile command-line option +// `-DName=foo`, the spelling location will be "<command line>". bool isSpelledInSourceCode(const Decl *D) { const auto &SM = D->getASTContext().getSourceManager(); auto Loc = D->getLocation(); @@ -33,7 +35,8 @@ // macros, we should use the location where the whole definition occurs. if (Loc.isMacroID()) { std::string PrintLoc = SM.getSpellingLoc(Loc).printToString(SM); - if (StringRef(PrintLoc).startswith("<scratch")) + if (StringRef(PrintLoc).startswith("<scratch") || + StringRef(PrintLoc).startswith("<command line>")) return false; } return true;
Index: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp @@ -614,6 +614,18 @@ DeclURI(TestHeaderURI)))); } +TEST_F(SymbolCollectorTest, SymbolFormedByCLI) { + Annotations Header(R"( + #ifdef NAME + class $expansion[[NAME]] {}; + #endif + )"); + runSymbolCollector(Header.code(), /*Main=*/"", /*ExtraArgs=*/{"-DNAME=name"}); + EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf( + QName("name"), DeclRange(Header.range("expansion")), + DeclURI(TestHeaderURI)))); +} + TEST_F(SymbolCollectorTest, IgnoreSymbolsInMainFile) { const std::string Header = R"( class Foo {}; Index: clang-tools-extra/trunk/clangd/AST.cpp =================================================================== --- clang-tools-extra/trunk/clangd/AST.cpp +++ clang-tools-extra/trunk/clangd/AST.cpp @@ -23,9 +23,11 @@ namespace clangd { // Returns true if the complete name of decl \p D is spelled in the source code. -// This is not the case for symbols formed via macro concatenation. -// (We used to attempt to treat names spelled on the command-line this way too, -// but the preamble doesn't preserve the required information). +// This is not the case for: +// * symbols formed via macro concatenation, the spelling location will +// be "<scratch space>" +// * symbols controlled and defined by a compile command-line option +// `-DName=foo`, the spelling location will be "<command line>". bool isSpelledInSourceCode(const Decl *D) { const auto &SM = D->getASTContext().getSourceManager(); auto Loc = D->getLocation(); @@ -33,7 +35,8 @@ // macros, we should use the location where the whole definition occurs. if (Loc.isMacroID()) { std::string PrintLoc = SM.getSpellingLoc(Loc).printToString(SM); - if (StringRef(PrintLoc).startswith("<scratch")) + if (StringRef(PrintLoc).startswith("<scratch") || + StringRef(PrintLoc).startswith("<command line>")) return false; } return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits