Repository navigation
Conversation
Add SwiftPlugin for .swift files, built on tree-sitter-swift (0.7.x, alex-pinkus grammar). In this grammar class, struct, enum, extension and actor are all class_declaration, told apart by declaration_kind. - Skeleton: class/actor, struct, enum and its cases, protocol (interface), extension (named after the extended type, last component for Outer.Inner), typealias, func, init/deinit, subscript and computed properties (SwiftUI `var body: some View`), with the right parent for nested types. Params keep external labels. Doc comments come from /// and /** */ only, so `// MARK: -` is not reported as a docstring. - get_symbol includes attributes and modifiers (@mainactor, private, static, override...). - Calls: functions, methods, self.foo(), foo?.bar(), Foo(...), Foo<T>(), trailing closures. init is not reported as a callee, since super.init()/.init() would resolve to every init in the repo. - Complexity: if, guard, switch cases, for, while, repeat, catch, &&, ||, ??, ternary. - Variables: parameters, let/var (including tuples), if/guard/while let, for, closure parameters, case and catch bindings. - Imports: import Foo, @testable import Foo. - Tests: test*() methods of classes inheriting a *Test* base (XCTestCase or a custom one) and @test functions (Swift Testing) carry an is_test flag. Indexer.find_tests honours that flag, so tests that do not follow the test_*/Test* naming convention are found. On a ~2 600-file Swift repository, indexing takes about 3 s, every func declaration except local nested functions is in the skeleton, and about 3% of files report syntax errors (mostly @available on #Preview, which the grammar does not parse; skeletons stay complete). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kevinrob
marked this pull request as ready for review
November 18, 2026 10:34
…tor kind An extension was reported as a second `class` with the extended type's name. Like Rust `impl Foo`, it is no longer a skeleton item: its members keep the extended type as parent, so references, call graph and blast radius attach them to the same type, and the graph no longer merges a duplicate symbol. Actors are reported with a new `actor` kind, which the skeleton formatter renders like the other type kinds (`actor Worker → line 1`, compact `act Worker:1`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The full skeleton format printed type kinds (class, struct, enum, type,
actor...) without indentation or "(in Parent)", so a Swift typealias or
nested type declared in a type or an extension looked file-level. Type
kinds now use the same parent prefix as methods:
struct CardView → line 2
type ViewModel (in CardView) → line 3
Only Swift emits nested types with a parent today, so other languages'
output is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Summary
Adds Swift (
.swift) support, following the same model as the Kotlin plugin: aSwiftPluginbuilt ontree-sitter-swift(0.7.x, wheels for macOS arm64/x86_64, Linux and Windows).In this grammar
class,struct,enum,extensionandactorare allclass_declaration, told apart bydeclaration_kind; functions have no parameter-list node, so params are sliced between the declaration's own parens.Changes
src/codetree/languages/swift.py— newSwiftPlugin:actor), struct, enum + its cases (new kindcase, with associated values as params), protocol (interface), typealias (type), func,init/deinit,subscript, computed properties (e.g. SwiftUIvar body: some View). Nested types get the rightparent. Like Rustimpl Foo, anextensionis not a symbol itself: its members keep the extended type asparent(last component forextension Outer.Inner), so references, call graph and blast radius attach them to the same type. Params keep external labels:(from url: URL, completion: @escaping (Result<Data, Error>) -> Void).///and/** */count, so// MARK: -comments are not reported as docstrings.get_symbol: full source including attributes and modifiers (@MainActor,@available,private static,override…); a type's own declaration is preferred over its extensions.self.foo(),foo?.bar(),Foo(...),Foo<T>(), trailing closures.initis not reported as a callee (super.init()/.init()would resolve to everyinitin the repo).if,guard,switchcases,for,while,repeat,catch,&&,||,??, ternary.let/var(incl. tuple destructuring),if/guard/while let, loop vars, closure parameters,case/catchbindings.import Foo,@testable import Foo,import struct Swift.Array.test*()methods in classes inheriting a*Test*base (XCTestCaseor a custom base class) and@Testfunctions (Swift Testing) carry anis_testflag.src/codetree/server.py— the skeleton formatter renders theactorkind like the other type kinds (actor Worker → line 1, compactact Worker:1), and shows the parent of nested types the same way as for methods (type ViewModel (in CardView) → line 3). Only Swift emits nested types with a parent, so other languages' output is unchanged.src/codetree/indexer.py—find_testshonours the plugin-setis_testflag (one line), so XCTesttestFoo()methods and@Testfunctions with free-form names are found.src/codetree/registry.py,pyproject.toml— register.swift, addtree-sitter-swift>=0.7.0.README.md,AGENTS.md,docs/LANDING_PAGE.md,.github/ISSUE_TEMPLATE/bug_report.yml— list Swift.tests/languages/test_swift.py,tests/languages/test_swift_comprehensive.py— 45 tests with fixed fixtures (protocol + extension, generics withwhere,async/await/throws,@Published, SwiftUI view, enums with associated values, nested types, XCTest and Swift Testing throughIndexer.find_tests, graph build with duplicate names).Test plan
pytest— all tests pass (1253 passed)actorand nested-type parents in the formatter,is_testinfind_tests,MARKdocs)funcdeclaration except local nested functions is in the skeleton; protocol/enum/extension counts match a grep;find_testsreturns the Swift Testing tests of a view model. ~3% of files report syntax errors, almost all@available(...)on a#Previewmacro, which the grammar does not parse — skeletons of those files stay complete.Known limitations (not addressed here)
load,body, a staticobjecton every mock type) fan out to every definition — on that repository the graph build dominates startup and the graph is large. This is builder-level and affects every language; worth a separate PR (e.g. cap name-only matches).get_dependency_graphis empty.static func ==) are in the skeleton but get no references.Related issues
None.
🤖 Generated with Claude Code