feat: implement rustdoc comment generation support#190
Open
rockaxorb13 wants to merge 2 commits intoaccordproject:mainfrom
Open
feat: implement rustdoc comment generation support#190rockaxorb13 wants to merge 2 commits intoaccordproject:mainfrom
rockaxorb13 wants to merge 2 commits intoaccordproject:mainfrom
Conversation
Signed-off-by: Aadityavardhan Singh <singhrashmi018@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds RustDoc (///) documentation comment generation to the Rust CTO code generator by introducing a writeDescription helper and calling it from several visitor methods when emitting Rust structs and their members.
Changes:
- Added
writeDescription(thing, parameters, indent)to emit///lines fromgetDescription(). - Updated
visitClassDeclarationto emit RustDoc comments for generated structs. - Updated
visitField(including HashMap handling) andvisitRelationshipDeclarationto emit RustDoc comments for fields/relationships.
Comments suppressed due to low confidence (1)
lib/codegen/fromcto/rust/rustvisitor.js:311
- PR description mentions generating docs for structs and enums, but this change only calls writeDescription from visitClassDeclaration (structs). If enum docs are intended, visitEnumDeclaration (and possibly visitEnumValueDeclaration) should also call writeDescription; otherwise please update the PR description to match actual behavior.
this.writeDescription(classDeclaration, parameters, 0);
parameters.fileWriter.writeLine(
0,
'#[derive(Debug, Clone, Serialize, Deserialize)]'
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1346
to
+1347
| if (thing.getDescription && thing.getDescription()) { | ||
| const description = thing.getDescription(); |
There was a problem hiding this comment.
writeDescription calls thing.getDescription() multiple times (in the condition and again when assigning), which can be inefficient and can repeat side effects if getDescription is computed. Consider calling it once, validating it's a string (or coercing via String()), and reusing the value.
Suggested change
| if (thing.getDescription && thing.getDescription()) { | |
| const description = thing.getDescription(); | |
| const description = thing.getDescription && thing.getDescription(); | |
| if (typeof description === 'string' && description.length > 0) { |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Matt Roberts <7544022+mttrbrts@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR brings the Rust generator closer to feature parity by adding support for documentation comments. It implements a
writeDescriptionhelper method that converts Concerto model descriptions into standard Rust documentation comments (///).Changes
writeDescriptionhelper method toRustVisitorclass.visitClassDeclarationto generate documentation for Structs and Enums.visitFieldto generate documentation for Fields (including HashMap support).visitRelationshipDeclarationto generate documentation for Relationships.Testing & Verification
I verified this logic locally using a debug script.
Note on Upstream Parser Behavior:
I discovered that the current version of
@accordproject/concerto-cto(v3.25.0) used in this repository appears to strip comments during AST parsing. As a result,thing.getDescription()returnsundefinedby default when parsing a string.To verify that my
RustVisitorlogic works correctly, I used a script that manually injects descriptions into theClassDeclarationobjects in memory after parsing. This confirmed that the generator correctly formats and outputs the RustDoc comments when the data is present in the model.Verification Script (
debug-rust.js)here is the debug script output which I got, after the modifications I made to rustvisitor.js:

Line 7 shows that the comment has been injected.
I am uploading the two files,
debug-rust.jshere:debug-rust.js