[PATCH] D84912: [clangd] findNearbyIdentifier(): fix the word search in the token stream.
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 30 02:47:39 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05b173466142: [clangd] findNearbyIdentifier(): fix the word search in the token stream. (authored by ArcsinX).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84912/new/
https://reviews.llvm.org/D84912
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
@@ -1197,7 +1197,14 @@
// h^i
)cpp",
- };
+ R"cpp(
+ // prefer nearest occurrence even if several matched tokens
+ // have the same value of `floor(log2(<token line> - <word line>))`.
+ int hello;
+ int x = hello, y = hello;
+ int z = [[hello]];
+ // h^ello
+ )cpp"};
for (const char *Test : Tests) {
Annotations T(Test);
auto AST = TestTU::withCode(T.code()).build();
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -518,7 +518,7 @@
// Find where the word occurred in the token stream, to search forward & back.
auto *I = llvm::partition_point(SpelledTokens, [&](const syntax::Token &T) {
assert(SM.getFileID(T.location()) == SM.getFileID(Word.Location));
- return T.location() >= Word.Location; // Comparison OK: same file.
+ return T.location() < Word.Location; // Comparison OK: same file.
});
// Search for matches after the cursor.
for (const syntax::Token &Tok : llvm::makeArrayRef(I, SpelledTokens.end()))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84912.281855.patch
Type: text/x-patch
Size: 1382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200730/1311b40b/attachment.bin>
More information about the cfe-commits
mailing list