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

[naga] Comments parsing #6364

Draft
wants to merge 3 commits into
base: v22
Choose a base branch
from
Draft

[naga] Comments parsing #6364

wants to merge 3 commits into from

Conversation

Vrixyz
Copy link

@Vrixyz Vrixyz commented Oct 3, 2024

Connections
None as far as I know.

Description
Generating automated documentation à la https://docs.rs is very useful, but currently difficult.

naga lacks information about comments to be too helpful, so this pull requests adds support to parsing those.

Note: I branched off 0.22 because I'm not confident with jumping on the maybe unstable trunk.

Testing
Not much for now, I'm compiling a currently private project based on https://github.com/jannik4/shader_docs to attempt to add documentation strings to it.

Status

  • Add a token Comment
  • Parse // comments
  • Parse /* */ comments
  • Add comments to ast::Struct
  • Add comments to other items (functions, variables, etc...)
  • Add comments to Module

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@Vrixyz Vrixyz requested a review from a team as a code owner October 3, 2024 15:56
@Vrixyz Vrixyz marked this pull request as draft October 3, 2024 15:56
@jimblandy
Copy link
Member

This doesn't get the comments out of the front end, though, does it?

It seems to me it could be fine to just add a field like:

    doc_comments: Option<Box<DocComments>>,

to naga::Module, and then have something like

struct DocComments {
    types: FastIndexMap<Handle<Type>, Vec<Span>>,
    global_variables: FastIndexMap<Handle<GlobalVariable>, Vec<Span>>,
    ...
}

I think it would make sense for Naga to adopt Rust's /// syntax as a WGSL extension.

@Vrixyz
Copy link
Author

Vrixyz commented Oct 4, 2024

This doesn't get the comments out of the front end, though, does it?

Correct, I'm looking into propagating them to the module now ; my first intuition was to add comments to naga::TypeInner::Struct and the likes ; but I fear for performance.

Your idea of a "flat" DocComments with an indexmap to Spans is interesting and probably a better idea! Thanks for suggesting. I'll go in that direction.

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

Successfully merging this pull request may close these issues.

2 participants