Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

feat(ingest): parse .sbt build definitions (#594)

KageBinary60e45e28eaff
diff --git a/core-ingestion/src/__tests__/queries.scala.test.ts b/core-ingestion/src/__tests__/queries.scala.test.ts
index 58d3abaf..af6262e5 100644
--- a/core-ingestion/src/__tests__/queries.scala.test.ts
+++ b/core-ingestion/src/__tests__/queries.scala.test.ts
@@ -67,4 +67,52 @@ describe('Scala queries', () => {
predicate: 'CALLS',
});
});
+
+ it('extracts modules and plugin imports from an .sbt build definition', () => {
+ const result = parseFile(
+ '/repo/build.sbt',
+ `import sbtassembly.MergeStrategy
+
+ThisBuild / scalaVersion := "2.13.16"
+
+lazy val commonSettings = Seq(scalacOptions ++= Seq("-Wunused:all"))
+
+lazy val core = (project in file("core"))
+ .settings(commonSettings, name := "ix-memory-core")
+
+lazy val root = (project in file(".")).aggregate(core)
+`,
+ );
+
+ expect(result).not.toBeNull();
+ expect(result!.entities.map((entity) => entity.name)).toEqual(
+ expect.arrayContaining(['commonSettings', 'core', 'root']),
+ );
+ expect(
+ result!.relationships
+ .filter((relationship) => relationship.predicate === 'IMPORTS')
+ .map((relationship) => relationship.dstName),
+ ).toEqual(expect.arrayContaining(['sbtassembly.MergeStrategy']));
+ });
+
+ it('still ignores method-local val bindings', () => {
+ // The top-level val query must not reopen the noise the template_body
+ // restriction was written to prevent.
+ const result = parseFile(
+ '/repo/Local.scala',
+ `object Service {
+ def run(): Int = {
+ val localBinding = 41
+ localBinding + 1
+ }
+}
+`,
+ );
+
+ expect(result!.entities.map((entity) => entity.name)).not.toContain('localBinding');
+ expect(result!.entities.map((entity) => entity.name)).toEqual(
+ expect.arrayContaining(['Service', 'run']),
+ );
+ });
+
});
diff --git a/core-ingestion/src/languages.ts b/core-ingestion/src/languages.ts
index 8d411004..f9fd2e6b 100644
--- a/core-ingestion/src/languages.ts
+++ b/core-ingestion/src/languages.ts
@@ -64,6 +64,9 @@ const EXT_MAP: Record<string, SupportedLanguages> = {
'.swift':SupportedLanguages.Swift,
'.scala':SupportedLanguages.Scala,
'.sc': SupportedLanguages.Scala,
+ // sbt build definitions are Scala expressions; the Scala grammar parses them
+ // as-is, and they are where modules are wired to their dependencies.
+ '.sbt': SupportedLanguages.Scala,
'.yaml': SupportedLanguages.YAML,
'.yml': SupportedLanguages.YAML,
'.dockerfile': SupportedLanguages.Dockerfile,
diff --git a/core-ingestion/src/queries.ts b/core-ingestion/src/queries.ts
index 6166bf1f..8abdcf17 100644
--- a/core-ingestion/src/queries.ts
+++ b/core-ingestion/src/queries.ts
@@ -1381,6 +1381,18 @@ export const SCALA_QUERIES = `
(template_body
(var_definition (identifier) @name) @definition.const)
+; ── Top-level val/var definitions (compilation-unit level) ────────────────────
+; Scala 2 forbids these, so ordinary .scala files are unaffected. They matter
+; for .sbt build definitions, where every module is a top-level
+; \`lazy val core = (project in file("core"))\`, and for Scala 3 top-level
+; definitions. Still excludes method-local bindings, which are nested inside a
+; block rather than the compilation unit.
+(compilation_unit
+ (val_definition (identifier) @name) @definition.const)
+
+(compilation_unit
+ (var_definition (identifier) @name) @definition.const)
+
; ── Imports: capture full declaration for dotted-path reconstruction ─────────
; Handles: import ix.memory.model._ (wildcard)
; import ix.memory.model.{NodeKind, GraphNode} (selective)
diff --git a/ix-cli/src/cli/supported-extensions.ts b/ix-cli/src/cli/supported-extensions.ts
index 83ee7af9..457808f4 100644
--- a/ix-cli/src/cli/supported-extensions.ts
+++ b/ix-cli/src/cli/supported-extensions.ts
@@ -11,7 +11,7 @@ export const SUPPORTED_EXTENSIONS = new Set<string>([
".py", ".pyi", ".java", ".c", ".h", ".cpp", ".cc", ".cxx", ".hpp",
".cu", ".cuh",
".cs", ".go", ".rb", ".rs", ".php", ".kt", ".kts", ".swift",
- ".scala", ".sc",
+ ".scala", ".sc", ".sbt",
".yaml", ".yml",
".dockerfile",
".sql",