From 2542ef83ed7c5a10f8b394ec8e7764558dc71d32 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Mon, 7 Dec 2020 12:54:38 +0100 Subject: [PATCH] [clangd] Fix windows slashes in project config diagnostics --- clang-tools-extra/clangd/ConfigProvider.cpp | 4 +++- clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) 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 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();