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

Swift Next package added. #8843

Merged
merged 6 commits into from
Feb 4, 2024
Merged

Swift Next package added. #8843

merged 6 commits into from
Feb 4, 2024

Conversation

yaroslavyaroslav
Copy link
Contributor

  • I'm the package's author and/or maintainer.
  • I have have read [the docs][1].
  • I have tagged a release with a [semver][2] version number.
  • My package repo has a description and a README describing what it's for and how to use it.
  • My package doesn't add context menu entries. *
  • My package doesn't add key bindings. **
  • Any commands are available via the command palette.
  • Preferences and keybindings (if any) are listed in the menu and the command palette, and open in split view.
  • If my package is a syntax it doesn't also add a color scheme. ***
  • If my package is a syntax it is named after the language it supports (without suffixes like "syntax" or "highlighting").
  • I use [.gitattributes][3] to exclude files from the package: images, test files, sublime-project/workspace.

This is the ST4 sublime-syntax support for Swift. I must clarify that I am not the author of this package. However, I firmly believe in the importance of this release, mainly due to the subpar quality of the currently available alternatives in the package control.

There are a few of them:

I recently discovered this package quite by chance and was actually stunned by the amount of work that the developer had put into it. Unfortunately, the main repo seems to have been neglected for half a year too. So, I merged all the pending PRs from there, created an organization, and relocated the updated repo there. In this way, I was able to invite the author of this package to the organization, granting him the owner rights (still pending) and all the recognition for this outstanding work.

This PR follows two main objectives:

  1. To share this incredible package with people, because believe me, Swift developers are in dire need of it.
  2. To appeal to the broader community to enhance it even more.

Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Packages modified:
  - Swift Next

@yaroslavyaroslav
Copy link
Contributor Author

@braver hey, could you please take a look at this one, when you'd have a chance

repository/s.json Show resolved Hide resolved
Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Packages modified:
  - Swift

@FichteFoll
Copy link
Collaborator

FichteFoll commented Nov 2, 2023

Interesting, I didn't know someone was working on an actually reasonable Swift.sublime-syntax. I only took a very brief look into it, but it's probably worth exploring the package for inclusion into the default Packages. I'll raise this over the next few days in our Discord chat. There are a few things to resolve because apparently a package named "Swift" already exists on PC and I forgot how exactly PC handles that. We might need to rename the original Swift package on PC in that case.

Outside of that, while I generally agree that taking over unmaintained packages is a good course of action, the replacement does not support ST3, so we'd need to consider this in our decision.
Also, the items in Swift.sublime-completions should definitely be snippets since they span multiple lines.

This is not a complete review. I just saw this in my notifications and took a quick look.

@braver
Copy link
Collaborator

braver commented Nov 4, 2023

the replacement does not support ST3, so we'd need to consider this in our decision

You can always incorporate the final commit of the replaced repository in the new repo (just as a dangling commit or branch) and tag that as the “st3-“ version.

@braver
Copy link
Collaborator

braver commented Nov 4, 2023

@FichteFoll assigning to you for now, I’d like to wait for what you come up with before we do anything else. ST deserves a good Swift syntax in the default package.

@FichteFoll
Copy link
Collaborator

FichteFoll commented Nov 4, 2023

I've tested the syntax on a few files I had lying around from 4 years ago and I gotta say it's pretty good. There are a few things that should be adjusted but are not too important because the general experience is there. @yaroslavyaroslav, if you're willing to move this package into the default packages, I'm sure that would be much appreciated. Even more if you're also willing to provide a bit of maintenance in the future as I don't think there are a lot of Swift users among the other contributors (read: probably none).

We would then most likely rename the existing package on PC as a preparation to allow for a smooth-ish transition once we get a sign from Sublime Hq that they are indeed willing to merge the syntax (without necessarily passing the review).


