Open Niols opened 1 year ago
In the stand-up meeting of today we mentioned the idea to have topiary
be able to take several --input-file
and that would then write everything in the one output file (potentially stdout), concatenating things. However, this would be maybe a bit counter intuitive but it would also behave very badly with a potential future multi-threaded version of Topiary.
Somehow, this reminds me of sed -i
that accepts an extension for backing-up files. Typically, one could write sed -i.bak ...
to get files to be copied into *.bak
files before applying formatting. I am not sure it would make sense for Topiary, though, but I thought I'd throw it in the mix.
As another random idea, if we really wanted to be able to have --input-file
and --output-file
work with several files at once, we could allow alternating them:
topiary -f file1.ml -o file1-fmt.ml -f file2.ml -o file2-fmt.ml ...
or maybe have --output-file
able to take a pattern or something, like:
topiary -f file1.ml -f file2.ml -o '{}-fmt.ml'
but I am really not convinced by this. Again, just throwing them in here.
I think it's time to think about subcommands.
There could be a subcommand topiary format
which takes a list of files and format them in place. This is the “standard” behaviour of a formatter. This can be multithread, or single thread. But could share compiled queries.
Then we could have topiary dev
(not sure it's the best name), with the current interface. Because things like --visualise
or the playground.sh
script don't necessarily make sense in the multi-file setting.
Would this avoid the complications?
Describe the bug
This issue is unrelated to #519. Topiary takes about half a second to format OCaml files, even trivial ones. This is reasonable when formatting one file but it becomes very frustrating when formatting a whole code base.
To Reproduce
For instance, on a relatively small codebase, with the latest version compiled in release mode:
Expected behavior
I would expect Topiary to be reasonably fast to format a whole code base (maybe a few seconds). This could be achieved either by having Topiary be very fast (probably under 100 ms) on separate files or by having Topiary able to process several files at once.
Environment
Additional context
The situation has already been improved a bit by https://github.com/tweag/topiary/pull/523 and its 40% speedup. However, one would need a much more drastic speedup per run to achieve something nicer.
If this helps, I'd imagine a command line interface of:
(or
-i
for short) handling at least one file (and failing if none were passed), or:(or
-f
and-o
for short) handling exactly one file and defaulting to stdin and stdout without any flags.Such an interface would also make for a much easier use in
find
/xargs
and inpre-commit
or similar utilities that expect formatters to handle several files at once.