This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd99b2a976a37: [clangd][remote] Add Windows paths support
(authored by ArcsinX).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89529/new/
https://reviews.llvm.org/D89529
Files:
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -239,8 +239,8 @@
clangd::Symbol::IncludeHeaderWithReferences Header;
// Add only valid headers.
- Header.IncludeHeader = Strings.save(
- URI::createFile("/usr/local/user/home/project/Header.h").toString());
+ Header.IncludeHeader =
+ Strings.save(URI::createFile(testPath("project/Header.h")).toString());
Header.References = 21;
Sym.IncludeHeaders.push_back(Header);
Header.IncludeHeader = Strings.save("<iostream>");
@@ -250,7 +250,7 @@
Header.References = 200;
Sym.IncludeHeaders.push_back(Header);
- Marshaller ProtobufMarshaller(convert_to_slash("/"), convert_to_slash("/"));
+ Marshaller ProtobufMarshaller(testPath(""), testPath(""));
auto Serialized = ProtobufMarshaller.toProtobuf(Sym);
ASSERT_TRUE(bool(Serialized));
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===================================================================
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -50,20 +50,23 @@
Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
: Strings(Arena) {
+ llvm::StringRef PosixSeparator =
+ llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
if (!RemoteIndexRoot.empty()) {
assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
- assert(RemoteIndexRoot ==
- llvm::sys::path::convert_to_slash(RemoteIndexRoot));
- this->RemoteIndexRoot = RemoteIndexRoot.str();
- if (!RemoteIndexRoot.endswith(llvm::sys::path::get_separator()))
- *this->RemoteIndexRoot += llvm::sys::path::get_separator();
+ this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
+ RemoteIndexRoot, llvm::sys::path::Style::windows);
+ llvm::StringRef Path(*this->RemoteIndexRoot);
+ if (!Path.endswith(PosixSeparator))
+ *this->RemoteIndexRoot += PosixSeparator;
}
if (!LocalIndexRoot.empty()) {
assert(llvm::sys::path::is_absolute(LocalIndexRoot));
- assert(LocalIndexRoot == llvm::sys::path::convert_to_slash(LocalIndexRoot));
- this->LocalIndexRoot = LocalIndexRoot.str();
- if (!LocalIndexRoot.endswith(llvm::sys::path::get_separator()))
- *this->LocalIndexRoot += llvm::sys::path::get_separator();
+ this->LocalIndexRoot = llvm::sys::path::convert_to_slash(
+ LocalIndexRoot, llvm::sys::path::Style::windows);
+ llvm::StringRef Path(*this->LocalIndexRoot);
+ if (!Path.endswith(PosixSeparator))
+ *this->LocalIndexRoot += PosixSeparator;
}
assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
}
@@ -92,6 +95,9 @@
for (const auto &Path : Message->proximity_paths()) {
llvm::SmallString<256> LocalPath = llvm::StringRef(*RemoteIndexRoot);
llvm::sys::path::append(LocalPath, Path);
+ // FuzzyFindRequest requires proximity paths to have platform-native format
+ // in order for SymbolIndex to process the query correctly.
+ llvm::sys::path::native(LocalPath);
Result.ProximityPaths.push_back(std::string(LocalPath));
}
for (const auto &Type : Message->preferred_types())
@@ -209,7 +215,7 @@
llvm::SmallString<256> RelativePath = llvm::StringRef(Path);
if (llvm::sys::path::replace_path_prefix(RelativePath, *LocalIndexRoot, ""))
RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
- RelativePath, llvm::sys::path::Style::posix));
+ RelativePath, llvm::sys::path::Style::windows));
}
for (const auto &Type : From.PreferredTypes)
RPCRequest.add_preferred_types(Type);
@@ -315,12 +321,17 @@
if (ParsedURI->scheme() != "file")
return error("Can not use URI schemes other than file, given: '{0}'.", URI);
llvm::SmallString<256> Result = ParsedURI->body();
+ llvm::StringRef Path(Result);
+ // Check for Windows paths (URI=file:///X:/path => Body=/X:/path)
+ if (llvm::sys::path::is_absolute(Path.substr(1),
+ llvm::sys::path::Style::windows))
+ Result = Path.drop_front();
if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
return error("File path '{0}' doesn't start with '{1}'.", Result.str(),
*RemoteIndexRoot);
- // Make sure the result has UNIX slashes.
- return llvm::sys::path::convert_to_slash(Result,
- llvm::sys::path::Style::posix);
+ assert(Result == llvm::sys::path::convert_to_slash(
+ Result, llvm::sys::path::Style::windows));
+ return std::string(Result);
}
clangd::SymbolLocation::Position
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits