Skip to content

Conversation

@95833
Copy link

@95833 95833 commented Dec 7, 2024

path::is_absolute(Path, path::Style::windows) will return false leading to an error when the path appears in the root driver form, for example: path-mappings=E:=/mnt/e

This modification also potentially provides support for WSL paths. for example: path-mappings=\\wsl.localhost/usr=/usr

@github-actions
Copy link

github-actions bot commented Dec 7, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Dec 7, 2024

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: None (95833)

Changes

path::is_absolute(Path, path::Style::windows) will return false leading to an error when the path appears in the root driver form, for example: path-mappings=E:=/mnt/e

This modification also potentially provides support for WSL paths. for example: path-mappings=\\wsl.localhost/usr=/usr


Full diff: https://github.com/llvm/llvm-project/pull/119085.diff

1 Files Affected:

  • (modified) clang-tools-extra/clangd/PathMapping.cpp (+5-5)
diff --git a/clang-tools-extra/clangd/PathMapping.cpp b/clang-tools-extra/clangd/PathMapping.cpp
index 4b93ff2c60c5c6..48a936867a738a 100644
--- a/clang-tools-extra/clangd/PathMapping.cpp
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -150,11 +150,11 @@ llvm::Expected<std::string> parsePath(llvm::StringRef Path) {
   if (path::is_absolute(Path, path::Style::posix)) {
     return std::string(Path);
   }
-  if (path::is_absolute(Path, path::Style::windows)) {
-    std::string Converted = path::convert_to_slash(Path, path::Style::windows);
-    if (Converted.front() != '/')
-      Converted = "/" + Converted;
-    return Converted;
+  llvm::StringRef Root = path::root_name(Path, path::Style::windows);
+  if (!Root.empty()) {
+    std::string Converted = "/";
+    return Converted.append(Root)
+          .append(path::convert_to_slash(Path.substr(Root.size()), path::Style::windows));
   }
   return error("Path not absolute: {0}", Path);
 }

@95833 95833 closed this Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants