[clangd] Fix windows slashes in project config diagnostics

This commit is contained in:
Sam McCall 2020-12-07 12:54:38 +01:00
parent f1357264b8
commit 2542ef83ed
2 changed files with 3 additions and 3 deletions

View File

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

View File

@ -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();