Stream: general

Topic: WIT formatter out now!


view this post on Zulip Mikhail Katychev (Apr 04 2025 at 19:48):

Hi all, my WIT formatter just got merged into topiary main!

This formatter can handle newer stuff like async and feature gates!
https://github.com/tweag/topiary/blob/main/topiary-cli/tests/samples/input/wit.wit#L162-L184

Install:

cargo install --git https://github.com/tweag/topiary --no-default-features topiary-cli --features=wit

Usage

topiary fmt path/to/my_file.wit!
for stdin:
cat input.wit | topiary fmt --language wit

P.S.

A lot of these changes were based off of work on my fork of tree-sitter-wit https://github.com/mkatychev/tree-sitter-wit/tree/rc-1.
If your code editor supports tree-sitter, you can get the new syntax highlighting as well!
image.png

Contribute to tweag/topiary development by creating an account on GitHub.
Tree Sitter grammar for Web Assembly Interface Types - GitHub - mkatychev/tree-sitter-wit at rc-1

view this post on Zulip Victor Adossi (Apr 06 2025 at 04:43):

Hey this is awesome! :)

How would someone use this/get started using topiary? Is there an easy Emacs onboarding path? Neovim? VSCode, etc? Seems like it should be run as a binary alongside other tooling?

view this post on Zulip Mikhail Katychev (Apr 06 2025 at 17:22):

Hey Victor, I'm not sure about VSCode as I don't use it but for neovim I set an Autocmd (I'm sure emacs has an equivalent) to do a file format on save

view this post on Zulip Mikhail Katychev (Apr 08 2025 at 15:23):

Here's my use of topiary for WIT in neovim:

local autocmd = vim.api.nvim_create_autocmd
autocmd("BufWritePre", {
    pattern = { "*.wit" },
    callback = function()
        local fmt_cmd_table = {
            ["wit"] = "topiary format --language wit",
        }
        format_buf(fmt_cmd_table[vim.bo.filetype])
    end,
})

I've omitted other languages but the pattern should be the same for vimscript or emacs


Last updated: Apr 08 2025 at 23:03 UTC