diff --git a/src/graph/map.ts b/src/graph/map.ts index d5d2fc4f9..932831b52 100644 --- a/src/graph/map.ts +++ b/src/graph/map.ts @@ -20,6 +20,7 @@ */ import type { GraphV1, NodeV1 } from "./types.js"; import { languageLabelOf } from "./extract.js"; +import { genericLangOf } from "./generic.js"; import { WALK_RELATIONS } from "./relations.js"; import { scopeLabel, scopeOf, scopesOfGraph } from "./scopes.js"; import { withSavings, savingsFor, type Savings } from "../context/savings.js"; @@ -132,7 +133,7 @@ function topHubs(nodes: NodeV1[], inDegree: Map, cap: number): H function sortedLanguages(paths: string[]): string[] { const set = new Set(); for (const p of paths) { - const label = languageLabelOf(p); + const label = languageLabelOf(p) ?? genericLangOf(p)?.name ?? null; if (label) set.add(label); } return [...set].sort(); diff --git a/test/graph-map.test.ts b/test/graph-map.test.ts index be45d4c7c..494da4000 100644 --- a/test/graph-map.test.ts +++ b/test/graph-map.test.ts @@ -87,6 +87,21 @@ test("buildRepoMap: totals count files, symbols, edges, and languages across the assert.deepEqual(map.totals.languages, ["python", "typescript"]); }); +// Issue #762: generic-tree-sitter-tier languages (rust, c, …) are indexed but +// `sortedLanguages` consulted only the depth-tier EXTENSIONS table, so a Rust +// repo with a few website .js files was labeled "javascript". +test("buildRepoMap: generic-tier languages (rust) label the map too, not just depth-tier ones", () => { + const nodes = [ + fileNode("src/lib.rs"), + symNode("src/lib.rs", "fnRust"), + fileNode("static/app.js"), + symNode("static/app.js", "fnJs"), + ]; + const map = buildRepoMap(graphOf(nodes, [])); + assert.deepEqual(map.totals.languages, ["javascript", "rust"]); + assert.match(formatRepoMap(map), /\brust\b/); +}); + test("buildRepoMap: dirs are grouped by first path segment and sorted by symbol count desc", () => { const nodes = [ fileNode("alpha/a.ts"),