Skip to content

feat: Add swift support - #3300

Draft
rinOfTheStars wants to merge 24 commits into
cursorless-dev:mainfrom
rinOfTheStars:swift-support
Draft

feat: Add swift support#3300
rinOfTheStars wants to merge 24 commits into
cursorless-dev:mainfrom
rinOfTheStars:swift-support

Conversation

@rinOfTheStars

Copy link
Copy Markdown
Contributor

Very much a work in progress right now. The three things that need to be done before this is ready are finishing filling out the list of unsupported facets, getting the test fixtures at resources/fixtures/scopes/swift/branch.if.else.scope, resources/fixtures/scopes/swift/branch.if.scope, and resources/fixtures/scopes/swift/condition.if.scope to generate properly, and figuring out the language plugin situation for VSCode testing specifically. Apparently, Swift shares the problem gdscript has where the language support extension only runs in a particular environment, so it's going to need the bare-bones language support extension trick as well. I've created a draft for such a thing already and it seems to work fine; should that be put in its own repository and uploaded to the VSCode and OpenVSC marketplaces, or should it live as part of the monorepo?

@rinOfTheStars

Copy link
Copy Markdown
Contributor Author

There's also currently a TODO here; as I'm not sure as to which scope facets should be used there

@AndreasArvidsson

Copy link
Copy Markdown
Member

This is a for each loop. A for loop refers to the c-style for loops with an incrementing integer.

for val in sequence {}

@rinOfTheStars

Copy link
Copy Markdown
Contributor Author

This is a for each loop. A for loop refers to the c-style for loops with an incrementing integer.

for val in sequence {}

That's what I thought, thanks—I just wanted to make sure. I'll remove the TODO and mark the c-style for as notApplicable when I have time later.

@rinOfTheStars

rinOfTheStars commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

As far as I can tell, I'm not doing anything too incorrectly when defining the if-else scopes in swift.scm; despite this, the tests for some of the scope facets still fail to generate. I even went and added the for-each loop scope facets in much the same way just to check, and those generated fine! Gonna link to this in the Slack in case someone else can either figure out what I'm doing wrong, or get it to generate on their machine despite it failing to generate here.

@AndreasArvidsson

Copy link
Copy Markdown
Member

You can use the parse tree command from cursorless-talon-dev to have a look at the parse tree for the tests that are failing and try to figure out why you don't get a match.

parse tree <user.cursorless_target>:
user.cursorless_command("private.showParseTree", cursorless_target)

Also I would like you to have a look at how the scope tests are formatted for other languages as well as our format guide. Right now you don't use the standard names or formatting.
https://github.com/cursorless-dev/cursorless/blob/c090b01794609e96c1650b68152a3f41f67661bb/packages/app-web-docs/src/docs/contributing/scope-test-format.md

Also all the recorded tests are not necessary. I don't really know what's up with the folder names, but we only need scope tests when you add a language. The recorded test are either for actions modifiers or just legacy language before we had the scope tests.

@rinOfTheStars

rinOfTheStars commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

You can use the parse tree command from cursorless-talon-dev to have a look at the parse tree for the tests that are failing and try to figure out why you don't get a match.

parse tree <user.cursorless_target>:
user.cursorless_command("private.showParseTree", cursorless_target)

It wasn't that the tests were failing in of themselves, but failing to generate in the first place. I was able to figure out what was going on there and got it working as of the most recent commit.

Also I would like you to have a look at how the scope tests are formatted for other languages as well as our format guide. Right now you don't use the standard names or formatting. https://github.com/cursorless-dev/cursorless/blob/c090b01794609e96c1650b68152a3f41f67661bb/packages/app-web-docs/src/docs/contributing/scope-test-format.md

I didn't realize there was a style guide for those, sorry! It's quite late here so I'll fix those tomorrow.

Also all the recorded tests are not necessary. I don't really know what's up with the folder names, but we only need scope tests when you add a language. The recorded test are either for actions modifiers or just legacy language before we had the scope tests.

I have no clue what's up with those either, they're very much not intentionally added and I pretty quickly realized they weren't supposed to be there and stopped including them in commits. I'll go through and remove those manually tomorrow as well. Very good chance they're generating due to something weird in my personal setup, but if other people (on macOS or more generally) start seeing similar behavior when adding scopes to languages/adding new languages to Cursorless, it might be worth investigating separately.

…cope support, redo scope tests to better fit style guide
two todos (lowercase ones) are questions, while the one that is upercase is a 'proper; todo
@rinOfTheStars

rinOfTheStars commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Just realized five minutes after committing that the ancestor checker predicate is overkill for the purpose I created it for, and that the single-parent check would've worked fine. I'll switch that the next time I have time and capacity to work on this, then, which might not be for a week or so.

Lmk if I should also remove the new predicate outright or if it should stay in, since I'm not quite sure if it's possible for someone to make a language feature where it would be necessary?

@AndreasArvidsson

Copy link
Copy Markdown
Member

We can always add the predicate if it's needed. For now please remove any unused code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling attention to this todo, since the description in scopeSupportFacetInfos.ts isn't clear

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its for static blocks. Please call out if any descriptions are unclear and I will fix it.

"type.iteration.interface": supported,

// per-block iteration -- todo: do classlikes, functions, protocols, branches, etc. count as blocks?
// per-block iteration -- todo: do classlikes, functions, protocols, etc. count as blocks? Or are only if states/branches/loops/etc. included here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this distinction actually matters on the implementation side, but I thought I would ask anyway

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ignore the git diff; the newest version of it is the more correct one)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's the iteration scope for statements: all code blocks that can have statements in them is applicable.

@github-actions github-actions Bot added the lines/1000+ Pull request changes at least 1,000 lines label Sep 6, 2026
seems like there might also be a regression in the engine somewhere but I'm not sure if that's the case or not; mostly making this commit to save my work before checking for that
…roken (potentially an issue with tree-sitter-swift?)

this is the source of what I thought might be an engine issue in the previous commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lines/1000+ Pull request changes at least 1,000 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants