smithy-lang / smithy-language-server

A Language Server Protocol implementation for the Smithy IDL
https://smithy.io
Apache License 2.0
33 stars 19 forks source link

Formatting Smithy document #89

Closed daddykotex closed 1 year ago

daddykotex commented 1 year ago

Recently, we made great progress on our Smithy parser. We were able to build a formatter to go along with it. This PR adds formatting capability to the language server implementation. Formatting happens when the client requests it. For example in VS Code:

  1. explicitly ask to format a file
  2. configure format on save - editor calls format before calling save

Here is a small demo:

https://user-images.githubusercontent.com/5230460/222233725-493e8b45-bb30-485c-84de-9e45ebac9ba1.mov

srchase commented 1 year ago

I got a chance to wire this into the Smithy for VS Code extension, and it's great!

Is it possible to tweak to the underlying formatter?

I noticed that trailing commas are added when 3 or more mixins are split into separate lines:

This:

structure UsesMixin with [MyMixin, MixinTwo, MixinThree] {
    foo: String
}

Gets reformatted to this:

structure UsesMixin with [
    MyMixin,
    MixinTwo,
    MixinThree
] {
    foo: String
}

Could those trailing commas get dropped? For comparison, when errors on an operation are broken into separate lines, trailing commas are not added there.

daddykotex commented 1 year ago

Is it possible to tweak to the underlying formatter? Definitely, right now this means, changing the formatter implementation, then updating the version here. I'll do it.

If this gets merged, I'd like to take some time to work on a configuration that could be used to tweak the formatter version, and, maybe, specify the version so we don't have to update the language server everytime the formatter gets an update.

srchase commented 1 year ago

If this gets merged, I'd like to take some time to work on a configuration that could be used to tweak the formatter version, and, maybe, specify the version so we don't have to update the language server everytime the formatter gets an update.

Making this configurable makes sense. I'll merge this now, and will bump the formatter after https://github.com/disneystreaming/smithy-translate/pull/102 is merged before we cut a release of the language server.

daddykotex commented 1 year ago

Thanks, @srchase this is amazing