grain icon indicating copy to clipboard operation
grain copied to clipboard

Grainfmt: Support `formatter-ignore` in more places

Open phated opened this issue 4 months ago • 0 comments

As per @ospencer at https://github.com/grain-lang/grain/pull/1976#discussion_r1477178775

We currently only support it on statements, so that's either top-level statements or statements within a block. We could open an issue to support it in more places, though it's a little tricky/could give unexpected results in some cases:

func(
  // formatter-ignore
  1+2, 2+3, 3+4
)

formatter-ignore is supposed to apply to the next node rather than the next line, so it could be expensive to check for that. We can't make it apply to all 3 arguments because they're treated as three separate nodes. Formatting once would place them on separate lines, making the formatter-ignore comment no longer apply to the second two nodes, so formatting again would actually format them (which is very bad behavior).

Trying to just cut out that one line is even trickier business since you could easily split across AST nodes. So we'd probably need to do that expensive check instead, but now we've got a super expensive check for every AST node.

It might be possible to not make it horribly expensive, but I'd have to think about it.

phated avatar Feb 19 '24 21:02 phated