astrale-sharp / typstfmt

Apache License 2.0
252 stars 25 forks source link

[bug] New indent is added to ignored code block on each run (of formatting) #76

Open Andrew15-5 opened 1 year ago

Andrew15-5 commented 1 year ago
Before formatting ```typ #let template(doc) = { //typstfmt::off show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== doc } #let template(doc) = [ //typstfmt::off #show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== #doc ] #let template(doc) = [ //typstfmt::off #show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== #doc ] ```
After 1st run ```typ #let template(doc) = { //typstfmt::off show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== doc } #let template(doc) = [ //typstfmt::off #show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== #doc ] #let template(doc) = [ //typstfmt::off #show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== #doc ] ```
After 10th run ```typ #let template(doc) = { //typstfmt::off show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== doc } #let template(doc) = [ //typstfmt::off #show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== #doc ] #let template(doc) = [ //typstfmt::off #show figure.where(kind: table): it => align(center)[ #it.body ] //typstfmt::on // END ====================================================================== #doc ] ```

Smaller examples:

#let template(doc) = {
  //typstfmt::off
  let a = ""
  //typstfmt::on
  // END ======================================================================
  doc
}
#let template(doc) = {
  let a = ""
  //typstfmt::off
  //typstfmt::on
  // END ======================================================================
  doc
}

Config:

ident_space = 2
max_line_length = 80
experimental_args_breaking_consecutive = false

Version: https://github.com/astrale-sharp/typstfmt/commit/578d39fb304020d0c26118e4eeab272868c9d525

Andrew15-5 commented 1 year ago

Here, block isn't ignored at all:

#{
  let a = ""

  // typstfmt::off
  ```anylang
  anything

// typstfmt::on }

astrale-sharp commented 1 year ago

wow this skipped my attention, I'll have to take a look, thanks!

astrale-sharp commented 1 year ago

I have an idea of what's going on but it's going to be a pain to fix I suspect

astrale-sharp commented 1 year ago

This is fixed in code blocks but testing would need to be done for content blocks, args (breaking and tight) etc

jeffa5 commented 12 months ago

Related case: https://github.com/astrale-sharp/typstfmt/pull/101

LDemetrios commented 11 months ago

Happens not only in ignored blocks.

/* multiline
    comments */

also do float each typstfmt call, and so do raw blocks

astrale-sharp commented 11 months ago

Happens not only in ignored blocks.

/* multiline
    comments */

also do float each typstfmt call, and so do raw blocks

That's supposed to be fixed, are you using the last version? (not on vscode yet probably)

miliog commented 9 months ago

Any updates on this? This is a major reason why I can't use typstfmt yet.

Andrew15-5 commented 9 months ago

I think ignore code block still doesn't work as intended and to fix this and many other things, a big refactoring needs to be done to make code more maintainable. At least this information was accurate about a month ago.

This is indeed a major feature without which the formatting becomes much less flexible. If I want to put 1 row per line in a table, this feature would make it possible and can increase readability of tables. Right now, formatter puts 1 cell per line. BTW, this could be a new feature where typstfmt would read the number of columns and try to put x amount of args per line (opt-in or opt-out option).

But there are many other cases where ignoring only part of a file would be beneficial.

astrale-sharp commented 9 months ago

Yes I would love to see dev in this area as well, It's quite difficult for me to handle it right now