-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Annotations to ignore sections of code #1704
Comments
Hello Adrián, thank you for showing interest in this project. In practice however, this would haunt me at night at first glance. Next, if the marker part of the process were to be in place, shifting in the original code at the right place might also be challenging. Getting the code from the original file based on an AST range could potentially not work out as you'd expect. I hope you understand my skepticism here. You will most likely be able to come up with something that works for a couple of use-cases, but once this gets canon and people start using it a whole new series of issues would be reported. This is purely because you cannot anticipate the spectrum of AST combinations that people use in their code. Such a large impacting feature request would only fit in the next major release, no time frame is known for that right now. |
Oh, I had no expectation of this being workable anytime soon, I'm aware this is blocked by all the trivia bugs. I even encountered some while preparing the examples for the request. But during discussion related to .fantomasignore I noticed others wish for this feature too, so I decided to make the request official. |
@nojaf is the Dallas rewrite making it in any way more feasible to achieve this feature? |
Hmm, I don't think so. Trivia has become a lot more accurate because of Dallas, so the risk of comments being removed has been improved. The main struggling points I currently see are:
|
Another request: RIDER-93681. |
This is probably a significant feature (with the reverse one, to only format specific sections) that would drive adoption in places where fantomas is not considered. It would also make sense, rather than .fantomasignore, to offer the reverse one, anytime an all or nothing decision is taken; "leave it to the user to pick a side" philosophy, it doesn't make the tool less opinionated. Thanks for having the suggestion open :) If it would make it easier for implementation of a first version, it could behave in a way that only makes it easy to apply, maybe not to inner chunks of code, but for a whole member; it would emit a warning if it can't handle it, inviting user to put the delimiters at a greater scope. |
I propose we support annotations in code to ignore certain sections from formatting. This is helpful for code known to trigger soundness bugs in Fantomas or sections that benefit from unusual formatting.
Looking at other formatters for inspiration, I see different annotations we could use for this:
// prettier-ignore
to exclude the next AST element from formatting. I think this is clever, although it can take more effort to get right.// @formatter:off/on
.#pragma warning disable/restore format
. In F# this could be a directive#format disable/restore
, but it'd raise a warning at compile time unless a language suggestion was made so the compiler recognises it.#if !FANTOMAS ... #endif
.The existing way Fantomas deals with this problem is by ignoring the entire file with .fantomasignore.
Pros and Cons
The advantage of making this adjustment to Fantomas is having an escape hatch for excluding small sections of code, specially to work around soundness bugs.
The disadvantage of making this adjustment to Fantomas is having to scan comments for annotations and track which nodes should be formatted. It could also interfact badly with existing soundness bugs around comments.
Examples
Using Prettier-like annotations and default settings. Before:
After:
The formatting of the syntax elements following
fantomas-ignore
comments has been ignored. Open questions are whether innerlet
/use
are counted as an element or only their binding part and what precedence does it have respect to F# operators.Using Rider-style annotations and default settings. Before:
After:
(Fantomas currently moves
// @formatter:on
to the first column.) The formatting of nodes betweenformatter:off
andformatter:on
comments has been ignored.#format disable/restore
would behave similarly.Extra information
Estimated cost (XS, S, M, L, XL, XXL): M/L, probably depends on which annotation syntax is chosen.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: