[clang-tools-extra] [clangd] Consolidate two functions converting index to LSP locations (PR #117885)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 27 06:13:48 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Christian Kandeler (ckandeler)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/117885.diff
1 Files Affected:
- (modified) clang-tools-extra/clangd/XRefs.cpp (+4-18)
``````````diff
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 61fa66180376cd..f1e701f1ad0210 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -121,31 +121,17 @@ void logIfOverflow(const SymbolLocation &Loc) {
// Convert a SymbolLocation to LSP's Location.
// TUPath is used to resolve the path of URI.
-// FIXME: figure out a good home for it, and share the implementation with
-// FindSymbols.
std::optional<Location> toLSPLocation(const SymbolLocation &Loc,
llvm::StringRef TUPath) {
if (!Loc)
return std::nullopt;
- auto Uri = URI::parse(Loc.FileURI);
- if (!Uri) {
- elog("Could not parse URI {0}: {1}", Loc.FileURI, Uri.takeError());
+ auto LSPLoc = indexToLSPLocation(Loc, TUPath);
+ if (!LSPLoc) {
+ elog("{0}", LSPLoc.takeError());
return std::nullopt;
}
- auto U = URIForFile::fromURI(*Uri, TUPath);
- if (!U) {
- elog("Could not resolve URI {0}: {1}", Loc.FileURI, U.takeError());
- return std::nullopt;
- }
-
- Location LSPLoc;
- LSPLoc.uri = std::move(*U);
- LSPLoc.range.start.line = Loc.Start.line();
- LSPLoc.range.start.character = Loc.Start.column();
- LSPLoc.range.end.line = Loc.End.line();
- LSPLoc.range.end.character = Loc.End.column();
logIfOverflow(Loc);
- return LSPLoc;
+ return *LSPLoc;
}
SymbolLocation toIndexLocation(const Location &Loc, std::string &URIStorage) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/117885
More information about the cfe-commits
mailing list