wasm-tools icon indicating copy to clipboard operation
wasm-tools copied to clipboard

reformat wit files

Open yamt opened this issue 9 months ago • 4 comments

is there rustfmt-like tools for wit files? otherwise, this is a feature request.

moved from: https://github.com/bytecodealliance/wit-bindgen/issues/710

yamt avatar Nov 15 '23 07:11 yamt

while wasm-tools component wit can perform wit-to-wit conversion, it doesn't seem to work for complex cases like multi-file definitions with use.

yamt avatar Nov 15 '23 07:11 yamt

As a temporary solution, you can try Intellij WIT, even the community version can use this plugin.

It supports formatting the selected area, or the entire file, or the wit files in the entire directory.

And support using .editorconfig to control indentation.

This is a pure lexer-level formatter that does not check whether the symbol exists, and supports experimental features such as nested namespace.

oovm avatar May 15 '24 12:05 oovm

The current formatter is written in pure kotlin.

In the long term, I may switch to a rust native implementation via the document/formatter protocol in lsp.

If you want to develop a native formatter, wit-parser should support prefix-tokens and postfix-tokens, like COMMENT_LINE, COMMENT_BLOCK, WHITE_SPACE, NEW_LINE.

oovm avatar May 15 '24 12:05 oovm

Nice @oovm! FWIW the Rust lexer lives here but isn't exposed at the crate root just yet. I don't think it'd be a problem exposing that from the wit-parser crate if you'd find that useful. I've not written many lexers for IDEs though so it may be too strict, but I think it'd be fine to change it to suit your use case as well too

alexcrichton avatar May 15 '24 15:05 alexcrichton