[PATCH] D76098: [clangd] Do not trigger go-to-def textual fallback inside string literals
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 19 14:50:19 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb89202e842ac: [clangd] Do not trigger go-to-def textual fallback inside string literals (authored by nridge).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76098/new/
https://reviews.llvm.org/D76098
Files:
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -644,7 +644,8 @@
// Comment mentioning M^yClass
)cpp",
R"cpp(// String
- struct [[MyClass]] {};
+ struct MyClass {};
+ // Not triggered for string literal tokens.
const char* s = "String literal mentioning M^yClass";
)cpp",
R"cpp(// Ifdef'ed out code
@@ -696,7 +697,7 @@
EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
}
}
-}
+} // namespace
TEST(LocateSymbol, Ambiguous) {
auto T = Annotations(R"cpp(
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -374,6 +374,18 @@
unsigned WordOffset = Word.data() - Code.data();
SourceLocation WordStart = SM.getComposedLoc(File, WordOffset);
+ // Attempt to determine the kind of token that contains the word,
+ // and bail if it's a string literal. Note that we cannot always
+ // determine the token kind (e.g. comments, for which we do want
+ // to activate, are not retained by TokenBuffer).
+ for (syntax::Token T :
+ syntax::spelledTokensTouching(WordStart, AST.getTokens())) {
+ if (T.range(AST.getSourceManager()).touches(WordOffset + Word.size())) {
+ if (isStringLiteral(T.kind()))
+ return {};
+ }
+ }
+
// Do not consider tokens that survived preprocessing.
// We are erring on the safe side here, as a user may expect to get
// accurate (as opposed to textual-heuristic) results for such tokens.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76098.251481.patch
Type: text/x-patch
Size: 1783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200319/b9a6f1d6/attachment.bin>
More information about the cfe-commits
mailing list