Skip to content

Conversation

@rockaxorb13
Copy link

Description

This PR brings the Rust generator closer to feature parity by adding support for documentation comments. It implements a writeDescription helper method that converts Concerto model descriptions into standard Rust documentation comments (///).

Changes

  • Added writeDescription helper method to RustVisitor class.
  • Updated visitClassDeclaration to generate documentation for Structs and Enums.
  • Updated visitField to generate documentation for Fields (including HashMap support).
  • Updated visitRelationshipDeclaration to 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() returns undefined by default when parsing a string.

To verify that my RustVisitor logic works correctly, I used a script that manually injects descriptions into the ClassDeclaration objects 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)

const { ModelManager, ModelFile } = require('@accordproject/concerto-core');
const { Parser } = require('@accordproject/concerto-cto');
const { CodeGen } = require('./index');
const FileWriter = require('@accordproject/concerto-util').FileWriter;

const cto = `namespace com.test
asset Car identified by vin {
  o String vin
  o String color
}`;

// 1. Setup
const modelManager = new ModelManager();
const ast = Parser.parse(cto);
const modelFile = new ModelFile(modelManager, ast, 'test.cto');
modelManager.addModelFile(modelFile);

// 2. Manual Injection (Simulating a working parser)
const carDecl = modelFile.getType('com.test.Car');
if (carDecl) {
    carDecl.getDescription = () => "Documentation for Car Class";
    
    const colorField = carDecl.getProperty('color');
    if (colorField) {
        colorField.getDescription = () => "Documentation for Color Field";
    }
}

// 3. Run Visitor
const visitor = new CodeGen.RustVisitor();
const parameters = { fileWriter: new FileWriter('./output') };

modelManager.accept(visitor, parameters);

here is the debug script output which I got, after the modifications I made to rustvisitor.js:
Screenshot
Line 7 shows that the comment has been injected.

I am uploading the two files, debug-rust.js here:
debug-rust.js

Signed-off-by: Aadityavardhan Singh <singhrashmi018@gmail.com>
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.

1 participant