fix(swift): index protocol method requirements as Method nodes - #1763
Merged
Conversation
A Swift protocol requirement — a bodyless `func generate() -> String` inside a protocol — was absent from the graph entirely. Swift codebases are heavily protocol-driven, so the requirement is very often the declaration a reader is looking for, and "who declares generate()" had no answer. Three edits deliver it: protocol_body joins the class-body types so a protocol's members are walked at all; protocol_function_declaration joins swift_func_types, because extract_class_methods gates on that set and would otherwise walk the requirement and discard it; and both name resolvers accept the node, which has the same simple_identifier shape as function_declaration. Distilled from #613 by xbsjason. That PR also carried an enum/struct half whose two assertions fail on CI: tree-sitter-swift has no struct_declaration or enum_declaration node type (it models both as class_declaration), so the corresponding swift_class_types entries are inert and a bare enum is still labeled Class. That is a real pre-existing modelling gap, left untouched here and now documented at the dead entries rather than silently deleted. Also dropped from the original: a find_first_descendant_by_kind rescue in extract_class_methods. Removing it changes no test outcome once the function-type entry is present, so it was carrying nothing. Advances #43. Co-authored-by: xbsjason <xbsjason@gmail.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
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.
fix(swift): index protocol method requirements as Method nodes
Advances #43. Distilled from #613 by @xbsjason, credited via
Co-authored-by.The gap
A Swift protocol requirement — a bodyless
func generate() -> Stringinside aprotocol— produced no node at all. Swift codebases are heavily protocol-driven, so the requirement is frequently the declaration a reader actually wants, and "who declaresgenerate()" simply had no answer.What delivers it
Three edits, and I verified each is load-bearing by removing it and watching the test fail:
protocol_bodyjoins the class-body types infind_class_body— without it, a protocol's members are never walked.protocol_function_declarationjoinsswift_func_types—extract_class_methodsgates on that set, so without the entry the requirement gets walked and then discarded.simple_identifiershape asfunction_declaration, and since it now reaches the free-function path too, naming it in only one place would leave a latent unnamed-def bug.What I dropped from #613, and why
The enum/struct half. #613 also tried to make bare
struct/enumproduceClass/Enumnodes, and both of its assertions fail on CI (lsan-macos,test-unix, and Windows alike). The cause is worth recording: tree-sitter-swift has nostruct_declarationorenum_declarationnode type — it models both asclass_declaration:So those two entries in
swift_class_typeshave been inert since they were written,class_label_for_kind'senum_declaration → "Enum"branch never fires for Swift, and a bare Swiftenumis labeledClass. That is a genuine pre-existing modelling gap. I've left the dead entries in place with a comment naming the problem — deleting them would tidy the code while erasing the only marker that the gap exists — and it stays out of this PR.A
find_first_descendant_by_kindrescue inextract_class_methods. Removing it changes no test outcome once the function-type entry is present, so it was carrying nothing.The result is three production edits instead of six, with no behaviour left unproven.
Tests
swift_protocolassertsInterface:StudyRunning+Method:generate. It is binding: applied against unmodifiedmain, it fails on exactlyASSERT(has_def(r, "Method", "generate")).Verification
macOS ASan/UBSan: extraction, grammar_labels, grammar_probe_g, grammar_regression, lang_contract, parse_coverage — 384 passed, 0 failed.
lint-cigreen.