================
@@ -449,6 +449,39 @@ TEST(RemoteMarshallingTest, URIToRelativePathTranslation) {
   llvm::consumeError(RelativePath.takeError());
 }
 
+TEST(RemoteMarshallingTest, CrossPlatformPathsRoundTrip) {
+  llvm::BumpPtrAllocator Arena;
+  llvm::UniqueStringSaver Strings(Arena);
+
+  // Simulate a Windows-built index
+  Marshaller ProtobufMarshaller("C:/remote/project/",
----------------
ArcsinX wrote:

Oh. You are right, `URI::createFile()` doesn't work correctly for Windows paths 
under Unix. And this looks like a problem. I think `URI::createFile()` should 
be independent on current OS, like `url.pathToFileURL()` from `Node.js`. I 
checked that with the following patch, everything works as expected (Windows 
and Linux paths converted to URI correctly independent on current OS)
```diff
diff --git a/clang-tools-extra/clangd/URI.cpp b/clang-tools-extra/clangd/URI.cpp
index 11d70dc917f5..e916d8b3fe7c 100644
--- a/clang-tools-extra/clangd/URI.cpp
+++ b/clang-tools-extra/clangd/URI.cpp
@@ -59,7 +59,8 @@ public:
   uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
     std::string Body;
     llvm::StringRef Authority;
-    llvm::StringRef Root = llvm::sys::path::root_name(AbsolutePath);
+    llvm::StringRef Root = llvm::sys::path::root_name(
+        AbsolutePath, llvm::sys::path::Style::windows);
     if (isNetworkPath(Root)) {
       // Windows UNC paths e.g. \\server\share => file://server/share
       Authority = Root.drop_front(2);
@@ -68,7 +69,8 @@ public:
       // Windows paths e.g. X:\path => file:///X:/path
       Body = "/";
     }
-    Body += llvm::sys::path::convert_to_slash(AbsolutePath);
+    Body += llvm::sys::path::convert_to_slash(AbsolutePath,
+                                              llvm::sys::path::Style::windows);
     return URI("file", Authority, Body);
   }
 };
```

However, since this affects many other parts of the code, it might require 
further investigation before applying the patch I wrote above. 

So, let's just ignore my review comment about `URI::createFile()` usage.

https://github.com/llvm/llvm-project/pull/207202
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to