[PATCH] D55275: [clangd] Dont provide locations for non-existent files.
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 5 01:21:51 PST 2018
kadircet updated this revision to Diff 176774.
kadircet marked an inline comment as done.
kadircet added a comment.
- Revert rL346488 <https://reviews.llvm.org/rL346488> partially.
Repository:
rCTE Clang Tools Extra
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D55275/new/
https://reviews.llvm.org/D55275
Files:
clangd/AST.cpp
unittests/clangd/SymbolCollectorTests.cpp
Index: unittests/clangd/SymbolCollectorTests.cpp
===================================================================
--- unittests/clangd/SymbolCollectorTests.cpp
+++ 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: clangd/AST.cpp
===================================================================
--- clangd/AST.cpp
+++ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55275.176774.patch
Type: text/x-patch
Size: 2087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181205/8997e081/attachment.bin>
More information about the cfe-commits
mailing list