Anyway, here's some quick feedback on the package as it is now. This could also be part of the review discussion for a PR to the default packages, but that doesn't exist currently. Note that this is also on a fairly detailed level and I'd generally not be so critical, but when we're talking about including it in the default packages, I need to be a bit stricter:

  • As I mentioned, the completions file actually contains several snippets. These must be converted to actual snippet files (because snippets are treated differently in ST regarding their usage and how they can be disabled) or removed entirely, because we don't really add (controversial) snippets in default packages anymore.
  • The constant.numeirc scope isn't set on the punctuation of floating point numbers, i.e. 1.0.
  • Always matching default as a keyword seems a bit over-eager. (WCSession.default.delegate = self)
    2023-11-04_13-32-03
  • Not sure how I feel about matching all non-mutable (i.e. let) variables as variable.other.constant. While they are immutable, the scope is usually used for appliction-wide (global) variables and values, not function-local ones. Rust doesn't do this either, for example (instead using that scope for static variables) and JavaScript only applies it too SCREAM_CASED variables.
  • The number in implicit parameters, i.e. delegates.invoke { _ = $0.calibrationChanged(Device.Origin(device, event: event), location: location, thresholds: sensor.thresholds) }, should not be a keyword.operator and constant.numeric because it's a variable. variable.parameter seems appropriate imo.
  • Not sure why these have variable.other (blue) (and only sometimes?).
    switch states {
    case (.off, let foreOut, let foreIn) where foreOut.rawValue > 0 && foreIn.rawValue > 0:
      return .takingOff(.heel)
    case (let heel, .off, let foreIn) where heel.rawValue > 0 && foreIn.rawValue > 0:
      return .takingOff(.foreOut)
    case (let heel, let foreOut, .off) where heel.rawValue > 0 && foreOut.rawValue > 0:
      return .takingOff(.foreIn)
     }

