-
Notifications
You must be signed in to change notification settings - Fork 789
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
Redesign XmlDoc collecting mechanism #11973
Conversation
Yes this is all reasonable.
I'm not particularly concerned to support this case - omitting the first
What if the declaration doesn't have attributes? I think I've authored types where the attributes come first |
We want to have it properly marked in tree anyway, so the tooling is able to analyze it correctly. |
Got it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few small comments.
tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj
Outdated
Show resolved
Hide resolved
""" | ||
checkResults | ||
|> checkXml "A" [|"B"|] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also add a test case for attributes before an xml doc in a type declaration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, I didn't spot it there, thanks!
Do I understand correctly that you mean the case [<Attr>]
/// A
type A In this case, |
I would also like to discuss the XmlDoc collecting mechanism for At the moment, it is allowed to leave additional doc-comments for /// A
member x.A with ///GET
get() = 5
and /// SET
set (y: int) = ()
// A xmlDoc: "A GET"
// get_A xmlDoc: "A GET"
// set_A xmlDoc: "A SET" Which seems overcomplicated unnecessarily. In this PR, it is proposed to leave the possibility of adding documentation only to the declaration of the property itself, |
What is the C# spec here? Can you document them separately? We should follow what they do. |
For C#, the documentation can be added only for properties
|
OK, yes, we should follow that |
We can mark each comment block when grabbing it (add a bool field to a block?), and then report syntax warnings for blocks that haven't been grabbed after parsing finishes. |
I think it is more or less ready. |
@dsyme, can you please take a look at this 👀 |
Will do! |
src/fsharp/pars.fsy
Outdated
| h :: _ -> h.Range | ||
LexbufLocalXmlDocStore.GrabXmlDocBeforeMarker(parseState.LexBuffer, grabPoint) | ||
|
||
let grabXmlDoc(parseState: IParseState, optAttributes: SynAttributeList list, elemIdx) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally best to move all helper functions outside pars.fsy, at least for new code or whenever we touch this code.
I'm still uneasy about us dropping the XML doc on this case: #11973 (comment) Am I right in thinking the XML doc is just dropped on the floor? Is it possible to emit an informational warning in this case, indeed whenever any |
Yes, in the described case, the comment is discarded. Or would you like the analyzer to be part of this PR? |
Yes I think we should have an informational warning (Aside: It can't be an "analyzer" in the sense of #11057 and it should be on for the command-line compiler by default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request for informational warning on dropped XML doc
src/fsharp/FSharp.Core/async.fs
Outdated
@@ -305,7 +305,7 @@ namespace Microsoft.FSharp.Control | |||
contents.aux.ccont (OperationCanceledException (contents.aux.token)) | |||
|
|||
/// Check for trampoline hijacking. | |||
// Note, this must make tailcalls, so may not be an instance member taking a byref argument, | |||
/// Note, this must make tailcalls, so may not be an instance member taking a byref argument, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like an internal comment to me. @dsyme Could you advice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@auduchinok, here it is rather suspicious since the line below is a continuation of this one and it begins with ///
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought maybe it was better to change all comments below to //
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsyme, |
As long as it isn't public FCS API I don't really mind So yes, replace all comments after // with /// -> // is fine |
@dsyme , it's done! (: |
@DedSec256 This is fantastic work, thank you |
@DedSec256 Thank you for everything you did on this, including the extensive testing and multiple iterations to take into account code feedback. It's really great to have this addressed |
@dsyme, I thought about the fact that we currently have XmlDoc allowed for local bindings. They do not participate in the generation of the documentation file, and XmlDoc is not allowed for local variables in C#. How do you feel about disallowing XmlDoc for local bindings in the same way? |
XML doc is allowed for local bindings in F#. They should show in autocomplete/intellisense. I assume this PR didn't change that? |
yes, in this PR the XmlDoc is still allowed for local bindings. |
@dsyme Could you tell more about why XmlDoc is preferred over normal comments in local scopes? |
The only rationale is to have them show in tooling. I guess it wasn't enabled in C# because scopes were generally much smaller, especially in C# 1.0 coding styles. In F# you can easily have a class 500 lines long and in that situation it pays to document a |
(Also, in F# XML doc comments are much lighter with the implicit |
(Hm, sounds just like in modern C#. 🙂) |
I wonder where they got that idea! |
This PR contains a redesign of the XmlDoc collecting mechanism to allow more predictable and C# consistent positions for XmlDoc.
Current approach
At the moment, doc-comments are sequentially collected and attached to the nearest (after comments) declaration that supports XmlDoc. This leads to errors when comments that should not be considered at all are attached to declarations:
Also at the moment, it is allowed to leave comments up to the name of the binding/type definition, which seems redundant:
Redesign
The basic idea is to set the grab points for doc-comments after the non-comment expressions encountered. Then we can assume that the comments block belongs to the declaration if its grab point coincides with the correct position in the declaration (for example the beginning of the declaration).
This PR offers to collect comments according to the following rules
1. Delimiter expressions
Similar to C#, if another expression (expression, simple comment, (*), etc.) is encountered when collecting doc-comments, doc-comments before this expression cannot be attached to the declaration
2. Attributes
Similar to C#, if the declaration has attributes, then the comments before the attributes are attached to the declaration
3. type/let-and
Since there is a real use case #11489 (comment), it is allowed to add doc-comments before
and
Also, doc-comments are allowed to be left after
and
However, if comments before and after
and
are present at the same time, then the priority is given to the comments beforeand
4. Declaration parts
It is allowed to leave comments only at the beginning of the declarations
Fix for #11488
Support XmlDoc for union case without bar
TODO
Discussion
PR in progress, we will be glad to hear your opinion, join the discussion (: