typstyle icon indicating copy to clipboard operation
typstyle copied to clipboard

Range rewrite

Open Enter-tainer opened this issue 1 year ago • 4 comments

Add an optional arg to current interface to perform certain action on source code ranges.

fn pretty_print(content: &str, width: usize, actions: Vec<(start, end, RewriteAction)>)

, where action is an enum defined in typstyle. It can be ToMultiline, ToSingleLine, ToBlockEquation, ToInlineEquation, NoFormat...

typstyle will find the first ast node(in order traversal) which is contained by the provided range.

When certain action is not applicable, it will be sliently ignored

Enter-tainer avatar Apr 06 '24 13:04 Enter-tainer

a builder/worker style may be more flexible, like std::process::Command.

Myriad-Dreamin avatar Apr 06 '24 23:04 Myriad-Dreamin

a builder/worker style may be more flexible, like std::process::Command.

Do you mean a PrettyPrinterBuilder? It's Ok for me. Like

PrettyPrinterBuilder::new()
  .with_column_width(..)
  .with_content(...)
  .with_actions(...)
  .format()

Enter-tainer avatar Apr 07 '24 04:04 Enter-tainer

It could be less flexible:

PrettyPrinterBuilder::new(column_width or config)
  .with_actions(...)
  .format(content)

Myriad-Dreamin avatar Apr 07 '24 04:04 Myriad-Dreamin

Looks similar to the nixfmt or ra-fmt declarative DSL style. Works very well with CST interfaces like Typst has.

https://www.github.com/rust-lang/rust-analyzer/pull/1678 https://github.com/nix-community/nixpkgs-fmt/

https://www.github.com/rust-lang/rust-analyzer/issues/1665

RossSmyth avatar Feb 10 '25 15:02 RossSmyth