typstfmt icon indicating copy to clipboard operation
typstfmt copied to clipboard

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

Open Andrew15-5 opened this issue 2 years ago • 10 comments

Before formatting
#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
#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
#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 avatar Aug 26 '23 17:08 Andrew15-5

Here, block isn't ignored at all:

#{
  let a = ""

  // typstfmt::off
  ```anylang
  anything
  ```
  // typstfmt::on
}

Andrew15-5 avatar Aug 26 '23 19:08 Andrew15-5

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

astrale-sharp avatar Aug 27 '23 12:08 astrale-sharp

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

astrale-sharp avatar Aug 30 '23 07:08 astrale-sharp

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

astrale-sharp avatar Sep 06 '23 19:09 astrale-sharp

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

jeffa5 avatar Sep 21 '23 17:09 jeffa5

Happens not only in ignored blocks.

/* multiline
    comments */

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

LDemetrios avatar Oct 07 '23 21:10 LDemetrios

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)

astrale-sharp avatar Oct 09 '23 16:10 astrale-sharp

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

miliog avatar Nov 24 '23 14:11 miliog

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.

Andrew15-5 avatar Nov 24 '23 14:11 Andrew15-5

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

astrale-sharp avatar Nov 25 '23 09:11 astrale-sharp