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()))
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()))
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits