diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/c-cpp.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/c-cpp.ts deleted file mode 100644 index 304851d00..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/c-cpp.ts +++ /dev/null @@ -1,25 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/c-cpp.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * C heritage extraction config. - * - * C has no class inheritance — no heritage captures expected. - * Config exists for completeness in the provider wiring. - */ -export const cHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.C, -}; - -/** - * C++ heritage extraction config. - * - * C++ has standard extends heritage through tree-sitter captures - * (class A : public B). Multiple inheritance uses leftmost-base MRO - * at the resolution layer. No special extraction hooks needed. - */ -export const cppHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.CPlusPlus, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/csharp.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/csharp.ts deleted file mode 100644 index 4363c8307..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/csharp.ts +++ /dev/null @@ -1,15 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/csharp.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * C# heritage extraction config. - * - * C# has standard extends/implements heritage through tree-sitter - * captures. Interface detection uses I-prefix convention (handled - * by heritage resolution strategy, not here). - */ -export const csharpHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.CSharp, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/dart.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/dart.ts deleted file mode 100644 index 0b3907267..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/dart.ts +++ /dev/null @@ -1,14 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/dart.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * Dart heritage extraction config. - * - * Dart has standard extends/implements/with heritage through tree-sitter - * captures. No special extraction hooks needed. - */ -export const dartHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.Dart, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/jvm.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/jvm.ts deleted file mode 100644 index 006cd2cb3..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/jvm.ts +++ /dev/null @@ -1,24 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/jvm.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * Java heritage extraction config. - * - * Java has standard extends/implements heritage through tree-sitter - * captures. No special extraction hooks needed. - */ -export const javaHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.Java, -}; - -/** - * Kotlin heritage extraction config. - * - * Kotlin uses ':' for both extends and implements (delegation markers - * are tree-sitter captures). No special extraction hooks needed. - */ -export const kotlinHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.Kotlin, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/php.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/php.ts deleted file mode 100644 index 6843712de..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/php.ts +++ /dev/null @@ -1,14 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/php.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * PHP heritage extraction config. - * - * PHP has standard extends/implements heritage through tree-sitter - * captures. No special extraction hooks needed. - */ -export const phpHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.PHP, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/python.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/python.ts deleted file mode 100644 index cabcdd78f..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/python.ts +++ /dev/null @@ -1,15 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/python.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * Python heritage extraction config. - * - * Python has standard extends heritage through tree-sitter captures - * (class A(B, C)). Multiple inheritance is handled by C3 MRO at - * the resolution layer. No special extraction hooks needed. - */ -export const pythonHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.Python, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/rust.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/rust.ts deleted file mode 100644 index f4c6b9d26..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/rust.ts +++ /dev/null @@ -1,15 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/rust.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * Rust heritage extraction config. - * - * Rust uses impl Trait for Struct syntax. Heritage captures include - * heritage.trait for trait implementations. No special extraction - * hooks needed beyond the standard capture handling. - */ -export const rustHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.Rust, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/swift.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/swift.ts deleted file mode 100644 index 058954db4..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/swift.ts +++ /dev/null @@ -1,16 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/swift.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * Swift heritage extraction config. - * - * Swift uses ':' for protocol conformance and class inheritance. - * The heritageDefaultEdge ('IMPLEMENTS') and resolution strategy - * are handled at the provider/resolution layer. No special - * extraction hooks needed. - */ -export const swiftHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.Swift, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/configs/typescript-javascript.ts b/gitnexus/src/core/ingestion/heritage-extractors/configs/typescript-javascript.ts deleted file mode 100644 index e59754b36..000000000 --- a/gitnexus/src/core/ingestion/heritage-extractors/configs/typescript-javascript.ts +++ /dev/null @@ -1,24 +0,0 @@ -// gitnexus/src/core/ingestion/heritage-extractors/configs/typescript-javascript.ts - -import { SupportedLanguages } from 'gitnexus-shared'; -import type { HeritageExtractionConfig } from '../../heritage-types.js'; - -/** - * TypeScript heritage extraction config. - * - * TypeScript has standard extends/implements heritage through tree-sitter - * captures. No special extraction hooks needed. - */ -export const typescriptHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.TypeScript, -}; - -/** - * JavaScript heritage extraction config. - * - * JavaScript has extends heritage (class A extends B). No implements - * keyword in plain JS. No special extraction hooks needed. - */ -export const javascriptHeritageConfig: HeritageExtractionConfig = { - language: SupportedLanguages.JavaScript, -}; diff --git a/gitnexus/src/core/ingestion/heritage-extractors/generic.ts b/gitnexus/src/core/ingestion/heritage-extractors/generic.ts index 9f12b7665..39c3d34c8 100644 --- a/gitnexus/src/core/ingestion/heritage-extractors/generic.ts +++ b/gitnexus/src/core/ingestion/heritage-extractors/generic.ts @@ -7,11 +7,13 @@ * field-extractors/generic.ts, call-extractors/generic.ts, and * variable-extractors/generic.ts. * - * Define a HeritageExtractionConfig per language and generate extractors - * from configs. The factory creates a HeritageExtractor whose behaviour - * is entirely driven by HeritageExtractionConfig. + * Languages with custom extraction hooks (Go: shouldSkipExtends, Ruby: + * callBasedHeritage) pass a full HeritageExtractionConfig. Languages + * that use the default capture-based extraction can pass just the + * SupportedLanguages enum value — no per-language config file needed. */ +import type { SupportedLanguages } from 'gitnexus-shared'; import type { CaptureMap } from '../language-provider.js'; import type { HeritageExtractionConfig, @@ -22,13 +24,22 @@ import type { import type { SyntaxNode } from '../utils/ast-helpers.js'; /** - * Create a HeritageExtractor from a declarative config. + * Create a HeritageExtractor from a declarative config or a language enum. + * + * When a full HeritageExtractionConfig is provided, custom hooks + * (shouldSkipExtends, callBasedHeritage) drive the extraction. + * When only a SupportedLanguages value is provided, the factory produces + * a default extractor that handles the standard @heritage.* captures. */ -export function createHeritageExtractor(config: HeritageExtractionConfig): HeritageExtractor { - const callNameSet = config.callBasedHeritage?.callNames; +export function createHeritageExtractor( + config: HeritageExtractionConfig | SupportedLanguages, +): HeritageExtractor { + const actualConfig: HeritageExtractionConfig = + typeof config === 'string' ? { language: config } : config; + const callNameSet = actualConfig.callBasedHeritage?.callNames; return { - language: config.language, + language: actualConfig.language, extract(captureMap: CaptureMap, context: HeritageExtractorContext): HeritageInfo[] { const classNode = captureMap['heritage.class']; @@ -39,7 +50,7 @@ export function createHeritageExtractor(config: HeritageExtractionConfig): Herit const extendsNode = captureMap['heritage.extends']; if (extendsNode) { - if (!config.shouldSkipExtends?.(extendsNode)) { + if (!actualConfig.shouldSkipExtends?.(extendsNode)) { results.push({ className, parentName: extendsNode.text, kind: 'extends' }); } } @@ -65,7 +76,7 @@ export function createHeritageExtractor(config: HeritageExtractionConfig): Herit context: HeritageExtractorContext, ): HeritageInfo[] | null { if (!callNameSet.has(calledName)) return null; - return config.callBasedHeritage!.extract(calledName, callNode, context.filePath); + return actualConfig.callBasedHeritage!.extract(calledName, callNode, context.filePath); }, } : {}), diff --git a/gitnexus/src/core/ingestion/language-provider.ts b/gitnexus/src/core/ingestion/language-provider.ts index 5bcdc0543..6b14a8f6a 100644 --- a/gitnexus/src/core/ingestion/language-provider.ts +++ b/gitnexus/src/core/ingestion/language-provider.ts @@ -182,8 +182,9 @@ interface LanguageProviderConfig { readonly classExtractor?: ClassExtractor; /** Heritage extractor for extracting extends/implements/trait-impl relationships * from tree-sitter @heritage.* captures and call-based heritage (e.g., Ruby - * include/extend/prepend). Produced by createHeritageExtractor() with a - * per-language HeritageExtractionConfig. + * include/extend/prepend). Produced by createHeritageExtractor() — pass a + * SupportedLanguages value for default behaviour or a full + * HeritageExtractionConfig for languages with custom hooks (Go, Ruby). * All tree-sitter providers MUST supply this. */ readonly heritageExtractor?: HeritageExtractor; /** Extract a semantic description for a definition node (e.g., PHP Eloquent diff --git a/gitnexus/src/core/ingestion/languages/c-cpp.ts b/gitnexus/src/core/ingestion/languages/c-cpp.ts index e14f61cc2..37e6da732 100644 --- a/gitnexus/src/core/ingestion/languages/c-cpp.ts +++ b/gitnexus/src/core/ingestion/languages/c-cpp.ts @@ -44,7 +44,6 @@ import { cVariableConfig, cppVariableConfig } from '../variable-extractors/confi import { createCallExtractor } from '../call-extractors/generic.js'; import { cCallConfig, cppCallConfig } from '../call-extractors/configs/c-cpp.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { cHeritageConfig, cppHeritageConfig } from '../heritage-extractors/configs/c-cpp.js'; const C_BUILT_INS: ReadonlySet = new Set([ 'printf', @@ -331,7 +330,7 @@ export const cProvider = defineLanguage({ }), variableExtractor: createVariableExtractor(cVariableConfig), classExtractor: cClassExtractor, - heritageExtractor: createHeritageExtractor(cHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.C), labelOverride: cppLabelOverride, builtInNames: C_BUILT_INS, }); @@ -353,7 +352,7 @@ export const cppProvider = defineLanguage({ }), variableExtractor: createVariableExtractor(cppVariableConfig), classExtractor: cppClassExtractor, - heritageExtractor: createHeritageExtractor(cppHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.CPlusPlus), labelOverride: cppLabelOverride, builtInNames: C_BUILT_INS, }); diff --git a/gitnexus/src/core/ingestion/languages/csharp.ts b/gitnexus/src/core/ingestion/languages/csharp.ts index 51fc96e67..a491f339a 100644 --- a/gitnexus/src/core/ingestion/languages/csharp.ts +++ b/gitnexus/src/core/ingestion/languages/csharp.ts @@ -25,7 +25,6 @@ import { csharpMethodConfig } from '../method-extractors/configs/csharp.js'; import { createVariableExtractor } from '../variable-extractors/generic.js'; import { csharpVariableConfig } from '../variable-extractors/configs/csharp.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { csharpHeritageConfig } from '../heritage-extractors/configs/csharp.js'; const BUILT_INS: ReadonlySet = new Set([ 'Console', @@ -137,6 +136,6 @@ export const csharpProvider = defineLanguage({ methodExtractor: createMethodExtractor(csharpMethodConfig), variableExtractor: createVariableExtractor(csharpVariableConfig), classExtractor: createClassExtractor(csharpClassConfig), - heritageExtractor: createHeritageExtractor(csharpHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.CSharp), builtInNames: BUILT_INS, }); diff --git a/gitnexus/src/core/ingestion/languages/dart.ts b/gitnexus/src/core/ingestion/languages/dart.ts index 311175834..130d15deb 100644 --- a/gitnexus/src/core/ingestion/languages/dart.ts +++ b/gitnexus/src/core/ingestion/languages/dart.ts @@ -31,7 +31,6 @@ import { dartVariableConfig } from '../variable-extractors/configs/dart.js'; import { createCallExtractor } from '../call-extractors/generic.js'; import { dartCallConfig } from '../call-extractors/configs/dart.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { dartHeritageConfig } from '../heritage-extractors/configs/dart.js'; /** * Resolve the enclosing function from a `function_body` node by looking at its @@ -104,7 +103,7 @@ export const dartProvider = defineLanguage({ methodExtractor: createMethodExtractor(dartMethodConfig), variableExtractor: createVariableExtractor(dartVariableConfig), classExtractor: createClassExtractor(dartClassConfig), - heritageExtractor: createHeritageExtractor(dartHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.Dart), enclosingFunctionFinder: dartEnclosingFunctionFinder, builtInNames: BUILT_INS, }); diff --git a/gitnexus/src/core/ingestion/languages/java.ts b/gitnexus/src/core/ingestion/languages/java.ts index 1fbfbe240..4781219d3 100644 --- a/gitnexus/src/core/ingestion/languages/java.ts +++ b/gitnexus/src/core/ingestion/languages/java.ts @@ -26,7 +26,6 @@ import { javaMethodConfig } from '../method-extractors/configs/jvm.js'; import { createVariableExtractor } from '../variable-extractors/generic.js'; import { javaVariableConfig } from '../variable-extractors/configs/jvm.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { javaHeritageConfig } from '../heritage-extractors/configs/jvm.js'; export const javaProvider = defineLanguage({ id: SupportedLanguages.Java, @@ -43,5 +42,5 @@ export const javaProvider = defineLanguage({ methodExtractor: createMethodExtractor(javaMethodConfig), variableExtractor: createVariableExtractor(javaVariableConfig), classExtractor: createClassExtractor(javaClassConfig), - heritageExtractor: createHeritageExtractor(javaHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.Java), }); diff --git a/gitnexus/src/core/ingestion/languages/kotlin.ts b/gitnexus/src/core/ingestion/languages/kotlin.ts index ea50cc29a..dd65e5d42 100644 --- a/gitnexus/src/core/ingestion/languages/kotlin.ts +++ b/gitnexus/src/core/ingestion/languages/kotlin.ts @@ -28,7 +28,6 @@ import { kotlinMethodConfig } from '../method-extractors/configs/jvm.js'; import { createVariableExtractor } from '../variable-extractors/generic.js'; import { kotlinVariableConfig } from '../variable-extractors/configs/jvm.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { kotlinHeritageConfig } from '../heritage-extractors/configs/jvm.js'; /** Check if a Kotlin function_declaration capture is inside a class_body (i.e., a method). * Kotlin grammar uses function_declaration for both top-level functions and class methods. @@ -118,7 +117,7 @@ export const kotlinProvider = defineLanguage({ methodExtractor: createMethodExtractor(kotlinMethodConfig), variableExtractor: createVariableExtractor(kotlinVariableConfig), classExtractor: createClassExtractor(kotlinClassConfig), - heritageExtractor: createHeritageExtractor(kotlinHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.Kotlin), builtInNames: BUILT_INS, labelOverride: (functionNode, defaultLabel) => { if (defaultLabel !== 'Function') return defaultLabel; diff --git a/gitnexus/src/core/ingestion/languages/php.ts b/gitnexus/src/core/ingestion/languages/php.ts index 001f3fd49..736a63468 100644 --- a/gitnexus/src/core/ingestion/languages/php.ts +++ b/gitnexus/src/core/ingestion/languages/php.ts @@ -27,7 +27,6 @@ import { phpVariableConfig } from '../variable-extractors/configs/php.js'; import { createCallExtractor } from '../call-extractors/generic.js'; import { phpCallConfig } from '../call-extractors/configs/php.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { phpHeritageConfig } from '../heritage-extractors/configs/php.js'; const BUILT_INS: ReadonlySet = new Set([ 'echo', @@ -250,7 +249,7 @@ export const phpProvider = defineLanguage({ methodExtractor: createMethodExtractor(phpMethodConfig), variableExtractor: createVariableExtractor(phpVariableConfig), classExtractor: createClassExtractor(phpClassConfig), - heritageExtractor: createHeritageExtractor(phpHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.PHP), descriptionExtractor: phpDescriptionExtractor, isRouteFile: isPhpRouteFile, builtInNames: BUILT_INS, diff --git a/gitnexus/src/core/ingestion/languages/python.ts b/gitnexus/src/core/ingestion/languages/python.ts index 3c06b0bd1..5773cd3dd 100644 --- a/gitnexus/src/core/ingestion/languages/python.ts +++ b/gitnexus/src/core/ingestion/languages/python.ts @@ -29,7 +29,6 @@ import { pythonVariableConfig } from '../variable-extractors/configs/python.js'; import { createCallExtractor } from '../call-extractors/generic.js'; import { pythonCallConfig } from '../call-extractors/configs/python.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { pythonHeritageConfig } from '../heritage-extractors/configs/python.js'; const BUILT_INS: ReadonlySet = new Set([ 'print', @@ -76,6 +75,6 @@ export const pythonProvider = defineLanguage({ methodExtractor: createMethodExtractor(pythonMethodConfig), variableExtractor: createVariableExtractor(pythonVariableConfig), classExtractor: createClassExtractor(pythonClassConfig), - heritageExtractor: createHeritageExtractor(pythonHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.Python), builtInNames: BUILT_INS, }); diff --git a/gitnexus/src/core/ingestion/languages/rust.ts b/gitnexus/src/core/ingestion/languages/rust.ts index 70df56ad1..ac0cd5788 100644 --- a/gitnexus/src/core/ingestion/languages/rust.ts +++ b/gitnexus/src/core/ingestion/languages/rust.ts @@ -31,7 +31,6 @@ import { rustVariableConfig } from '../variable-extractors/configs/rust.js'; import { createCallExtractor } from '../call-extractors/generic.js'; import { rustCallConfig } from '../call-extractors/configs/rust.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { rustHeritageConfig } from '../heritage-extractors/configs/rust.js'; /** Rust impl_item: find the function_item child and extract its name as a Method. */ const rustExtractFunctionName = ( @@ -136,6 +135,6 @@ export const rustProvider = defineLanguage({ }), variableExtractor: createVariableExtractor(rustVariableConfig), classExtractor: createClassExtractor(rustClassConfig), - heritageExtractor: createHeritageExtractor(rustHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.Rust), builtInNames: BUILT_INS, }); diff --git a/gitnexus/src/core/ingestion/languages/swift.ts b/gitnexus/src/core/ingestion/languages/swift.ts index 07777f058..38f5d8147 100644 --- a/gitnexus/src/core/ingestion/languages/swift.ts +++ b/gitnexus/src/core/ingestion/languages/swift.ts @@ -31,7 +31,6 @@ import { swiftVariableConfig } from '../variable-extractors/configs/swift.js'; import { createCallExtractor } from '../call-extractors/generic.js'; import { swiftCallConfig } from '../call-extractors/configs/swift.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { swiftHeritageConfig } from '../heritage-extractors/configs/swift.js'; /** * Group Swift files by SPM target for implicit module visibility. @@ -256,7 +255,7 @@ export const swiftProvider = defineLanguage({ }), variableExtractor: createVariableExtractor(swiftVariableConfig), classExtractor: createClassExtractor(swiftClassConfig), - heritageExtractor: createHeritageExtractor(swiftHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.Swift), implicitImportWirer: wireSwiftImplicitImports, builtInNames: BUILT_INS, }); diff --git a/gitnexus/src/core/ingestion/languages/typescript.ts b/gitnexus/src/core/ingestion/languages/typescript.ts index 018852978..0a1c3f28f 100644 --- a/gitnexus/src/core/ingestion/languages/typescript.ts +++ b/gitnexus/src/core/ingestion/languages/typescript.ts @@ -44,10 +44,6 @@ import { javascriptCallConfig, } from '../call-extractors/configs/typescript-javascript.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { - typescriptHeritageConfig, - javascriptHeritageConfig, -} from '../heritage-extractors/configs/typescript-javascript.js'; /** * TypeScript/JavaScript: arrow_function and function_expression get their name @@ -187,7 +183,7 @@ export const typescriptProvider = defineLanguage({ }), variableExtractor: createVariableExtractor(typescriptVariableConfig), classExtractor: createClassExtractor(typescriptClassConfig), - heritageExtractor: createHeritageExtractor(typescriptHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.TypeScript), builtInNames: BUILT_INS, }); @@ -207,6 +203,6 @@ export const javascriptProvider = defineLanguage({ }), variableExtractor: createVariableExtractor(javascriptVariableConfig), classExtractor: createClassExtractor(javascriptClassConfig), - heritageExtractor: createHeritageExtractor(javascriptHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.JavaScript), builtInNames: BUILT_INS, }); diff --git a/gitnexus/src/core/ingestion/languages/vue.ts b/gitnexus/src/core/ingestion/languages/vue.ts index 457262e8c..51ab37882 100644 --- a/gitnexus/src/core/ingestion/languages/vue.ts +++ b/gitnexus/src/core/ingestion/languages/vue.ts @@ -28,7 +28,6 @@ import { typescriptVariableConfig } from '../variable-extractors/configs/typescr import { createCallExtractor } from '../call-extractors/generic.js'; import { typescriptCallConfig } from '../call-extractors/configs/typescript-javascript.js'; import { createHeritageExtractor } from '../heritage-extractors/generic.js'; -import { typescriptHeritageConfig } from '../heritage-extractors/configs/typescript-javascript.js'; const VUE_SPECIFIC_BUILT_INS = [ 'ref', @@ -78,6 +77,6 @@ export const vueProvider = defineLanguage({ fieldExtractor: typescriptFieldExtractor, variableExtractor: createVariableExtractor(typescriptVariableConfig), classExtractor: vueClassExtractor, - heritageExtractor: createHeritageExtractor(typescriptHeritageConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.TypeScript), builtInNames: VUE_BUILT_INS, }); diff --git a/gitnexus/test/unit/heritage-extraction.test.ts b/gitnexus/test/unit/heritage-extraction.test.ts index 08908c3f2..93010fa78 100644 --- a/gitnexus/test/unit/heritage-extraction.test.ts +++ b/gitnexus/test/unit/heritage-extraction.test.ts @@ -1,25 +1,7 @@ import { describe, it, expect } from 'vitest'; import { createHeritageExtractor } from '../../src/core/ingestion/heritage-extractors/generic.js'; -import { - javaHeritageConfig, - kotlinHeritageConfig, -} from '../../src/core/ingestion/heritage-extractors/configs/jvm.js'; -import { csharpHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/csharp.js'; -import { - typescriptHeritageConfig, - javascriptHeritageConfig, -} from '../../src/core/ingestion/heritage-extractors/configs/typescript-javascript.js'; -import { - cHeritageConfig, - cppHeritageConfig, -} from '../../src/core/ingestion/heritage-extractors/configs/c-cpp.js'; -import { pythonHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/python.js'; import { rubyHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/ruby.js'; -import { rustHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/rust.js'; -import { dartHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/dart.js'; import { goHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/go.js'; -import { phpHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/php.js'; -import { swiftHeritageConfig } from '../../src/core/ingestion/heritage-extractors/configs/swift.js'; import type { HeritageExtractionConfig, HeritageExtractorContext, @@ -73,29 +55,37 @@ function ctx(filePath = 'Test.java', language = SupportedLanguages.Java): Herita describe('createHeritageExtractor', () => { it('creates an extractor from a minimal config', () => { - const extractor = createHeritageExtractor(javaHeritageConfig); + const extractor = createHeritageExtractor(SupportedLanguages.Java); expect(extractor).toBeDefined(); expect(extractor.language).toBe(SupportedLanguages.Java); expect(typeof extractor.extract).toBe('function'); }); - it('accepts all currently registered language configs', () => { - const configs: HeritageExtractionConfig[] = [ - javaHeritageConfig, - kotlinHeritageConfig, - csharpHeritageConfig, - typescriptHeritageConfig, - javascriptHeritageConfig, - cppHeritageConfig, - cHeritageConfig, - pythonHeritageConfig, - rubyHeritageConfig, - rustHeritageConfig, - dartHeritageConfig, - goHeritageConfig, - phpHeritageConfig, - swiftHeritageConfig, + it('creates an extractor from a language enum (default config)', () => { + const languages: SupportedLanguages[] = [ + SupportedLanguages.Java, + SupportedLanguages.Kotlin, + SupportedLanguages.CSharp, + SupportedLanguages.TypeScript, + SupportedLanguages.JavaScript, + SupportedLanguages.CPlusPlus, + SupportedLanguages.C, + SupportedLanguages.Python, + SupportedLanguages.Rust, + SupportedLanguages.Dart, + SupportedLanguages.PHP, + SupportedLanguages.Swift, ]; + for (const lang of languages) { + const extractor = createHeritageExtractor(lang); + expect(extractor.language, `${lang} extractor should have correct language`).toBe(lang); + expect(typeof extractor.extract).toBe('function'); + expect(extractor.extractFromCall).toBeUndefined(); + } + }); + + it('creates an extractor from full config with custom hooks', () => { + const configs: HeritageExtractionConfig[] = [goHeritageConfig, rubyHeritageConfig]; for (const cfg of configs) { expect( () => createHeritageExtractor(cfg), @@ -110,8 +100,8 @@ describe('createHeritageExtractor', () => { expect(typeof extractor.extractFromCall).toBe('function'); }); - it('does not set extractFromCall when callBasedHeritage is absent', () => { - const extractor = createHeritageExtractor(javaHeritageConfig); + it('does not set extractFromCall for default language extractors', () => { + const extractor = createHeritageExtractor(SupportedLanguages.Java); expect(extractor.extractFromCall).toBeUndefined(); }); }); @@ -121,7 +111,7 @@ describe('createHeritageExtractor', () => { // --------------------------------------------------------------------------- describe('HeritageExtractor.extract', () => { - const extractor = createHeritageExtractor(javaHeritageConfig); + const extractor = createHeritageExtractor(SupportedLanguages.Java); it('returns empty array when heritage.class is not present', () => { const captures = buildCaptureMap({}); @@ -156,7 +146,7 @@ describe('HeritageExtractor.extract', () => { }); it('extracts trait-impl heritage', () => { - const rustExtractor = createHeritageExtractor(rustHeritageConfig); + const rustExtractor = createHeritageExtractor(SupportedLanguages.Rust); const captures = buildCaptureMap({ 'heritage.class': makeNode('MyStruct'), 'heritage.trait': makeNode('Display'), @@ -370,16 +360,6 @@ describe('Ruby HeritageExtractor — call-based heritage', () => { // --------------------------------------------------------------------------- describe('HeritageExtraction language configs', () => { - it('Java config has correct language', () => { - expect(javaHeritageConfig.language).toBe(SupportedLanguages.Java); - expect(javaHeritageConfig.shouldSkipExtends).toBeUndefined(); - expect(javaHeritageConfig.callBasedHeritage).toBeUndefined(); - }); - - it('Kotlin config has correct language', () => { - expect(kotlinHeritageConfig.language).toBe(SupportedLanguages.Kotlin); - }); - it('Go config has shouldSkipExtends hook', () => { expect(goHeritageConfig.language).toBe(SupportedLanguages.Go); expect(goHeritageConfig.shouldSkipExtends).toBeDefined(); @@ -394,44 +374,26 @@ describe('HeritageExtraction language configs', () => { ); }); - it('Swift config has correct language', () => { - expect(swiftHeritageConfig.language).toBe(SupportedLanguages.Swift); - }); - - it('Rust config has correct language', () => { - expect(rustHeritageConfig.language).toBe(SupportedLanguages.Rust); - }); - - it('TypeScript config has correct language', () => { - expect(typescriptHeritageConfig.language).toBe(SupportedLanguages.TypeScript); - }); - - it('JavaScript config has correct language', () => { - expect(javascriptHeritageConfig.language).toBe(SupportedLanguages.JavaScript); - }); - - it('C config has correct language', () => { - expect(cHeritageConfig.language).toBe(SupportedLanguages.C); - }); - - it('C++ config has correct language', () => { - expect(cppHeritageConfig.language).toBe(SupportedLanguages.CPlusPlus); - }); - - it('Python config has correct language', () => { - expect(pythonHeritageConfig.language).toBe(SupportedLanguages.Python); - }); - - it('PHP config has correct language', () => { - expect(phpHeritageConfig.language).toBe(SupportedLanguages.PHP); - }); - - it('Dart config has correct language', () => { - expect(dartHeritageConfig.language).toBe(SupportedLanguages.Dart); - }); - - it('C# config has correct language', () => { - expect(csharpHeritageConfig.language).toBe(SupportedLanguages.CSharp); + it('default language extractors have no custom hooks', () => { + const defaultLanguages: SupportedLanguages[] = [ + SupportedLanguages.Java, + SupportedLanguages.Kotlin, + SupportedLanguages.CSharp, + SupportedLanguages.TypeScript, + SupportedLanguages.JavaScript, + SupportedLanguages.CPlusPlus, + SupportedLanguages.C, + SupportedLanguages.Python, + SupportedLanguages.Rust, + SupportedLanguages.Dart, + SupportedLanguages.PHP, + SupportedLanguages.Swift, + ]; + for (const lang of defaultLanguages) { + const extractor = createHeritageExtractor(lang); + expect(extractor.language).toBe(lang); + expect(extractor.extractFromCall, `${lang} should not have extractFromCall`).toBeUndefined(); + } }); });