diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/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)); diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/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 int fstBar = [[bar1]](); int sndBar = [[bar2]]();