Skip to content

Commit d1aec79

Browse files
[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 clangd/clangd#1941
1 parent 5549b01 commit d1aec79

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ std::string getSymbolDetail(ASTContext &Ctx, const NamedDecl &ND) {
223223
std::optional<DocumentSymbol> declToSym(ASTContext &Ctx, const NamedDecl &ND) {
224224
auto &SM = Ctx.getSourceManager();
225225

226-
SourceLocation BeginLoc = SM.getFileLoc(ND.getBeginLoc());
227-
SourceLocation EndLoc = SM.getFileLoc(ND.getEndLoc());
226+
SourceLocation BeginLoc = ND.getBeginLoc();
227+
SourceLocation EndLoc = ND.getEndLoc();
228228
const auto SymbolRange =
229229
toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
230230
if (!SymbolRange)

clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ TEST(DocumentSymbols, RangeFromMacro) {
750750
$fullDef[[FF3() {
751751
int var = 42;
752752
}]]
753+
754+
#define FF4(name) int name = 0
755+
$FooRange[[FF4($FooSelectionRange[[foo]])]];
753756
)");
754757
TU.Code = Main.code().str();
755758
EXPECT_THAT(
@@ -766,7 +769,11 @@ TEST(DocumentSymbols, RangeFromMacro) {
766769
AllOf(withName("FF3"), withDetail("()"),
767770
symRange(Main.range("fullDef")),
768771
children(AllOf(withName("waldo"), withDetail("void ()"),
769-
symRange(Main.range("fullDef")))))));
772+
symRange(Main.range("fullDef"))))),
773+
AllOf(
774+
withName("FF4"), withDetail("(foo)"),
775+
children(AllOf(withName("foo"), symRange(Main.range("FooRange")),
776+
symNameRange(Main.range("FooSelectionRange")))))));
770777
}
771778

772779
TEST(DocumentSymbols, FuncTemplates) {

0 commit comments

Comments
 (0)