feat(parser): add Dart language support#50
Merged
tirth8205 merged 1 commit intotirth8205:mainfrom Mar 26, 2026
Merged
Conversation
Add `.dart` to EXTENSION_TO_LANGUAGE and populate the four node-type maps for Dart: - _CLASS_TYPES: class_definition, mixin_declaration, enum_declaration - _FUNCTION_TYPES: function_signature (covers top-level functions and class methods; the parser recurses into method_signature generically and matches function_signature inside it) - _IMPORT_TYPES: import_or_export (walks down to string_literal for the URI value) - _CALL_TYPES: omitted — Dart's AST lacks a dedicated call_expression wrapper; CALLS attribution will be added in a follow-up Supporting changes: - _get_name: Dart-specific path for function_signature to skip the return-type node and return the identifier (function name) - _get_params: accept formal_parameter_list (Dart's param list type) - _get_bases: handle superclass/mixins/interfaces children for INHERITS edges across extends, with, and implements clauses - _extract_import: recursive string_literal finder for import_or_export - _do_resolve_module: resolve relative Dart imports (.dart extension) - _TEST_FILE_PATTERNS: detect *_test.dart as test files Adds tests/fixtures/sample.dart covering abstract class, mixin, enum, inheritance (extends + with + implements), top-level function, and class methods. 7 new test cases, all 35 parser tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.darttoEXTENSION_TO_LANGUAGE, enabling the graph to parse Flutter/Dart codebases_CLASS_TYPES,_FUNCTION_TYPES, and_IMPORT_TYPESfor Dart_get_name,_get_params,_get_bases,_extract_import, and_do_resolve_modulewith Dart-specific logic*_test.dartto_TEST_FILE_PATTERNStests/fixtures/sample.dartand 7 new test cases (all 35 parser tests pass)What's extracted
Classclass_definition,mixin_declaration,enum_declarationFunctionfunction_signature(top-level and class methods viamethod_signaturerecursion)IMPORTS_FROMimport_or_export→ walks tostring_literalURIINHERITSextends,with(mixins),implementsclausesCONTAINSKnown limitation
Dart's AST represents method bodies as
function_bodysiblings ofmethod_signature, rather than children. The current walker architecture attributes calls toenclosing_funcvia parent-node recursion, so CALLS edges inside method bodies are not attributed in this initial pass. A follow-up can add a Dart-specific sibling-lookahead in_extract_from_tree.Test plan
test_detect_language_darttest_parse_dart_file— Class, Function nodes extracted correctlytest_parse_dart_imports—dart:async,package:flutter/material.darttest_parse_dart_inheritance—extends Animal,with SwimmingMixintest_parse_dart_contains_edges— file→class and class→method CONTAINStest_parse_dart_method_parent— methodparent_nameset to enclosing classtest_parse_dart_top_level_function_no_parent— top-level fns haveparent_name=None