-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
top-level doc comment should be allowed in zig fmt #2288
Comments
This assumes we want top-level documentation. There may be alternatives that are better suited and we can play with more once the documentation generator is started. For example, since a file is semantically a struct (by #1047), would we also allow this sort of top-level documentation as allowed as the first node in a struct ast. It may be better to handle these differently even if semantically they are the same, so have the least surprising behaviour. |
Are top level doc comments something we want now that documentation generation is here? For normal containers and namespaces the need for top level doc comments can easily be avoided. However we'll probably need them if we want to document a package in its root file. |
If we want container level doc comments we should probably copy rust and have a different kind of comment for them since properly parsing /// container doc comment
/// declaration doc comment
const A = ... requires the parser to understand whitespace whereas //! container doc comment
/// declaration doc comment
const A = ... doesn't. |
I agree with copying rust here. It's unfortunate that there will be 2 ways to add doc comments for a container which is not the file, but maybe zig fmt can canonicalize that. |
Take the following program:
After applying
zig fmt
this is turned into:I don't think we should collapse top-level documentation at the beginning of the ast. I note that we have
Error.UnattachedDocComment
inzig/ast.zig
. I do think it still makes sense to emit an error for documentation which isn't attached in the middle of a file, as I'm not sure how it could be interpreted in a meaningful way.Related, but running
zig fmt
on a file with only a doc comment deletes it.The text was updated successfully, but these errors were encountered: