Open yamt opened 1 year ago
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
.
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.
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
.
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
I was missing witfmt too and started a toy prototype in https://github.com/bytecodealliance/wasm-tools/commit/fc6a1656c32cdcc609ffce5fc18f4bff6c8c967b
is there rustfmt-like tools for wit files? otherwise, this is a feature request.
moved from: https://github.com/bytecodealliance/wit-bindgen/issues/710