Skip to content
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

Trivia not restored after long identifier in SynField #2103

Closed
3 tasks
pbiggar opened this issue Feb 17, 2022 · 2 comments
Closed
3 tasks

Trivia not restored after long identifier in SynField #2103

pbiggar opened this issue Feb 17, 2022 · 2 comments

Comments

@pbiggar
Copy link
Contributor

pbiggar commented Feb 17, 2022

Issue created from fantomas-online

Code

type X = 
  | A of int // This comment survives
  | B of C.D // This comment disappears!

Result

type X =
    | A of int // This comment survives
    | B of C.D

Problem description

The comment labelled "This comment disappears" disappears! I played around a bit and it seems that the key thing is the variant type to be in the form A.B.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas master branch at 1/1/1990

Default Fantomas configuration

@nojaf
Copy link
Contributor

nojaf commented Feb 18, 2022

Hey Paul, thanks for raising this issue.
This is again another subtle trivia bug I'm afraid.

The comment that disappears is linked to the D Ident:

image

and it is not being handled in CodePrinter:

| TLongIdent s ->
ifElseCtx
(fun ctx ->
not ctx.Config.StrictMode
&& astContext.IsCStylePattern)
(!-(if s = "unit" then "void" else s))
(!-s)
|> genTriviaFor Ident_ current.Range

Because the TLongIdent active pattern does not keep track of the range an individual Ident, it just returns the combined string.

let (|TLongIdent|_|) =
function
| SynType.LongIdent (LongIdentWithDots s) -> Some s
| _ -> None

Are you interested in submitting a PR for this one?

@pbiggar
Copy link
Contributor Author

pbiggar commented Feb 18, 2022

Are you interested in submitting a PR for this one?

Alas a busy time for me. If it's still here in a few months I might give it a go.

@nojaf nojaf changed the title Variants with Modules lose comments Trivia not restored after long identifier in SynField Jun 7, 2022
@nojaf nojaf added good first issue Long hanging fruit: easy issue to get your feet wet! and removed good first issue Long hanging fruit: easy issue to get your feet wet! labels Jun 27, 2022
@nojaf nojaf closed this as completed Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants