[PATCH] D155215: [clangd] Fix the range for include reference to itself.
Viktoriia Bakalova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 13 09:26:51 PDT 2023
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155215
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
@@ -2299,7 +2299,7 @@
TEST(FindReferences, UsedSymbolsFromInclude) {
const char *Tests[] = {
- R"cpp([[#include ^"bar.h"]]
+ R"cpp( [[#include ^"bar.h"]]
#include <vector>
int fstBar = [[bar1]]();
int sndBar = [[bar2]]();
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1363,9 +1363,11 @@
// Add the #include line to the references list.
auto IncludeLen = std::string{"#include"}.length() + Inc.Written.length() + 1;
+ auto Start =
+ offsetToPosition(SM.getBufferData(SM.getMainFileID()), Inc.HashOffset);
ReferencesResult::Reference Result;
- Result.Loc.range = clangd::Range{Position{Inc.HashLine, 0},
- Position{Inc.HashLine, (int)IncludeLen}};
+ Result.Loc.range = clangd::Range{
+ Start, Position{Inc.HashLine, Start.character + (int)IncludeLen}};
Result.Loc.uri = URIMainFile;
Results.References.push_back(std::move(Result));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155215.540074.patch
Type: text/x-patch
Size: 1320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230713/a31b7aed/attachment.bin>
More information about the cfe-commits
mailing list