[clang-tools-extra] [clangd] Remove calls to getFileLoc() in declToSym() (PR #83532)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 29 22:38:45 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Nathan Ridge (HighCommander4)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/83532.diff
2 Files Affected:
- (modified) clang-tools-extra/clangd/FindSymbols.cpp (+2-2)
- (modified) clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp (+8-1)
``````````diff
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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/83532
More information about the cfe-commits
mailing list