https://github.com/mikomikotaishi updated https://github.com/llvm/llvm-project/pull/187657
>From 54d1315ff5e2c8c2517feb662c355c657c642ce8 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/2] 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 c185db80b87654622ec640874c2a7cdd4a259031 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/2] 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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
