[llvm-branch-commits] [clang-tools-extra] 2542ef8 - [clangd] Fix windows slashes in project config diagnostics

Sam McCall via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 7 03:55:34 PST 2020


Author: Sam McCall
Date: 2020-12-07T12:54:38+01:00
New Revision: 2542ef83ed7c5a10f8b394ec8e7764558dc71d32

URL: https://github.com/llvm/llvm-project/commit/2542ef83ed7c5a10f8b394ec8e7764558dc71d32
DIFF: https://github.com/llvm/llvm-project/commit/2542ef83ed7c5a10f8b394ec8e7764558dc71d32.diff

LOG: [clangd] Fix windows slashes in project config diagnostics

Added: 
    

Modified: 
    clang-tools-extra/clangd/ConfigProvider.cpp
    clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/ConfigProvider.cpp b/clang-tools-extra/clangd/ConfigProvider.cpp
index 8a3991ed1c1e..0933e7e2c283 100644
--- a/clang-tools-extra/clangd/ConfigProvider.cpp
+++ b/clang-tools-extra/clangd/ConfigProvider.cpp
@@ -83,7 +83,7 @@ Provider::fromAncestorRelativeYAMLFiles(llvm::StringRef RelPath,
     const ThreadsafeFS &FS;
 
     mutable std::mutex Mu;
-    // Keys are the ancestor directory, not the actual config path within it.
+    // Keys are the (posix-style) ancestor directory, not the config within it.
     // We only insert into this map, so pointers to values are stable forever.
     // Mutex guards the map itself, not the values (which are threadsafe).
     mutable llvm::StringMap<FileConfigCache> Cache;
@@ -117,6 +117,8 @@ Provider::fromAncestorRelativeYAMLFiles(llvm::StringRef RelPath,
           if (It == Cache.end()) {
             llvm::SmallString<256> ConfigPath = Ancestor;
             path::append(ConfigPath, RelPath);
+            // Use native slashes for reading the file, affects diagnostics.
+            llvm::sys::path::native(ConfigPath);
             It = Cache.try_emplace(Ancestor, ConfigPath.str(), Ancestor).first;
           }
           Caches.push_back(&It->second);

diff  --git a/clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp b/clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
index 4e44af6fad58..9c45266d1a83 100644
--- a/clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
@@ -144,11 +144,9 @@ TEST(ProviderTest, FromAncestorRelativeYAMLFiles) {
   Cfg = P->getConfig(ABCParams, Diags.callback());
   EXPECT_THAT(Diags.Diagnostics,
               ElementsAre(DiagMessage("Unknown CompileFlags key Unknown")));
-#ifdef LLVM_ON_UNIX
   // FIXME: fails on windows: paths have mixed slashes like C:\a/b\c.yaml
   EXPECT_THAT(Diags.Files,
               ElementsAre(testPath("a/foo.yaml"), testPath("a/b/c/foo.yaml")));
-#endif
   EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo", "bar", "baz"));
   Diags.clear();
 


        


More information about the llvm-branch-commits mailing list