[clang-tools-extra] d1aec79 - [clangd] Remove calls to getFileLoc() in declToSym() (#83532)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 5 20:12:46 PST 2024
Author: Nathan Ridge
Date: 2024-03-05T23:12:43-05:00
New Revision: d1aec79a2ce077e49da7699c4ca2dee239d0a249
URL: https://github.com/llvm/llvm-project/commit/d1aec79a2ce077e49da7699c4ca2dee239d0a249
DIFF: https://github.com/llvm/llvm-project/commit/d1aec79a2ce077e49da7699c4ca2dee239d0a249.diff
LOG: [clangd] Remove calls to getFileLoc() in declToSym() (#83532)
toHalfOpenFileRange() already handles translating macro locations to
file locations, and it can provide a better result by knowing about both
ends of the range.
Fixes https://github.com/clangd/clangd/issues/1941
Added:
Modified:
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index 5b3e46a7b4dc16..5244a4e893769e 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -223,8 +223,8 @@ std::string getSymbolDetail(ASTContext &Ctx, const NamedDecl &ND) {
std::optional<DocumentSymbol> declToSym(ASTContext &Ctx, const NamedDecl &ND) {
auto &SM = Ctx.getSourceManager();
- SourceLocation BeginLoc = SM.getFileLoc(ND.getBeginLoc());
- SourceLocation EndLoc = SM.getFileLoc(ND.getEndLoc());
+ SourceLocation BeginLoc = ND.getBeginLoc();
+ SourceLocation EndLoc = ND.getEndLoc();
const auto SymbolRange =
toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
if (!SymbolRange)
diff --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index b1b8b4ccd184c2..4276a44275f535 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -750,6 +750,9 @@ TEST(DocumentSymbols, RangeFromMacro) {
$fullDef[[FF3() {
int var = 42;
}]]
+
+ #define FF4(name) int name = 0
+ $FooRange[[FF4($FooSelectionRange[[foo]])]];
)");
TU.Code = Main.code().str();
EXPECT_THAT(
@@ -766,7 +769,11 @@ TEST(DocumentSymbols, RangeFromMacro) {
AllOf(withName("FF3"), withDetail("()"),
symRange(Main.range("fullDef")),
children(AllOf(withName("waldo"), withDetail("void ()"),
- symRange(Main.range("fullDef")))))));
+ symRange(Main.range("fullDef"))))),
+ AllOf(
+ withName("FF4"), withDetail("(foo)"),
+ children(AllOf(withName("foo"), symRange(Main.range("FooRange")),
+ symNameRange(Main.range("FooSelectionRange")))))));
}
TEST(DocumentSymbols, FuncTemplates) {
More information about the cfe-commits
mailing list