Skip to content

Conversation

@mkatychev
Copy link
Member

@mkatychev mkatychev commented Oct 15, 2025

Handle inline comments and trailing commas in WIT

Resolves #XXX
References #YYY
Depends on #ZZZ

Description

[PR Description]

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.

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.

2 participants