-
Notifications
You must be signed in to change notification settings - Fork 524
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
bindgen: Initial doc comments for Odin & Zig #1176
bindgen: Initial doc comments for Odin & Zig #1176
Conversation
Very cool! I'm currently deep into emulator stuff but as soon as I crawl out of that rabbit hole again I'll try to reserve some time to take care of pending PRs. One thing I keep rolling around in the back of my head is to find a better doc-comment structure which doesn't generate such huge documentation panels when mousing over a struct declaration. But that's unrelated to making the comments available in the bindings code :) |
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 some quick'n'dirty review comments where I think it's worth it to move some similar code into a helper function.
PS: don't worry about the CI error, that's something unrelated in the D bindings test. |
@floooh Added a utility function to add comment outputs (if exists), also found a better way to handle indenting and prefixing via Also went ahead and added Zig comments, just to make sure it was ergonomic to "port" from one generator to another considering different syntax requirements. Should be much better now for porting!
I think it's fine, they're not unbearably big (apart from the huge top comment block which would be useful to at least have in the bindings but not attached to a specific declaration). As this comment often includes important notes, examples, etc, I think it would be useful to somehow include that in the bindings so I don't have to navigate to the C files. |
I added an extremely rudimentary method to include the top comment in the output. The clang AST doesn't include it, because it's not attached to any node, so I just wrote a regex that extracted the first comment block ( I'm wasn't too happy with just the top comment, so I made sure to only include it if it contains the "Project URL" section (which is also not ideal, I know), which all files do. Another method would be to have a special mark (like It's up to you if you want to include it or not! Let me know if I should revert that part. |
FYI: I'll try to take care of this PR after wrapping up some more PRs in my emulator project, most like on the weekend. |
Ok, merged! I also added an entry to the changelog. Many thanks! |
Ok, sokol-zig and sokol-odin updates are live: |
Here's a proof of concept method of preserving comments in bindgen, as mentioned in #1147.
Right now I've only added it to the Odin (and now Zig) bindgen, but each generator can enable it by turning on
with_comments
flag to thegen_ir
parser. But after that, the generator must handle the additional AST nodes. In Odin, I did this simply by stripping away all comments whenever we're looping through inner node children, and getting the comment separately and adding it to the output.Should be straight forward to add the same behavior to the other generators, but this is a good start!
Here's some examples of some comments:
These then show up in the OLS LSP, at least in neovim: