Skip to content

Commit 5d38a34

Browse files
authored
[clangd] Consolidate two functions converting index to LSP locations (#117885)
1 parent 3a8ada6 commit 5d38a34

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,17 @@ void logIfOverflow(const SymbolLocation &Loc) {
121121

122122
// Convert a SymbolLocation to LSP's Location.
123123
// TUPath is used to resolve the path of URI.
124-
// FIXME: figure out a good home for it, and share the implementation with
125-
// FindSymbols.
126124
std::optional<Location> toLSPLocation(const SymbolLocation &Loc,
127125
llvm::StringRef TUPath) {
128126
if (!Loc)
129127
return std::nullopt;
130-
auto Uri = URI::parse(Loc.FileURI);
131-
if (!Uri) {
132-
elog("Could not parse URI {0}: {1}", Loc.FileURI, Uri.takeError());
128+
auto LSPLoc = indexToLSPLocation(Loc, TUPath);
129+
if (!LSPLoc) {
130+
elog("{0}", LSPLoc.takeError());
133131
return std::nullopt;
134132
}
135-
auto U = URIForFile::fromURI(*Uri, TUPath);
136-
if (!U) {
137-
elog("Could not resolve URI {0}: {1}", Loc.FileURI, U.takeError());
138-
return std::nullopt;
139-
}
140-
141-
Location LSPLoc;
142-
LSPLoc.uri = std::move(*U);
143-
LSPLoc.range.start.line = Loc.Start.line();
144-
LSPLoc.range.start.character = Loc.Start.column();
145-
LSPLoc.range.end.line = Loc.End.line();
146-
LSPLoc.range.end.character = Loc.End.column();
147133
logIfOverflow(Loc);
148-
return LSPLoc;
134+
return *LSPLoc;
149135
}
150136

151137
SymbolLocation toIndexLocation(const Location &Loc, std::string &URIStorage) {

0 commit comments

Comments
 (0)