Skip to content

feat(swift): add extension detection, inheritance edges, and type kind#202

Open
lngyeen wants to merge 1 commit intotirth8205:mainfrom
lngyeen:feat/swift-extensions-inheritance-kind
Open

feat(swift): add extension detection, inheritance edges, and type kind#202
lngyeen wants to merge 1 commit intotirth8205:mainfrom
lngyeen:feat/swift-extensions-inheritance-kind

Conversation

@lngyeen
Copy link
Copy Markdown

@lngyeen lngyeen commented Apr 10, 2026

Summary

  • Extension detection: Fixed _get_name() to extract names from user_type > type_identifier for Swift extensions — previously extensions were silently dropped because the name was nested one level deeper than the generic path expected.
  • Inheritance/conformance edges: Added Swift branch to _get_bases() that walks inheritance_specifier > user_type > type_identifier — previously zero INHERITS edges were produced for any Swift file.
  • Type differentiation: Populated extra["swift_kind"] with the actual keyword (class/struct/enum/actor/extension/protocol) following the same pattern as Solidity's extra["solidity_kind"].

Motivation

Swift's Tree-sitter grammar maps struct, enum, actor, and extension declarations all to class_declaration nodes. The existing parser handled the first three correctly (since type_identifier is a direct child), but extensions use user_type > type_identifier for the extended type name, which was not traversed.

Similarly, Swift uses inheritance_specifier > user_type > type_identifier for protocol conformances and class inheritance, but _get_bases() had no Swift-specific branch, resulting in zero inheritance edges.

These gaps are significant for Swift projects using Clean Architecture (protocol-oriented design, extensions for conformance, actors for isolation).

Changes

File Change
parser.py:_get_name() Added Swift extension name extraction via user_type
parser.py:_get_bases() Added Swift inheritance_specifier traversal
parser.py:_extract_classes() Populate extra["swift_kind"] from keyword child
tests/fixtures/sample.swift Added enum, actor, and extension samples
tests/test_multilang.py Added 6 new tests for enum, actor, extension, protocol, swift_kind, and inheritance edges

Test plan

  • All 9 Swift tests pass (TestSwiftParsing)
  • All 621 tests pass with zero regressions
  • Verified AST structure with Tree-sitter Swift grammar directly

Three improvements to Swift language support:

1. Extension detection: extract name from user_type > type_identifier
   in _get_name() -- previously extensions were silently dropped because
   the name sat one level deeper than the generic path expected.

2. Inheritance/conformance edges: add Swift branch to _get_bases() that
   walks inheritance_specifier > user_type > type_identifier -- previously
   zero INHERITS edges were produced for Swift files.

3. Type differentiation: populate extra[swift_kind] with the actual
   keyword (class/struct/enum/actor/extension/protocol) following the
   same pattern as Solidity extra[solidity_kind].

Updated test fixture with enum, actor, and extension samples.
Added 6 new tests covering all three fixes.
All 621 existing tests pass with no regressions.
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.

1 participant