diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp --- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp +++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp @@ -50,20 +50,23 @@ Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot, llvm::StringRef LocalIndexRoot) : Strings(Arena) { + auto 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,7 @@ for (const auto &Path : Message->proximity_paths()) { llvm::SmallString<256> LocalPath = llvm::StringRef(*RemoteIndexRoot); llvm::sys::path::append(LocalPath, Path); + llvm::sys::path::native(LocalPath); Result.ProximityPaths.push_back(std::string(LocalPath)); } for (const auto &Type : Message->preferred_types()) @@ -209,7 +213,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 +319,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 Result.str().str(); } clangd::SymbolLocation::Position diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp --- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp +++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp @@ -239,10 +239,6 @@ clangd::Symbol::IncludeHeaderWithReferences Header; // Add only valid headers. - Header.IncludeHeader = Strings.save( - URI::createFile("/usr/local/user/home/project/Header.h").toString()); - Header.References = 21; - Sym.IncludeHeaders.push_back(Header); Header.IncludeHeader = Strings.save(""); Header.References = 100; Sym.IncludeHeaders.push_back(Header); @@ -250,7 +246,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));