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

User Story: Generate UML diagrams for rust code/crates. #33

Open
dan-da opened this issue Jan 27, 2023 · 6 comments
Open

User Story: Generate UML diagrams for rust code/crates. #33

dan-da opened this issue Jan 27, 2023 · 6 comments
Labels
A-user-story Area: A user story or a related issue

Comments

@dan-da
Copy link

dan-da commented Jan 27, 2023

I have hacked a bit on ml, a tool that generates diagrams from rust code.

Here are some example diagrams

It presently uses the AST generated by nightly which seems to be always changing. So the ml tool is locked to a specific version of nightly.

This tool is very crusty (a prototype really) and badly needs a re-write. It occurs to me that rust-marker could serve as the AST basis for such.

@dan-da dan-da added the A-user-story Area: A user story or a related issue label Jan 27, 2023
@xFrednet
Copy link
Member

Hey, thank you for the issue. This kind of analysis / metadata extraction should definitely be possible with marker. I have one quick question regarding the UML diagrams. Are they drawn on a per crate level or on a global level based on what the user specified?

@dan-da
Copy link
Author

dan-da commented Jan 27, 2023

crate level.

It looks for all *.rs files below src for a given crate, parses and transforms each in memory, and then outputs a single .dot (graphviz) and single .svg file for the crate.

As I recall, it presently ignores module names, and thus collisions can occur. something to fix, but not easy with present impl.

I made a script that can take a list of crate names and urls as input and output an html page with diagram links for each crate. (as per the above-linked example). In this script, the ml tool is invoked 3 times per crate to generate different levels of detail.

@xFrednet
Copy link
Member

Perfect, thank you for the explanation :)

@jhpratt
Copy link
Member

jhpratt commented Jan 27, 2023

Personally, I think this should fall under what was discussed in #7. Namely, go for it, but it's not a use case that is explicitly supported. The primary goal of the project is a custom linter, after all.

@xFrednet
Copy link
Member

This is the second request we got related to extracting metadata. Maybe adding this as a primary use case could be good. I'd be careful with adding explicit utilities for this, as the main focus is linting. However, this and the other use cases I heard off, all require the same information that lints would need anyways. The main additional requirement, I see, would be, that it has to be possible to run the linter with only a specified lint crate. This can be handled by the CLI and is in fact something I already planned for ^^.

@dan-da
Copy link
Author

dan-da commented Jan 28, 2023

btw, this diagram generator tool is rather crude.

I think the ultimate evolution would be a tool that exports something like a high-level AST that expresses the data types and relations between them. It would include crate and module information. It would then be possible to run this tool over a crate and all its dependencies recursively to generate a full AST for entire dependency tree.

A visualizer tool (2d and/or 3d) could then take the generated AST as input and render a navigable 3d graph, or 2d diagrams, where different levels of detail can by dynamically selected, including doc comments. So it could look like docs.rs all the way to just struct names.

It might even be that such a visualizer tool could be built directly from the rust-marker AST with no translator tool necessary....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-user-story Area: A user story or a related issue
Projects
None yet
Development

No branches or pull requests

3 participants