[clang] [Sema] [Modules] Remove unrelated module partitions from suggestion list (PR #187657)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 22 16:09:13 PDT 2026


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 <110693261+mikomikotaishi at users.noreply.github.com>
Date: Fri, 20 Mar 2026 03:56:15 -0400
Subject: [PATCH] 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(



More information about the cfe-commits mailing list