diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp --- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp +++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp @@ -11,6 +11,7 @@ #include "SourceCode.h" #include "index/SymbolCollector.h" #include "support/Logger.h" +#include "support/Path.h" #include "clang/AST/Decl.h" namespace clang { @@ -82,7 +83,7 @@ llvm::StringMap Candidates; // Target path => score. auto AwardTarget = [&](const char *TargetURI) { if (auto TargetPath = URI::resolve(TargetURI, OriginalFile)) { - if (*TargetPath != OriginalFile) // exclude the original file. + if (!pathEqual(*TargetPath, OriginalFile)) // exclude the original file. ++Candidates[*TargetPath]; } else { elog("Failed to resolve URI {0}: {1}", TargetURI, TargetPath.takeError()); diff --git a/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp b/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp --- a/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp +++ b/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp @@ -12,7 +12,9 @@ #include "TestFS.h" #include "TestTU.h" #include "index/MemIndex.h" +#include "support/Path.h" #include "llvm/ADT/None.h" +#include "llvm/ADT/StringExtras.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -271,6 +273,29 @@ *llvm::cantFail(runSwitchHeaderSource(Server, CppPath))); } +#ifdef _WIN32 +// Outside of windows systems, we usually have case sensitive file systems. +TEST(HeaderSourceSwitchTest, CaseSensitivity) { + TestTU TU = TestTU::withCode("void foo() {}"); + TU.HeaderCode = R"cpp( + inline void bar1() {} + inline void bar2() {})cpp"; + // Give main file and header different base names to make sure file system + // heuristics don't work. + TU.Filename = "Source.cpp"; + TU.HeaderFilename = "Header.h"; + + auto Index = TU.index(); + auto AST = TU.build(); + + auto HeaderAbsPath = testPath(TU.Filename); + HeaderAbsPath[0] = llvm::toLower(HeaderAbsPath[0]); + EXPECT_EQ(testPath(TU.Filename), + getCorrespondingHeaderOrSource(testPath(TU.HeaderFilename), AST, + Index.get())); +} +#endif + } // namespace } // namespace clangd } // namespace clang