[clang-tools-extra] fix parse windows driver and wsl path (PR #119085)

via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 7 11:16:24 PST 2024


https://github.com/95833 updated https://github.com/llvm/llvm-project/pull/119085

>From 1a37796fbb624a54b00cfff42674fbfa79616f61 Mon Sep 17 00:00:00 2001
From: root <987004590 at qq.com>
Date: Sun, 8 Dec 2024 01:19:59 +0800
Subject: [PATCH] fix parse windows driver and wsl path

---
 clang-tools-extra/clangd/PathMapping.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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);
 }



More information about the cfe-commits mailing list