Skip to content

Conversation

@mkatychev
Copy link
Member

@mkatychev mkatychev commented Oct 15, 2025

Handle inline comments and trailing commas in WIT

Description

This PR handles trailing commas for newline delimited sections and inline comments for WIT

Checklist

Checklist before merging, wherever relevant:

  • CHANGELOG.md updated
  • Documentation (The Topiary Book, README.md, etc.) up-to-date
  • Updated regression tests

@mkatychev
Copy link
Member Author

getting some strange logic for newline separations, @Xophmeister any thoughts?

thread 'test_fmt::fmt_input_wit' panicked at topiary-core/src/test_utils.rs:6:9:

...
  2 // Packages and Comments
  3 // ==================

  4 // WIT grammar for tree-sitter
  5 //// WIT grammar for tree-sitter
...
 16 package wasmi:io:hello;
 17 package wasmi:io:hello/[email protected];
 18
 19 /// `stream` (no _s_) is a *type* that
 20 /// - can include a `<T>`
...
 62     import a: func();
 63 }
 64
 65 world world-two {
 66     import a: func();
...
186 // Gates
187 // ==================

188 @since(version = 0.1.0)
189 world imports {
...

@mkatychev mkatychev marked this pull request as ready for review October 15, 2025 21:45
@mkatychev mkatychev marked this pull request as draft October 16, 2025 18:12
@Xophmeister
Copy link
Member

getting some strange logic for newline separations, @Xophmeister any thoughts?

The preserved blank line on L4 makes sense. You have the blank in the input and you have @allow_blank_line_before on (line_comment) nodes. (The same thing happens with the Gates section at the end: the blank on L180 is preserved.)

On L20-21 in the input (L18-19 in the output): you have a (package_decl) followed by a (line_comment), but no blank in the input...which I think makes sense given this rule:

(
  [
    (export_item)
    (func_item)
    (import_item)
    (include_item)
    (interface_item)
    (package_decl)
    (resource_item)
    (type_item)
    (resource_method)
    (since_gate)
    (deprecated_gate)
    (unstable_gate)
  ] @append_spaced_softline
  .
  [
    (block_comment)
    (line_comment)
  ]* @do_nothing
)

I guess those world world-one and world world-two on L65-66 in the input are ultimately using this rule:

(body
  .
  "{" @append_hardline @append_indent_start @prepend_space
  _
  "}" @append_hardline @prepend_hardline @prepend_indent_end
  .
) @append_hardline

I'm pretty sure the two @append_hardlines -- after } and at the end of the (body) -- will get merged together, so you lose the blank between functions.

@mkatychev
Copy link
Member Author

mkatychev commented Oct 28, 2025

@Xophmeister I've addressed all the issues (thanks to your feedback!) except for the world one & two (tried every which way, something else is conflicting) but I don't want to hold up the release, this can be fixed afterwards (the double newline separation after (_ (body))).

@mkatychev mkatychev marked this pull request as ready for review October 28, 2025 22:58
@mkatychev mkatychev requested a review from Xophmeister October 29, 2025 05:48
Copy link
Member

@Xophmeister Xophmeister left a comment

Choose a reason for hiding this comment

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

LGTM 💯

@mkatychev mkatychev merged commit 3cc4a5d into main Oct 29, 2025
11 checks passed
@mkatychev mkatychev deleted the fix/wit-inline-comment branch October 29, 2025 15:55
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.

3 participants