diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts new file mode 100644 index 0000000..a8724f4 --- /dev/null +++ b/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts @@ -0,0 +1,48 @@ +import type { StructuralAnalysis, CallGraphEntry } from "../../types.js"; +import type { LanguageExtractor, TreeSitterNode } from "./types.js"; +import { findChild, findChildren } from "./base-extractor.js"; + +/** + * Whether a Dart name is exported. + * + * Dart's visibility rule is name-based and the INVERSE of Kotlin's: names + * starting with `_` are library-private, everything else is exported. There + * is no `public` / `private` keyword to inspect — only the leading character. + */ +function isExported(name: string): boolean { + return !name.startsWith("_"); +} + +/** + * Dart extractor for tree-sitter structural analysis + call graph. + * + * Approach (matching `KotlinExtractor` convention): mixin / extension / enum + * declarations are folded into `StructuralAnalysis.classes[]` because the + * shared schema does not have a first-class slot for them. Extension + * declarations without a name surface as `"on "` so they aren't + * silently dropped. + */ +export class DartExtractor implements LanguageExtractor { + readonly languageIds = ["dart"]; + + extractStructure(rootNode: TreeSitterNode): StructuralAnalysis { + const functions: StructuralAnalysis["functions"] = []; + const classes: StructuralAnalysis["classes"] = []; + const imports: StructuralAnalysis["imports"] = []; + const exports: StructuralAnalysis["exports"] = []; + + // Implementation lands in subsequent tasks. + void rootNode; + void findChild; + void findChildren; + void isExported; + + return { functions, classes, imports, exports }; + } + + extractCallGraph(rootNode: TreeSitterNode): CallGraphEntry[] { + // Implementation lands in a later task. + void rootNode; + return []; + } +} diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/index.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/index.ts index 4f0b5a3..8fbe736 100644 --- a/understand-anything-plugin/packages/core/src/plugins/extractors/index.ts +++ b/understand-anything-plugin/packages/core/src/plugins/extractors/index.ts @@ -9,6 +9,7 @@ export { RubyExtractor } from "./ruby-extractor.js"; export { PhpExtractor } from "./php-extractor.js"; export { CppExtractor } from "./cpp-extractor.js"; export { CSharpExtractor } from "./csharp-extractor.js"; +export { DartExtractor } from "./dart-extractor.js"; export { KotlinExtractor } from "./kotlin-extractor.js"; import type { LanguageExtractor } from "./types.js"; @@ -21,6 +22,7 @@ import { RubyExtractor } from "./ruby-extractor.js"; import { PhpExtractor } from "./php-extractor.js"; import { CppExtractor } from "./cpp-extractor.js"; import { CSharpExtractor } from "./csharp-extractor.js"; +import { DartExtractor } from "./dart-extractor.js"; import { KotlinExtractor } from "./kotlin-extractor.js"; export const builtinExtractors: LanguageExtractor[] = [ @@ -33,5 +35,6 @@ export const builtinExtractors: LanguageExtractor[] = [ new PhpExtractor(), new CppExtractor(), new CSharpExtractor(), + new DartExtractor(), new KotlinExtractor(), ];