Skip to content

[clangd] [C++20] [Modules] Add modules suffix for 'Header' Source Switch #131591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang-tools-extra/clangd/HeaderSourceSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ std::optional<Path> getCorrespondingHeaderOrSource(
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
".c++", ".m", ".mm"};
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"};
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx",
".inc", ".cppm", ".ccm", ".cxxm",
".c++m", ".ixx"};

llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);

Expand Down
38 changes: 38 additions & 0 deletions clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,44 @@ TEST(HeaderSourceSwitchTest, FileHeuristic) {
EXPECT_FALSE(PathResult.has_value());
}

TEST(HeaderSourceSwitchTest, ModuleInterfaces) {
MockFS FS;

auto FooCC = testPath("foo.cc");
auto FooCPPM = testPath("foo.cppm");
FS.Files[FooCC];
FS.Files[FooCPPM];
std::optional<Path> PathResult =
getCorrespondingHeaderOrSource(FooCC, FS.view(std::nullopt));
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(*PathResult, FooCPPM);

auto Foo2CPP = testPath("foo2.cpp");
auto Foo2CCM = testPath("foo2.ccm");
FS.Files[Foo2CPP];
FS.Files[Foo2CCM];
PathResult = getCorrespondingHeaderOrSource(Foo2CPP, FS.view(std::nullopt));
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(*PathResult, Foo2CCM);

auto Foo3CXX = testPath("foo3.cxx");
auto Foo3CXXM = testPath("foo3.cxxm");
FS.Files[Foo3CXX];
FS.Files[Foo3CXXM];
PathResult = getCorrespondingHeaderOrSource(Foo3CXX, FS.view(std::nullopt));
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(*PathResult, Foo3CXXM);

auto Foo4CPLUSPLUS = testPath("foo4.c++");
auto Foo4CPLUSPLUSM = testPath("foo4.c++m");
FS.Files[Foo4CPLUSPLUS];
FS.Files[Foo4CPLUSPLUSM];
PathResult =
getCorrespondingHeaderOrSource(Foo4CPLUSPLUS, FS.view(std::nullopt));
EXPECT_TRUE(PathResult.has_value());
ASSERT_EQ(*PathResult, Foo4CPLUSPLUSM);
}

MATCHER_P(declNamed, Name, "") {
if (const NamedDecl *ND = dyn_cast<NamedDecl>(arg))
if (ND->getQualifiedNameAsString() == Name)
Expand Down