Skip to content

Commit 89d0164

Browse files
authored
Merge pull request #3007 from veryl-lang/feat/component-doc
feat(doc): refine generated component pages
2 parents ba03f6b + bd42a86 commit 89d0164

4 files changed

Lines changed: 132 additions & 170 deletions

File tree

crates/component/macros/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ fn expand_derive(input: DeriveInput) -> syn::Result<TokenStream2> {
343343
let mut has_clock_port = false;
344344
// #[interface] fields, spliced into the manifest by const
345345
// concatenation.
346-
let mut groups: Vec<(String, Type)> = Vec::new();
346+
let mut groups: Vec<(String, Type, Option<String>)> = Vec::new();
347347
// Port and group names share the connection-item namespace, so
348348
// duplicates are rejected here where both declarations are visible.
349349
let mut port_names: std::collections::HashSet<String> = std::collections::HashSet::new();
@@ -378,7 +378,7 @@ fn expand_derive(input: DeriveInput) -> syn::Result<TokenStream2> {
378378
let ty = field.ty.clone();
379379
inits.push(quote!(#field_ident:
380380
<#ty as ::veryl_component::VerylInterface>::resolve(ctx, #group)?));
381-
groups.push((group, ty));
381+
groups.push((group, ty, doc));
382382
continue;
383383
}
384384

@@ -502,11 +502,14 @@ fn expand_derive(input: DeriveInput) -> syn::Result<TokenStream2> {
502502
// Splicing another type's consts needs const concatenation; a component
503503
// without interface fields keeps the plain literal.
504504
let mut decl_parts: Vec<TokenStream2> = vec![quote!(#decl_prefix)];
505-
for (i, (group, ty)) in groups.iter().enumerate() {
505+
for (i, (group, ty, doc)) in groups.iter().enumerate() {
506506
let head = format!(
507-
r#"{}{{"name":"{}","interface":""#,
507+
r#"{}{{"name":"{}"{}"interface":""#,
508508
if i == 0 { "" } else { "," },
509509
json_escape(group),
510+
doc.as_ref()
511+
.map(|d| format!(r#","doc":"{}","#, json_escape(d)))
512+
.unwrap_or_else(|| ",".to_string()),
510513
);
511514
decl_parts.push(quote!(#head));
512515
decl_parts.push(quote!(<#ty as ::veryl_component::VerylInterface>::INTERFACE_PATH));

crates/languageserver/src/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@ mod tests {
16471647
doc: None,
16481648
},
16491649
],
1650+
doc: None,
16501651
});
16511652
let text = component_new_text("$comp::x", Some(&grouped));
16521653
assert_eq!(text, "$comp::x (clk, q, axi: , );");

crates/metadata/src/component_manifest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct ManifestGroup {
2727
pub interface: String,
2828
pub modport: String,
2929
pub members: Vec<ManifestMember>,
30+
pub doc: Option<String>,
3031
}
3132

3233
/// One interface member a group binds; the connected interface must
@@ -363,6 +364,7 @@ impl ComponentManifest {
363364
.collect()
364365
})
365366
.unwrap_or_default(),
367+
doc: doc_of(g),
366368
})
367369
.collect()
368370
})

0 commit comments

Comments
 (0)