Skip to content

refactor(plantuml): introduce Rust idmap generation and CLI source-aware output wiring#321

Open
AAmbuj wants to merge 2 commits into
eclipse-score:mainfrom
AAmbuj:amsh_refactor_plantuml_rust_idmap_cli
Open

refactor(plantuml): introduce Rust idmap generation and CLI source-aware output wiring#321
AAmbuj wants to merge 2 commits into
eclipse-score:mainfrom
AAmbuj:amsh_refactor_plantuml_rust_idmap_cli

Conversation

@AAmbuj

@AAmbuj AAmbuj commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This change introduces a Rust-native idmap generation flow in the PlantUML parser pipeline and wires the CLI to emit source-aware idmap outputs.

What is included:

  • Added a new Rust idmap library to generate idmap sidecar data for supported diagram models.
  • Extended the CLI with source-aware output handling for idmap emission.
  • Updated related Rust integration points so idmap output can be produced consistently during parsing.

Why:

  • Establishes deterministic, source-anchored link metadata at parse time.
  • Simplifies downstream consumption by producing structured sidecar data directly from Rust components.
  • Enables incremental adoption of idmap-based linking with a focused, testable Rust-only scope.

@AAmbuj AAmbuj marked this pull request as ready for review July 7, 2026 09:57
Comment thread plantuml/parser/puml_cli/src/main.rs Outdated
Comment on lines +121 to +125
/// Stable workspace-relative source name baked into generated artifacts
/// (FlatBuffers/lobster/idmap ``source`` field). When omitted, the
/// filesystem basename is used as a fallback.
#[arg(long)]
source_name: Option<String>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--source-name doesn't scale to multiple input files because a single CLI argument cannot be mapped unambiguously to multiple sources. The source field is a property of each input file and should be derived from the file path itself (preferably converted to a workspace-relative path), rather than being supplied independently by the caller.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread plantuml/parser/puml_cli/src/main.rs Outdated
ResolvedDiagram::Sequence(_) => LobsterModel::Empty,
};
write_lobster_to_file(lobster_model, path, ldir)?;
write_lobster_to_file(lobster_model, path, Some(source_file), ldir)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path and source_file are effectively the same thing. I don't think we need to change fucntion write_lobster_to_file signature here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread plantuml/parser/puml_idmap/src/lib.rs Outdated
/// `true` when this diagram elaborates the element (i.e. it is listed
/// under `defines`). Omitted from the JSON for plain references.
#[serde(default, skip_serializing_if = "is_not_elaborated")]
pub elaborated: bool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is elaborated still needed here? The split between defines and references already conveys the same information. Unless there are cases where a define can be non-elaborated (or a reference elaborated), this field seems redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed elaborated from idmap entries. Define/reference role is now represented only by membership in defines vs references arrays.

/// `parent_id` (i.e. it has children and is therefore elaborated here).
/// All remaining elements are **references** (top-level leaves that mention
/// something that may be detailed in another diagram).
fn comp_model_to_idmap(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question: how should packages be handled in this case?

For example:

package P {
  component A {
    component AA
  }
}

Since both package P and component A have children, the current rule "elements with children" seems to classify both as defines. Is that the intended behavior, or should packages be treated purely as containers/namespaces rather than emitted as definitions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread plantuml/parser/puml_idmap/src/lib.rs Outdated
let has_members = !entity.methods.is_empty() || !entity.variables.is_empty();
let matches_diagram_name = diagram_name == Some(entity.name.as_str());
let is_define = has_members || matches_diagram_name;
let entry = IdMapEntry {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any handling of entity.relationships here. Since the proposal defines references to include relation endpoints, shouldn't those be emitted as reference entries as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now add relationship source/target endpoints as references (deduplicated, and not duplicating defines).

}

/// Collect the unique participant names from a sequence tree.
fn collect_participants(tree: &SequenceTree) -> HashSet<String> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently derives participants from interaction endpoints (caller/callee). We have a planned follow-up to persist participant declarations in the AST, so this logic should be updated to use the explicit participant list instead of reconstructing it here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially addressed for now. The current SequenceTree model does not yet persist explicit participant declarations, so behavior remains endpoint-derived. I added a TODO marker to switch to declaration-based sourcing once the resolver/AST exposes participants explicitly.

Comment thread plantuml/parser/puml_idmap/src/lib.rs Outdated
Class(&'a ClassDiagram),
Sequence(&'a SequenceTree),
Fta(&'a FtaModel),
Empty,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the Empty variant here? It seems to conflate several different states (no model, unsupported diagram type, empty diagram, parse failure, etc.).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed Empty from IdMapModel and introduced an explicit empty writer API used only where intentionally empty output is desired (for example activity diagrams).

Emits a per-source .idmap.json with defines[] / references[] entries used
by the clickable_plantuml Sphinx extension to resolve cross-diagram links.
Supports Component, Class, Sequence, Activity (empty), and FTA diagrams.
@AAmbuj AAmbuj force-pushed the amsh_refactor_plantuml_rust_idmap_cli branch from f551a99 to eb2921f Compare July 9, 2026 07:21
Calls write_idmap_to_file() for every resolved diagram. Passes short_path
as source_name so both idmap and lobster outputs use the stable
workspace-relative path rather than the sandbox-local filesystem path.
@AAmbuj AAmbuj force-pushed the amsh_refactor_plantuml_rust_idmap_cli branch from eb2921f to b4dcb24 Compare July 9, 2026 07:53
@AAmbuj AAmbuj requested a review from melodyoncode July 9, 2026 08:58
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