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

Print XML Document comments from AST #1878

Closed
nojaf opened this issue Sep 7, 2021 · 5 comments · Fixed by #2122
Closed

Print XML Document comments from AST #1878

nojaf opened this issue Sep 7, 2021 · 5 comments · Fixed by #2122

Comments

@nojaf
Copy link
Contributor

nojaf commented Sep 7, 2021

Currently, Fantomas is not printing PreXmlDoc (unless in strict mode is active).
Comments are detected as trivia as well so, in order not to print them twice, we don't print PreXmlDoc but print the trivia instead.
This is actually perhaps a bit inefficient as currently, we need to match the trivia with a trivia node.
The PreXmlDoc will always be assigned to the correct node in the tree, so it should be ignored as trivia instead.

Practically, I see an opportunity to capture the ranges of PreXmlDoc in ASTTransformer and eliminate trivia content in Trivia.fs.
CodePrinter would then need an additional change to always print PreXmlDoc.

@nojaf
Copy link
Contributor Author

nojaf commented Sep 7, 2021

Keep in mind that this idea needs to play well with newline trivia.
Something like

type PostalAddress =
    {
      /// The address
      Address: string

      /// The city
      City: string

      /// The zip code
      Zip: string
    }

Would still need to work. Perhaps the PreXmlDoc should also be considered as trivia node candidate in that scenario.

@auduchinok
Copy link
Contributor

XML docs could be integrated into declaration ranges after dotnet/fsharp#11973, would it help Fantomas? Would it make sense to wait until that PR is merged?

@nojaf
Copy link
Contributor Author

nojaf commented Sep 7, 2021

Interesting stuff there, yes is worth the wait for that.

@nojaf
Copy link
Contributor Author

nojaf commented Feb 2, 2022

Be aware that this is valid code:

/// DOC COMMENT
// simple comment
// yet anothet simple or (* multiline *) comment
type A = ...

@nojaf
Copy link
Contributor Author

nojaf commented Feb 11, 2022

I've been playing around with this on a local branch using an FCS that has the recent improvements by @DedSec256.
It works out nicely.

The only catch was when you have a regular code comment underneath an XMLDoc.

/// doc
// no doc
let a () = 0

To resolve that scenario, it was useful to have the let keyword as part of the SynBindingTrivia.

@nojaf nojaf linked a pull request Mar 4, 2022 that will close this issue
@nojaf nojaf closed this as completed Mar 4, 2022
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.

2 participants