smithy-lang / smithy

Smithy is a protocol-agnostic interface definition language and set of tools for generating clients, servers, and documentation for any programming language.
https://smithy.io
Apache License 2.0
1.7k stars 201 forks source link

Fix formatting comments in operation errors list #2283

Closed milesziemer closed 1 month ago

milesziemer commented 1 month ago

Background

For operation errors like:

errors // foo
: // bar
[
    // baz
    MyError
]

you'd expect formatting of:

// foo
// bar
errors: [
    // baz
    MyError
]

Prior to this commit, we were handling the cases of foo and bar, but inadvertently doing the same thing for baz. This is because we were looking for comments to pull out to above errors in the direct children of OPERATION_ERRORS, which include all WS within the [].

To make it work as expected, we need to only pull out comments in the first two positions (foo, bar), and leave the rest for BracketFormatter to format. BracketFormatter was expecting to operate on all the children of a given TreeCursor, so I modified it to act on an arbitrary stream of cursors, and added a way to get all remaining siblings after a cursor.

Testing

Links