From 26a160770c22423ea1ea9bfea1cd45d85cab01e8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 14 May 2026 20:32:45 +0000 Subject: [PATCH] refactor(cpp): simplify ADL associated-namespace collection Agent-Logs-Url: https://github.com/abhigyanpatwari/GitNexus/sessions/beaa1e9b-2ba6-4cbe-86f5-6fbfe9aa45bf --- .../src/core/ingestion/languages/cpp/adl.ts | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/gitnexus/src/core/ingestion/languages/cpp/adl.ts b/gitnexus/src/core/ingestion/languages/cpp/adl.ts index a69801856..463cbea1b 100644 --- a/gitnexus/src/core/ingestion/languages/cpp/adl.ts +++ b/gitnexus/src/core/ingestion/languages/cpp/adl.ts @@ -186,32 +186,7 @@ export function pickCppAdlCandidates( // Collect associated namespace QNames from every participating class-typed arg. const associatedNamespaces = new Set(); for (const arg of args) { - if (arg.simpleClassName !== '') { - // For template args this may be the template name itself (e.g. - // `vector`); simple-name lookup can match project classes with the - // same name (known V1/V2 simplification). - const classDef = findCppClassDefBySimpleName(arg.simpleClassName, scopes); - if (classDef !== undefined) { - const nsQName = classToNamespaceQualifiedName.get(classDef.nodeId); - if (nsQName !== undefined) associatedNamespaces.add(nsQName); - } - } - - // Includes template-owner namespaces (e.g. `std` in std::vector). - // If that surfaces extra candidates, ADL_AMBIGUOUS suppression below - // prevents arbitrary edge emission. - if (arg.templateNamespace.length > 0) associatedNamespaces.add(arg.templateNamespace); - - for (const ns of arg.templateArgNamespaces) { - if (ns.length > 0) associatedNamespaces.add(ns); - } - for (const className of arg.templateArgClassNames) { - if (className.length === 0) continue; - const classDef = findCppClassDefBySimpleName(className, scopes); - if (classDef === undefined) continue; - const nsQName = classToNamespaceQualifiedName.get(classDef.nodeId); - if (nsQName !== undefined) associatedNamespaces.add(nsQName); - } + collectAssociatedNamespacesForAdlArg(arg, scopes, associatedNamespaces); } if (associatedNamespaces.size === 0) return undefined; @@ -260,6 +235,41 @@ export function pickCppAdlCandidates( return ADL_AMBIGUOUS; } +function collectAssociatedNamespacesForAdlArg( + arg: CppAdlArgInfo, + scopes: ScopeResolutionIndexes, + associatedNamespaces: Set, +): void { + // For template args this may be the template name itself (e.g. `vector`); + // simple-name lookup can match project classes with the same name (known + // V1/V2 simplification). + addAssociatedNamespaceForClassName(arg.simpleClassName, scopes, associatedNamespaces); + + // Includes template-owner namespaces (e.g. `std` in std::vector). If + // that surfaces extra candidates, ADL_AMBIGUOUS suppression below prevents + // arbitrary edge emission. + if (arg.templateNamespace.length > 0) associatedNamespaces.add(arg.templateNamespace); + + for (const ns of arg.templateArgNamespaces) { + if (ns.length > 0) associatedNamespaces.add(ns); + } + for (const className of arg.templateArgClassNames) { + addAssociatedNamespaceForClassName(className, scopes, associatedNamespaces); + } +} + +function addAssociatedNamespaceForClassName( + simpleClassName: string, + scopes: ScopeResolutionIndexes, + associatedNamespaces: Set, +): void { + if (simpleClassName.length === 0) return; + const classDef = findCppClassDefBySimpleName(simpleClassName, scopes); + if (classDef === undefined) return; + const nsQName = classToNamespaceQualifiedName.get(classDef.nodeId); + if (nsQName !== undefined) associatedNamespaces.add(nsQName); +} + /** Walk upward from a Class scope, finding the innermost enclosing * Namespace scope, and return that namespace's qualified name (dot- * joined, outermost-first). Returns '' when the class has no enclosing