2023-11-04_13-43-04

  • sensors in let foreOut = sensors[Sensor.Location.foreOut.rawValue] is marked as variable.function.
  • Generics are marked as support.generic in usage but only in usage, not in definition (which is unheard of; usually it's variable.parameter.type in definition and support.class in usage).
  init<T>(from value: T) {
    var value = value
    self.init(buffer: UnsafeBufferPointer(start: &value, count: 1))
  }

Finally, as a quick reminder, don't forget to include the license in a PR to the packages repo.

@deathaxe
Copy link
Contributor

deathaxe commented Nov 4, 2023

A clone of this package is sitting around in my Setup for months, but never got time to review it seriously.

It looks promising on a first glance.

Might probably try to make more use of named contexts.

I'd expect proper syntax tests to be present as a least pre-condition to make it a default packages candidate.

@yaroslavyaroslav
Copy link
Contributor Author

I'd expect proper syntax tests to be present as a least pre-condition to make it a default packages candidate.

@deathaxe, just to clarify, does this contradicts with @FichteFoll request to move this PR to default packages repo, or is it nothing more than an additional task to got it approved?

@yaroslavyaroslav
Copy link
Contributor Author

@FichteFoll Yep, I believe I'd capable to manage that, I mean both, to move this PR to a default package and to resolve some bug fixes during the review process.

Although I just like to highlight that language markups isn't somehow related to my main scope of proficiency, so I'd be in my turn greatly appreciated for kind-of-dunno guidance during reviewing process.

@deathaxe
Copy link
Contributor

deathaxe commented Nov 4, 2023

No contradiction. Just another task to be completed in order to add it to ST's default packages. Syntax tests are crucial to verify a certain level of quality and to ensure not to break things by future changes.

With regards to this PR, we in general try not to add multiple packages with nearly the same function. So if this package was to be added here, it should probably replace existing "Swift" syntax. Maybe by restricting the existing one to ST3 and use the new one for ST4.

@yaroslavyaroslav
Copy link
Contributor Author

Syntax tests are crucial to verify a certain level of quality and to ensure not to break things by future changes.

I see a few files in the test dir, is this it or you're talking about something more advanced?

So if this package was to be added here, it should probably replace existing "Swift" syntax. Maybe by restricting the existing one to ST3 and use the new one for ST4.

Isn't these are mutually exclusive options with moving this PR to a default packages repo? And in the case they are, which one is preferred one?

@deathaxe
Copy link
Contributor

deathaxe commented Nov 5, 2023

Sublime Text supports automated syntax tests to make sure each token receives desired scopes. Those tests are run by CI each time changes are pushed upstream.

Example: https://github.com/sublimehq/Packages/blob/master/Java/tests/syntax_test_java.java


Isn't these are mutually exclusive options ...

Sure. Just expessing expectations that solution, just in case.

@yaroslavyaroslav
Copy link
Contributor Author

I believe I have the strength to undertake the test implementation task, although it might take me a considerable amount of time. At best, I don't see it taking less than a few months. So, from my perspective, I'm completely fine not having this package within Package Control for the duration, as long as I can have it locally on my laptop. Is this acceptable to you @FichteFoll, or should we consider initially taking a shortcut by releasing it here with only a few minor bug fixes as it stands now?

As a final question for @deathaxe, I perused the Packages ci/cd config and downloaded syntax_tests. It seems that this binary should run as-is on a Linux system. However, I'm encountering an error when trying to run it on arm (both macOS and the Linux container). Is there a simple way to run it in those environments? It would be quite inconvenient to run the validation pipeline remotely on GitHub otherwise.

@deathaxe
Copy link
Contributor

deathaxe commented Nov 5, 2023

You can run syntax tests directly from within Sublime Text. Just hit ctrl+shift+b to open build system while sublime-syntax file or syntax_test_... file is open and chose "Run Syntax Tests"

@jrappen
Copy link
Contributor

jrappen commented Nov 6, 2023

@aerobounce FYI

Maybe you could comment here on the plans of adding Swift to the default packages? Would you be willing to work on that and/or future support (i.e. updating it yourself or reviewing PRs)?

@FichteFoll
Copy link
Collaborator

So, from my perspective, I'm completely fine not having this package within Package Control for the duration, as long as I can have it locally on my laptop. Is this acceptable to you @FichteFoll, or should we consider initially taking a shortcut by releasing it here with only a few minor bug fixes as it stands now?

I don't really care, but if we intend to only have it on PC temporarily, I also vote against taking over the old Swift package name and go ahead with "Swift Next" or similar, as in the initial proposal. We don't need to disrupt users' workflow more often than necessary.

@yaroslavyaroslav
Copy link
Contributor Author

I don't really care, but if we intend to only have it on PC temporarily

Not sure that I got this one. Whether it about to drop it from a PC version afterwards it would be covered with tests or to replace such package later on, when it'll be ready.

But anyway I have to say that while messing with this package with my own swift project I found few more bugs and pretty sure more to come. So it definitely worth to me to revise it carefully while covering it with tests. So I consider the task of including this package in the default repo as a mid term at its best now yet still achievable with my own efforts.

@FichteFoll
Copy link
Collaborator

FichteFoll commented Nov 16, 2023

I understand. Then I propose the following points of action.

Short-term:

  1. Add this package as "Swift Next" to PC to drive it on some users' machines for some time but without impacting users of the current "Swift" package (even though it is of bad quality).
  2. Rename the current "Swift" package on PC to something like "Swift Legacy" in order to free the name for an eventual addition to the default packages. If the package requires changes for the new name, we will suggest a PR to the repo first and otherwise fork it into the Sublime Text organization to make the changes there and redirect the PC entry to it.

Mid-term:

  1. Add the contents of this package to the default packages under a permissive (e.g. the current) license. This means that it will be available to all users of newer ST builds and that it will see some general maintenance by the various contributors but also that pull requests to it will be reviewed and merged for the forseeable future. Since none of the current collaborators uses Swift regularly, @yaroslavyaroslav will most likely be the main contributer still.
  2. Deprecate the "Swift Next" package on PC and suggest users to use the default Swift package going forward using an update message and by adding it to the README.
  3. Deprecate the "Swift Legacy" package and restrict installation of it to builds that don't have the default Swift syntax.

@braver, @deathaxe, what do you think?

@braver
Copy link
Collaborator

braver commented Nov 19, 2023

Sounds like a plan 👍🏻

@deathaxe
Copy link
Contributor

It's an explicit way, which involves quite some steps and package renames though.

PC4.0 will handle built-in package overrides in sane ways (see: wbond/package_control@3d35ece). They will behave like any other 3rd-party package.

If Swift Next is judged as being quite good already, I wonder if there's a more transparent way for end users to move on. Do we need to retain current Swift package for everyone or would it be good enough to move on as we did with other packages such as Less, Liquid, ...

  1. Fork Swift into SublimeText org
  2. freeze current state for installation in ST2-3
  3. create a branch on top for further development
  4. merge in content of "Swift Next" to it (while maintaining snippets or some other useful parts of current "Swift" package).
  5. Register the fork as "Swift".

This way:

  1. all ST3 users stay on current "Swift" syntax
  2. all ST4 users are automatically updated to new syntax and we can use ST4 syntax features when needed.
  3. once "Swift" has been added to built-in packages, its installation can be restricted to older builds.
  4. we could advice users of newer ST builds to run "Package Control: Revert built-in package".

The downside might be ST4 users not being able to actively choose the old syntax anymore.

@braver
Copy link
Collaborator

braver commented Nov 19, 2023

The downside might be ST4 users not being able to actively choose the old syntax anymore.

Not easily via package control perhaps, but users can always be pointed to a commit of a given repo that can be installed manually. I've handled breaking changes in packages that way before, it's fine.

@FichteFoll
Copy link
Collaborator

We could also do what @deathaxe proposed. I won't really have time for managing any of this for the next 1.5 weeks at least, but that's probably not much of a problem since you should have the necessary permissions as well.

It's good to know that PC 4.0 will have some code for handling a situation like this and it's not like ST4 users would lose out on many of the improvements done to Swift in the default package since it'd be basically overriding itself. From a user perspective, I presume this to be way with the least effort required to get the latest Swift syntax definition available to you.

This reverts commit 7821389.
Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Packages modified:
  - Swift Next

@yaroslavyaroslav
Copy link
Contributor Author

yaroslavyaroslav commented Jan 23, 2024

@FichteFoll

Well it took a while, but here we are. I've fixed not all but most of issues provided in your feedback.

  • As I mentioned, the completions file actually contains several snippets. These must be converted to actual snippet files (because snippets are treated differently in ST regarding their usage and how they can be disabled) or removed entirely, because we don't really add (controversial) snippets in default packages anymore.
  • The constant.numeirc scope isn't set on the punctuation of floating point numbers, i.e. 1.0.

defining decimal point as a separate punctuation sign. I do see that it presented unhighlighted towards the rest of a number, but I do see that this was an intent of the author as well. So I decided to made it nested (i.e. constant.numeric.value.swift punctuation.separator.decimal.swift) which still breaks syntax highlight though. Therefore fell free to force drop punctuation definition it if you think it'd be better, I'll be happy to apply. I just preferred to stay cautious to not break what's working.

  • Always matching default as a keyword seems a bit over-eager.
  • Not sure how I feel about matching all non-mutable (i.e. let) ...
  • The number in implicit parameters, i.e. delegates.invoke { _ = $0.calibrationChanged(Device.Origin(device, event: event), location: location, thresholds: sensor.thresholds) }, should not be a keyword.operator and constant.numeric because it's a variable. variable.parameter seems appropriate imo.

= $0 the 0 is still constant.numeric.value.swift as it's actually what it is. It is a constant though it's not always a numeric one. Again feel free to force it, if you know what you're doing, coz I'm not.

  • Not sure why these have variable.other (blue) (and only sometimes?).
  • sensors in let foreOut = sensors[Sensor.Location.foreOut.rawValue] is marked as variable.function.
  • Generics are marked as support.generic

As you can notice I've skipped sensor and using variable.other.constant for let and other constants issues. This is because as I can see there's a plenty amount of effort required to fix these. More than that I would have need to put some extra mile here as I still quite lame in all this syntax definition stuff.

Just to clarify the last one, it doesn't mean that I refuse to fix it completely, but it is mean that I won't do it anytime soon.

in addition to that I reverted the renaming commit in here, so the Package is called Swift-Next yet again.

PS: Just to clarify things up: the main plan for now is to release this boi as a stand alone package.

UPD: changes haven't been merged in master and tagged yet, I'm planning to make it happen when I get an approval here.

@jrappen
Copy link
Contributor

jrappen commented Jan 24, 2024

It works the other way around, you need to update your package including tags and everything for an approval here and before this merge will happen.

@yaroslavyaroslav
Copy link
Contributor Author

you need to update your package including tags and everything for an approval here

Np, main updated with 1.0.2 release tag.

@yaroslavyaroslav
Copy link
Contributor Author

@FichteFoll @braver
It's not that I'm rushing you in any way, just checking if there's anything left on me here or should I just relax and keep waiting when the magic happens?

repository/s.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Packages modified:
  - Swift Next

Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Packages removed:
  - Swift

Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Repo link: Swift Next

Packages added:
  - Swift Next

Processing package "Swift Next"
  - All checks passed

@braver
Copy link
Collaborator

braver commented Feb 4, 2024

Alright, let's get this package out there!

@deathaxe @FichteFoll we can do an iteration later, where we do basically what @deathaxe suggested. For now, let this new package prove itself in the wild for a bit, there is no rush.

@braver braver merged commit c51ae37 into wbond:master Feb 4, 2024
2 checks passed
@FichteFoll
Copy link
Collaborator

It's not that I'm rushing you in any way, just checking if there's anything left on me here or should I just relax and keep waiting when the magic happens?

I saw your reply but was just busy with other stuff over the past weeks. Reviewing a package (and especially a huge syntax definition) takes some time, even when you're just iterating over stuff you had previously seen, and I want to give it the attention it deserves instead of doing a rushed analysis, if you could even call it that.

That said, we were in agreement over how to handle this package going forward (get it onto PC first, think about making it a default package later) and the first step was just completed, so let's see how the package fares in the near future. I personally do not have any interest in working with Swift any time soon, so I don't have much interest in a hands-on review, but I'm confident we'll eventually manage something when it comes to aligning it more with the default packages eventually, which is an ongoing process even for the syntaxes that we already have.


So I decided to made it nested (i.e. constant.numeric.value.swift punctuation.separator.decimal.swift) which still breaks syntax highlight though. Therefore fell free to force drop punctuation definition it if you think it'd be better,

No, it's quite alright. This is what you should be doing.

As for the rest, they are too minor to discuss them in detail here. I'll just add a refence to this package in the latest Swift issue/PR on the default packages and move on for a while until we get back to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants