Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

feat(core): DartExtractor — enum declarations

thejeshfd1d1c6450ab
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts
index 3bab6ea9..4cf09f2c 100644
--- a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts
@@ -220,6 +220,19 @@ describe("DartExtractor", () => {
});
});
+ describe("extractStructure - enums", () => {
+ it("extracts a simple enum and surfaces its constants as properties", () => {
+ const { tree, parser, root } = parse(`enum Color { red, green, blue }\n`);
+ const result = extractor.extractStructure(root);
+
+ expect(result.classes).toHaveLength(1);
+ expect(result.classes[0].name).toBe("Color");
+ expect(result.classes[0].properties).toEqual(["red", "green", "blue"]);
+ tree.delete();
+ parser.delete();
+ });
+ });
+
describe("extractStructure - extensions", () => {
it("extracts a named extension on String", () => {
const { tree, parser, root } = parse(`extension StringX on String {
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
index dacdfee5..5e37f467 100644
--- a/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts
@@ -241,6 +241,9 @@ export class DartExtractor implements LanguageExtractor {
case "extension_declaration":
this.extractExtensionDeclaration(node, classes, functions, exports);
break;
+ case "enum_declaration":
+ this.extractEnumDeclaration(node, classes, exports);
+ break;
}
}
@@ -348,6 +351,36 @@ export class DartExtractor implements LanguageExtractor {
);
}
+ private extractEnumDeclaration(
+ declNode: TreeSitterNode,
+ classes: StructuralAnalysis["classes"],
+ exports: StructuralAnalysis["exports"],
+ ): void {
+ const nameNode = findChild(declNode, "identifier");
+ if (!nameNode) return;
+ const name = nameNode.text;
+
+ const properties: string[] = [];
+ const body = findChild(declNode, "enum_body");
+ if (body) {
+ for (const k of findChildren(body, "enum_constant")) {
+ const id = findChild(k, "identifier");
+ if (id) properties.push(id.text);
+ }
+ }
+
+ classes.push({
+ name,
+ lineRange: [declNode.startPosition.row + 1, declNode.endPosition.row + 1],
+ methods: [],
+ properties,
+ });
+
+ if (isExported(name)) {
+ exports.push({ name, lineNumber: declNode.startPosition.row + 1 });
+ }
+ }
+
extractCallGraph(rootNode: TreeSitterNode): CallGraphEntry[] {
// Implementation lands in a later task.
void rootNode;