fix(swift): extract computed & observed properties (#2181)#2220
Open
ozdemirsarman wants to merge 1 commit into
Open
fix(swift): extract computed & observed properties (#2181)#2220ozdemirsarman wants to merge 1 commit into
ozdemirsarman wants to merge 1 commit into
Conversation
function_types only recognised func/init/deinit/subscript, so computed properties (var body: some View { ... }) and willSet/didSet observers produced no node and their bodies were never walked — erasing the whole SwiftUI view layer. Emit a function-like member node for them and defer the body to the call-walk via function_bodies; stored properties are unchanged. Adds tests.
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.
Closes #2181.
Problem
Swift's extractor only treats
function_declaration,init_declaration,deinit_declarationandsubscript_declarationas callables(
_SWIFT_CONFIG.function_types). Computed properties parse asproperty_declaration → computed_property → statements, which no branchhandled — so they produced no node and their bodies were never walked.
For SwiftUI this is severe:
var body: some View { … }is a computed property,so an entire view file collapses to just the file + struct nodes and every UI
element and call inside
bodydisappears.willSet/didSetobservers have thesame shape and lost their body calls too.
Before (repro)
Only
.doTap()was emitted;body,toggled, and thedoTap()call insidebodywere all missing.Fix
In the Swift
property_declarationbranch (which already collects type-annotationreferences), after the existing handling: if the property has a
computed_propertyor
willset_didset_blockchild, emit a function-like member node (.name,methodedge to the enclosing type) and defer its body to the call-walk viafunction_bodies— the same mechanism methods use. This is additive: theexisting
references/field edges from the property's type are unchanged.Stored properties have no body child, so they are untouched (no regression).
After
.bodyand.toggledare emitted, and thedoTap()call insidebodynowproduces a
callsedge from.body→.doTap(), so the view hierarchy istraversed.
Tests
Adds
tests/test_swift_computed_properties.py:referencesedge (regression guard);willSet/didSetobserver body is walked.Full language test suite (
test_languages.py, 324 tests) and the existing Swifttests pass with no changes.