https://github.com/mikomikotaishi updated https://github.com/llvm/llvm-project/pull/187657
>From 1315b9e47b954cc5fc150315a6403f989f7182f5 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <[email protected]> Date: Fri, 20 Mar 2026 03:56:15 -0400 Subject: [PATCH 1/3] Remove unrelated module partitions from suggestion list --- clang/lib/Sema/SemaCodeComplete.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 0cd9819dc2964..a04e942d2ee28 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -4696,7 +4696,16 @@ void SemaCodeCompletion::CodeCompleteModuleImport(SourceLocation ImportLoc, // Enumerate all top-level modules. SmallVector<Module *, 8> Modules; SemaRef.PP.getHeaderSearchInfo().collectAllModules(Modules); + Module *CurrentModule = SemaRef.getCurrentModule(); for (unsigned I = 0, N = Modules.size(); I != N; ++I) { + // Skip module partitions that don't belong to the current file's declared + // module. + if (Modules[I]->isModulePartition()) { + if (!CurrentModule || + Modules[I]->getPrimaryModuleInterfaceName() != + CurrentModule->getPrimaryModuleInterfaceName()) + continue; + } Builder.AddTypedTextChunk( Builder.getAllocator().CopyString(Modules[I]->Name)); Results.AddResult(Result( >From 07ac2116f74ca74e590e5632689a03494165cbc3 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <[email protected]> Date: Sun, 22 Mar 2026 19:19:28 -0400 Subject: [PATCH 2/3] Add a module test for code completion --- .../test/CodeCompletion/module-partitions.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 clang/test/CodeCompletion/module-partitions.cpp diff --git a/clang/test/CodeCompletion/module-partitions.cpp b/clang/test/CodeCompletion/module-partitions.cpp new file mode 100644 index 0000000000000..bdbadf6351c8f --- /dev/null +++ b/clang/test/CodeCompletion/module-partitions.cpp @@ -0,0 +1,26 @@ +// RUN: rm -rf %t && mkdir %t + +// Set up a partition of module M. +// RUN: echo 'export module M:Part; export int mpart_func();' > %t/m-part.cppm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/m-part.cppm -o %t/M-Part.pcm + +// Set up module N with a partition. +// RUN: echo 'export module N:OtherPart; export int npart_func();' > %t/n-otherpart.cppm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/n-otherpart.cppm -o %t/N-OtherPart.pcm +// RUN: printf 'export module N;\nexport import :OtherPart;\n' > %t/n.cppm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/n.cppm -fmodule-file=N:OtherPart=%t/N-OtherPart.pcm -o %t/N.pcm + +// Complete at the module name position in an "import" inside module M. +// Own partition (M:Part) should be suggested; another module's partition +// (N:OtherPart) should be filtered out. +// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:%(line+6):8 %s \ +// RUN: -fmodule-file=M:Part=%t/M-Part.pcm \ +// RUN: -fmodule-file=N=%t/N.pcm \ +// RUN: -fmodule-file=N:OtherPart=%t/N-OtherPart.pcm | FileCheck %s + +export module M; +import ; + +// CHECK-NOT: OtherPart +// CHECK: M:Part +// CHECK-NOT: OtherPart >From e5a196a71d203da78d3d17572c7742290ee26af1 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <[email protected]> Date: Sun, 22 Mar 2026 23:39:40 -0400 Subject: [PATCH 3/3] Fix unhandled code completion cases in preprocessing --- clang/lib/Lex/PPDirectives.cpp | 1 + clang/lib/Lex/Preprocessor.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 09f0c3fe8c61e..4f2db2b8accdb 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -4220,6 +4220,7 @@ void Preprocessor::HandleCXXImportDirective(Token ImportTok) { UseLoc = Tok.getLocation(); Lex(Tok); [[fallthrough]]; + case tok::code_completion: case tok::identifier: { if (HandleModuleName(ImportTok.getIdentifierInfo()->getName(), UseLoc, Tok, Path, DirToks, /*AllowMacroExpansion=*/true, diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 2cfefac1052a4..6358b34dee3ed 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -1354,7 +1354,7 @@ bool Preprocessor::HandleModuleContextualKeyword(Token &Result) { if (Result.getIdentifierInfo()->isImportKeyword()) { if (NextTok->isOneOf(tok::identifier, tok::less, tok::colon, - tok::header_name)) { + tok::header_name, tok::code_completion)) { Result.setKind(tok::kw_import); ModuleImportLoc = Result.getLocation(); IsAtImport = false; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
