Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Swift Grammar and Queries #10802

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

levitatingpineapple
Copy link

@levitatingpineapple levitatingpineapple commented May 21, 2024

This PR includes various improvements for swift language.

  1. Adds swiftinterface to recognised file types as discussed in Support .swiftinterface files #10763
  2. Updates tree-sitter-swift to 0.5.0. The corresponding highlight queries have been updated using 0.4.0...0.5.0 diff
  3. Configures apple/swift-format as the formatter since it's the one used in the LSP code suggestions1
  4. Adds an inject query for the compile time regex literal. 2
Screenshot 2024-05-21 at 23 09 57
  1. Adds basic textobject queries for type, function, comment and argument.
    I tried to keep them similar to rust/textobjects.scm
demo.mp4

Footnotes

  1. When formatter is invoked using a file path,
    it recursively looks for ".swift-formatter" configuration file in the parent directories.
    Since helix uses STDIN swift-format won't know where to look for the configuration.
    This is why --configuration .swift-format argument is used explicitly.
    To enable the formatter for a package: swift-format dump-configuration > $PACKAGE_ROOT/.swift-format

  2. Even though slash regex literals have been available since swift 5.7,
    they still need to be manually enabled for the target: swiftSettings: [.unsafeFlags(["-enable-bare-slash-regex"])]

@the-mikedavis the-mikedavis added the A-language-support Area: Support for programming/text languages label Jun 3, 2024
@WuerfelDev
Copy link
Contributor

WuerfelDev commented Jun 5, 2024

Regarding your comment at [1] about swift-format:

Therefore a --configuration flag isn't needed once we get a new release (it would even block the other options from loading). FYI

@the-mikedavis the-mikedavis merged commit aa1630a into helix-editor:master Jun 7, 2024
6 checks passed
@levitatingpineapple
Copy link
Author

That's great to hear @WuerfelDev!
I am subscribed to https://github.com/apple/swift-format/releases.atom feed,
so I can remove the option once the new version is available. :)

Could you elaborate on:

it would even block the other options from loading

Do you mean the global config?

@WuerfelDev
Copy link
Contributor

That's great to hear @WuerfelDev! I am subscribed to https://github.com/apple/swift-format/releases.atom feed, so I can remove the option once the new version is available. :)

Could you elaborate on:

it would even block the other options from loading

Do you mean the global config?

A invalid configuration file will return nil therefore not continuing to look for other configuration locations (neither cwd nor global).
It is a defined behavior as per this comment:
https://github.com/apple/swift-format/blob/4f19acc9acd4ff7bfe54ff58d32b5f1c3855a4a9/Sources/swift-format/Frontend/Frontend.swift#L190-L191

AOx0 pushed a commit to AOx0/helix that referenced this pull request Jun 15, 2024
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
@tarikkirgin
Copy link

As a casual user I just wanted formatting to work on .swift files without having a .swift-format file. Felt quite unintuitive to have to delve into languages.toml to remove the --configuration flag as it is there by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants