Skip to content

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

Merged
tirth8205 merged 1 commit intotirth8205:mainfrom
lngyeen:feat/swift-extensions-inheritance-kind
Apr 14, 2026
Merged

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

Conversation

@lngyeen
Copy link
Copy Markdown
Contributor

@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

@tirth8205
Copy link
Copy Markdown
Owner

This PR is correct and well-implemented — the Swift extension name extraction, inheritance edges, and swift_kind differentiation all follow existing patterns (Solidity's solidity_kind, the C/C++ _get_name ordering). The 6 new tests are thorough.

However, the branch now has merge conflicts with main (likely in tests/test_multilang.py due to the Luau PR #165 that was just merged). Please rebase onto main and resolve the conflicts — the changes themselves are in different class sections so the resolution should be straightforward.

Once rebased, this is ready to merge.

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.
@lngyeen lngyeen force-pushed the feat/swift-extensions-inheritance-kind branch from c07d9ce to 3d3cf01 Compare April 13, 2026 03:11
@lngyeen
Copy link
Copy Markdown
Contributor Author

lngyeen commented Apr 13, 2026

Rebased onto latest main — conflicts resolved, all 9 Swift tests passing. No changes lost; the only conflict was positional (new ObjC/Bash/Go blocks in _get_name()). Ready for re-review.

@tirth8205 tirth8205 merged commit 2c18544 into tirth8205:main Apr 14, 2026
1 check passed
tirth8205 added a commit that referenced this pull request Apr 14, 2026
15 new features: hub/bridge node detection, knowledge gap analysis,
surprise scoring, suggested questions, BFS/DFS traversal, edge
confidence scoring, export formats (GraphML/Neo4j/Obsidian/SVG),
graph diff, token benchmarking, memory loop, community auto-splitting,
4 new languages (Zig/PowerShell/Julia/Svelte), visualization
enhancements (degree-scaled nodes, community legend toggles).

6 community PRs merged: #127, #184, #202, #249, #253, #267.
28 MCP tools (was 22). Schema v9. 788 tests pass.

README translations: zh-CN, ja-JP, ko-KR, hi-IN.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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