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

XML docs for commented code automatically removed #2186

Closed
3 tasks
sergey-tihon opened this issue Apr 3, 2022 · 7 comments · Fixed by #2240
Closed
3 tasks

XML docs for commented code automatically removed #2186

sergey-tihon opened this issue Apr 3, 2022 · 7 comments · Fixed by #2240

Comments

@sergey-tihon
Copy link
Member

Issue created from fantomas-online

Code

/// <summary>
/// Some comment
/// </summary>
// type TestUnion = First | Second of int | Third of string

Result

// type TestUnion = First | Second of int | Third of string

Problem description

Ideally Fantomas should not remove comments during formatting

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 2022-04-01T14:31:49Z - b6828ff

    { config with
                SpaceBeforeLowercaseInvocation = false }

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@nojaf
Copy link
Contributor

nojaf commented Apr 4, 2022

Hey Sergey, this is a tricky one.
The XML doc is not attached to any (or any correct) node, so the behaviour is what I expected it to be.
Perhaps Fantomas should not touch this file in the first place as the syntax tree is empty.
Or course, adding another let binding to the file will trigger the same problem.
The AST is already giving out a warning as well.
Changing your XML doc to double slashes seems like the right thing to do here.
But I understand that answer isn't very satisfying.

@sergey-tihon
Copy link
Member Author

It was in the middle of the large file - fsprojects/FsUnit@e60510c#diff-badc17ff44c87f5563ad36766e8d42f4dfdb140433e680a9d82c439136af9066L28-L33

I think that it would ok to produce warning in console and skip file from formatting (if it is possible)
But I am not sure if it possible to detect it

@auduchinok
Copy link
Contributor

auduchinok commented Apr 4, 2022

Changing your XML doc to double slashes seems like the right thing to do here.

It doesn't sound like a thing that a formatter should do to me, to be honest. Could Fantomas just print them as is, maybe?

@nojaf
Copy link
Contributor

nojaf commented Apr 4, 2022

We don't plan to detect them anymore like we used to do. They are part of the untyped tree unless placed in the wrong location, and then we just don't know about them. There is no "print them as is", we don't know about them in the first place.

If you commented out the type, you should have taken the triple slashes into account as well while doing it.

@auduchinok
Copy link
Contributor

They are part of the untyped tree unless placed in the wrong location, and then we just don't know about them.

We could add the wrongly placed comments to that collection too, perhaps? :)

@nojaf
Copy link
Contributor

nojaf commented Apr 4, 2022

Maybe, if we can push the information of

https://github.com/dotnet/fsharp/blob/6f1a77804b390c2a6e81f7ec56628075c1b95af1/src/fsharp/ParseHelpers.fs#L143-L145

to the LexbufCommentStore that could work.

@DedSec256 any ideas?

@DedSec256
Copy link
Contributor

Maybe, if we can push the information of
https://github.com/dotnet/fsharp/blob/6f1a77804b390c2a6e81f7ec56628075c1b95af1/src/fsharp/ParseHelpers.fs#L143-L145
to the LexbufCommentStore that could work.

Yes, this seems like a good solution to the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants