Replies: 2 comments
-
My first instinct is to say no. As you said, Let me chew it over a bit, though. I can see the value. |
Beta Was this translation helpful? Give feedback.
-
@brianmcgee and I talked about this a while back. Right now treefmt operates on the file boundary. It has an advantage of simplicity (most formatters already support our interface). And also speed, as we don't need to read the files to map them to the right formatter. This makes treefmt good for wide industry support, but also limits what it can do. One aspect that's tricky when dealing with partial buffers is that spawning sub-processes has a cost. Imagine HTML files with CSS, JavaScript and embedded SVGs. There is also the issue that there is no widely-accepted interface to handle partial formats. So then you start thinking of keeping the formatters around and interacting with them over a RPC or maybe even embedding a tree-sitter engine (eg: https://github.com/tweag/topiary does the latter). What could be interesting is to take a look at LSPs and see if there is another elegant inteface that could exist there. |
Beta Was this translation helpful? Give feedback.
-
I feel bad for asking this, as
treefmt
currently has a very nice, tight scope. I do think it's an area where treefmt could really provide some value, though.Oftentimes, we end up embedding one language in another (
python
innix
,bash
inmarkdown
, etc). Tree-sitter calls these injections.One could imagine a version of treefmt that parses files with tree-sitter, and invokes formatters for each injected language block it discovers.
conform.nvim
is a neovim plugin that does exactly this (see Injected language formatting (code blocks)), but that only is useful for neovim users with the right config, and can't be enforced in CI.I don't know how Tree-sitter or
conform.nvim
handles situations where the injected language isn't actually valid code for that language. For example, imagine this nix code:@brianmcgee, @zimbatm, I'm curious how you feel about this. Does this seem like an interesting thing for us to do someday?
Beta Was this translation helpful? Give feedback.
All reactions