Skip to content

feat(parser): add Dart language support#50

Merged
tirth8205 merged 1 commit intotirth8205:mainfrom
MohammedAlsayani:feat/dart-language-support
Mar 26, 2026
Merged

feat(parser): add Dart language support#50
tirth8205 merged 1 commit intotirth8205:mainfrom
MohammedAlsayani:feat/dart-language-support

Conversation

@MohammedAlsayani
Copy link

Summary

  • Adds .dart to EXTENSION_TO_LANGUAGE, enabling the graph to parse Flutter/Dart codebases
  • Populates _CLASS_TYPES, _FUNCTION_TYPES, and _IMPORT_TYPES for Dart
  • Extends _get_name, _get_params, _get_bases, _extract_import, and _do_resolve_module with Dart-specific logic
  • Adds *_test.dart to _TEST_FILE_PATTERNS
  • Adds tests/fixtures/sample.dart and 7 new test cases (all 35 parser tests pass)

What's extracted

Node type Dart AST nodes
Class class_definition, mixin_declaration, enum_declaration
Function function_signature (top-level and class methods via method_signature recursion)
IMPORTS_FROM import_or_export → walks to string_literal URI
INHERITS extends, with (mixins), implements clauses
CONTAINS file→class, class→method

Known limitation

Dart's AST represents method bodies as function_body siblings of method_signature, rather than children. The current walker architecture attributes calls to enclosing_func via 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_dart
  • test_parse_dart_file — Class, Function nodes extracted correctly
  • test_parse_dart_importsdart:async, package:flutter/material.dart
  • test_parse_dart_inheritanceextends Animal, with SwimmingMixin
  • test_parse_dart_contains_edges — file→class and class→method CONTAINS
  • test_parse_dart_method_parent — method parent_name set to enclosing class
  • test_parse_dart_top_level_function_no_parent — top-level fns have parent_name=None
  • All 28 pre-existing tests continue to pass

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.
@tirth8205 tirth8205 merged commit 5fd69d2 into tirth8205:main Mar 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants