diff --git a/src/services/code-graph.ts b/src/services/code-graph.ts index d2de430..fb5a22f 100644 --- a/src/services/code-graph.ts +++ b/src/services/code-graph.ts @@ -13,7 +13,7 @@ import type { } from "../types.js"; import { loadPathAliases } from "./graph-aliases.js"; import { extractImports } from "./graph-imports.js"; -import { buildJvmSuffixMap, resolveImport } from "./graph-resolution.js"; +import { buildCsNamespaceMap, buildJvmSuffixMap, resolveImport } from "./graph-resolution.js"; import { computeUnresolvedPct, resolveCallSites } from "./graph-symbol-resolution.js"; import { extractSymbolsAndCalls, rawCallsToUnresolvedEdges } from "./graph-symbols.js"; import { createIgnoreFilter, shouldIgnore } from "./ignore.js"; @@ -605,13 +605,20 @@ export async function buildCodeGraph( // Build a suffix lookup map for JVM multi-module projects (Java/Kotlin/Scala). // This resolves FQNs like com.example.Foo when the class lives under a nested // src/main/java/ tree (e.g. module-a/sub/src/main/java/com/example/Foo.java). - // Cost: O(n) once here, O(1) per import lookup — negligible vs. full AST parse. + // Cost: O(n) once here, O(1) per import lookup (negligible vs. full AST parse). const hasJvm = files.some((f) => { const e = path.extname(f).toLowerCase(); return e === ".java" || e === ".kt" || e === ".kts" || e === ".scala"; }); const jvmSuffixMap = hasJvm ? buildJvmSuffixMap(fileSet) : undefined; + // Build a namespace lookup map for C# projects. Each `namespace X.Y.Z` block + // (or file-scoped `namespace X.Y.Z;`) is recorded so `using X.Y.Z;` directives + // can be resolved to the file(s) that contribute to that namespace. Without + // this, every C# import resolved to null and the file graph was empty. + const hasCs = files.some((f) => path.extname(f).toLowerCase() === ".cs"); + const csNamespaceMap = hasCs ? buildCsNamespaceMap(fileSet, resolvedPath) : undefined; + for (const relPath of files) { const ext = path.extname(relPath).toLowerCase(); const lang = getAstGrepLang(ext); @@ -682,7 +689,7 @@ export async function buildCodeGraph( // Try to resolve to a project file // CSS imports from