Skip to content

armgit / Ix

Public Imported from GitHub
0

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

fix: add language guard to tier-3 edge resolver to prevent cross-language false CALLS edges

Joseph Mikhail469cb586c6ff
diff --git a/core-ingestion/dist/index.js b/core-ingestion/dist/index.js
index 32c011f6..7e45558c 100644
--- a/core-ingestion/dist/index.js
+++ b/core-ingestion/dist/index.js
@@ -504,8 +504,36 @@ export function resolveEdges(results) {
}
}
for (const rel of result.relationships) {
- if (rel.predicate !== 'CALLS' && rel.predicate !== 'EXTENDS' && rel.predicate !== 'REFERENCES')
+ if (rel.predicate !== 'CALLS' && rel.predicate !== 'EXTENDS' && rel.predicate !== 'REFERENCES' && rel.predicate !== 'IMPORTS')
continue;
+ // Resolve Scala/Java dotted class imports (e.g. "ix.memory.model.ClaimId")
+ // to the actual indexed entity node in the defining file.
+ // Uses package-path lookup: extract package ("ix.memory.model") and entity
+ // name ("ClaimId"), find files registered under that package, then find
+ // the one that defines the entity.
+ if (rel.predicate === 'IMPORTS') {
+ if (result.language !== SupportedLanguages.Scala && result.language !== SupportedLanguages.Java)
+ continue;
+ const dstName = rel.dstName;
+ const lastDot = dstName.lastIndexOf('.');
+ if (lastDot === -1)
+ continue; // not a dotted class import
+ const entityName = dstName.slice(lastDot + 1);
+ if (!entityName || entityName === '_')
+ continue; // wildcard import
+ const pkgPath = dstName.slice(0, lastDot); // e.g. "ix.memory.model"
+ // Find files in the declared package that define this entity
+ const pkgFiles = packageToFiles.get(pkgPath) ?? [];
+ const matchFiles = pkgFiles.filter(fp => fp !== srcFilePath && fileHasSymbol.get(fp)?.has(entityName));
+ if (matchFiles.length !== 1)
+ continue; // ambiguous or not found
+ const fp = matchFiles[0];
+ const dstQualifiedKey = bestQKey(fileQKeys, fp, entityName);
+ if (dstQualifiedKey === null)
+ continue;
+ resolved.push({ srcFilePath, srcName: rel.srcName, dstFilePath: fp, dstName, dstQualifiedKey, predicate: 'IMPORTS', confidence: 0.9 });
+ continue;
+ }
const dstName = rel.dstName;
const srcName = rel.srcName;
// Tier 1b: qualifier-assisted (confidence 0.9 / 0.7)
@@ -588,9 +616,11 @@ export function resolveEdges(results) {
if (transitiveMatches.length > 1)
continue; // ambiguous — do not emit
// Tier 3: global fallback (confidence 0.5) — exactly one other file defines it
+ // Only match files in the same language as the caller to avoid cross-language false positives.
+ const srcLanguage = result.language;
const globalMatches = [];
for (const [fp, symbols] of fileHasSymbol) {
- if (fp !== srcFilePath && symbols.has(dstName))
+ if (fp !== srcFilePath && symbols.has(dstName) && languageFromPath(fp) === srcLanguage)
globalMatches.push(fp);
}
if (globalMatches.length === 1) {
diff --git a/core-ingestion/dist/patch-builder.js b/core-ingestion/dist/patch-builder.js
index 7c3efb59..d8769324 100644
--- a/core-ingestion/dist/patch-builder.js
+++ b/core-ingestion/dist/patch-builder.js
@@ -31,10 +31,10 @@ function sourceType(filePath) {
return 'code';
}
function extractorName() {
- return `tree-sitter/1.7`;
+ return `tree-sitter/1.11`;
}
/** Previous extractor versions — their patches are superseded when re-ingesting. */
-const PREVIOUS_EXTRACTORS = ['tree-sitter/1.6', 'tree-sitter/1.5', 'tree-sitter/1.4', 'tree-sitter/1.3', 'tree-sitter/1.2', 'tree-sitter/1.1'];
+const PREVIOUS_EXTRACTORS = ['tree-sitter/1.10', 'tree-sitter/1.9', 'tree-sitter/1.8', 'tree-sitter/1.7', 'tree-sitter/1.6', 'tree-sitter/1.5', 'tree-sitter/1.4', 'tree-sitter/1.3', 'tree-sitter/1.2', 'tree-sitter/1.1'];
/** Compute a patchId for a (filePath, sourceHash, extractorVersion) triple. */
function computePatchId(filePath, sourceHash, extractor) {
return deterministicId(`${filePath}:${sourceHash}:${extractor}`);
diff --git a/core-ingestion/src/index.ts b/core-ingestion/src/index.ts
index ba79c442..11299867 100644
--- a/core-ingestion/src/index.ts
+++ b/core-ingestion/src/index.ts
@@ -593,7 +593,32 @@ export function resolveEdges(results: FileParseResult[]): ResolvedEdge[] {
}
for (const rel of result.relationships) {
- if (rel.predicate !== 'CALLS' && rel.predicate !== 'EXTENDS' && rel.predicate !== 'REFERENCES') continue;
+ if (rel.predicate !== 'CALLS' && rel.predicate !== 'EXTENDS' && rel.predicate !== 'REFERENCES' && rel.predicate !== 'IMPORTS') continue;
+
+ // Resolve Scala/Java dotted class imports (e.g. "ix.memory.model.ClaimId")
+ // to the actual indexed entity node in the defining file.
+ // Uses package-path lookup: extract package ("ix.memory.model") and entity
+ // name ("ClaimId"), find files registered under that package, then find
+ // the one that defines the entity.
+ if (rel.predicate === 'IMPORTS') {
+ if (result.language !== SupportedLanguages.Scala && result.language !== SupportedLanguages.Java) continue;
+ const dstName = rel.dstName;
+ const lastDot = dstName.lastIndexOf('.');
+ if (lastDot === -1) continue; // not a dotted class import
+ const entityName = dstName.slice(lastDot + 1);
+ if (!entityName || entityName === '_') continue; // wildcard import
+ const pkgPath = dstName.slice(0, lastDot); // e.g. "ix.memory.model"
+ // Find files in the declared package that define this entity
+ const pkgFiles = packageToFiles.get(pkgPath) ?? [];
+ const matchFiles = pkgFiles.filter(fp => fp !== srcFilePath && fileHasSymbol.get(fp)?.has(entityName));
+ if (matchFiles.length !== 1) continue; // ambiguous or not found
+ const fp = matchFiles[0];
+ const dstQualifiedKey = bestQKey(fileQKeys, fp, entityName);
+ if (dstQualifiedKey === null) continue;
+ resolved.push({ srcFilePath, srcName: rel.srcName, dstFilePath: fp, dstName, dstQualifiedKey, predicate: 'IMPORTS', confidence: 0.9 });
+ continue;
+ }
+
const dstName = rel.dstName;
const srcName = rel.srcName;
@@ -674,9 +699,11 @@ export function resolveEdges(results: FileParseResult[]): ResolvedEdge[] {
if (transitiveMatches.length > 1) continue; // ambiguous — do not emit
// Tier 3: global fallback (confidence 0.5) — exactly one other file defines it
+ // Only match files in the same language as the caller to avoid cross-language false positives.
+ const srcLanguage = result.language;
const globalMatches: string[] = [];
for (const [fp, symbols] of fileHasSymbol) {
- if (fp !== srcFilePath && symbols.has(dstName)) globalMatches.push(fp);
+ if (fp !== srcFilePath && symbols.has(dstName) && languageFromPath(fp) === srcLanguage) globalMatches.push(fp);
}
if (globalMatches.length === 1) {
diff --git a/core-ingestion/src/patch-builder.ts b/core-ingestion/src/patch-builder.ts
index 3722f20b..d453ba34 100644
--- a/core-ingestion/src/patch-builder.ts
+++ b/core-ingestion/src/patch-builder.ts
@@ -38,11 +38,11 @@ function sourceType(filePath: string): string {
}
function extractorName(): string {
- return `tree-sitter/1.7`;
+ return `tree-sitter/1.11`;
}
/** Previous extractor versions — their patches are superseded when re-ingesting. */
-const PREVIOUS_EXTRACTORS = ['tree-sitter/1.6', 'tree-sitter/1.5', 'tree-sitter/1.4', 'tree-sitter/1.3', 'tree-sitter/1.2', 'tree-sitter/1.1'];
+const PREVIOUS_EXTRACTORS = ['tree-sitter/1.10', 'tree-sitter/1.9', 'tree-sitter/1.8', 'tree-sitter/1.7', 'tree-sitter/1.6', 'tree-sitter/1.5', 'tree-sitter/1.4', 'tree-sitter/1.3', 'tree-sitter/1.2', 'tree-sitter/1.1'];
/** Compute a patchId for a (filePath, sourceHash, extractorVersion) triple. */
function computePatchId(filePath: string, sourceHash: string, extractor: string): string {