feat(swift): add extension detection, inheritance edges, and type kind#202
Open
lngyeen wants to merge 1 commit intotirth8205:mainfrom
Open
feat(swift): add extension detection, inheritance edges, and type kind#202lngyeen wants to merge 1 commit intotirth8205:mainfrom
lngyeen wants to merge 1 commit intotirth8205:mainfrom
Conversation
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.
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
_get_name()to extract names fromuser_type > type_identifierfor Swift extensions — previously extensions were silently dropped because the name was nested one level deeper than the generic path expected._get_bases()that walksinheritance_specifier > user_type > type_identifier— previously zeroINHERITSedges were produced for any Swift file.extra["swift_kind"]with the actual keyword (class/struct/enum/actor/extension/protocol) following the same pattern as Solidity'sextra["solidity_kind"].Motivation
Swift's Tree-sitter grammar maps
struct,enum,actor, andextensiondeclarations all toclass_declarationnodes. The existing parser handled the first three correctly (sincetype_identifieris a direct child), but extensions useuser_type > type_identifierfor the extended type name, which was not traversed.Similarly, Swift uses
inheritance_specifier > user_type > type_identifierfor 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
parser.py:_get_name()user_typeparser.py:_get_bases()inheritance_specifiertraversalparser.py:_extract_classes()extra["swift_kind"]from keyword childtests/fixtures/sample.swiftenum,actor, andextensionsamplestests/test_multilang.pyTest plan
TestSwiftParsing)