fix(rmcp-macros): fix extract_doc_line code (#142)
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
This commit is contained in:
parent
b6fabc8836
commit
18346b94e4
1 changed files with 8 additions and 14 deletions
|
|
@ -296,33 +296,27 @@ pub(crate) fn tool_impl_item(attr: TokenStream, mut input: ItemImpl) -> syn::Res
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extract doc line from attribute
|
||||||
fn extract_doc_line(attr: &syn::Attribute) -> Option<String> {
|
fn extract_doc_line(attr: &syn::Attribute) -> Option<String> {
|
||||||
if !attr.path().is_ident("doc") {
|
if !attr.path().is_ident("doc") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name_value = match &attr.meta {
|
let syn::Meta::NameValue(name_value) = &attr.meta else {
|
||||||
syn::Meta::NameValue(nv) => nv,
|
return None;
|
||||||
_ => return None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let expr_lit = match &name_value.value {
|
let syn::Expr::Lit(expr_lit) = &name_value.value else {
|
||||||
syn::Expr::Lit(lit) => lit,
|
return None;
|
||||||
_ => return None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let lit_str = match &expr_lit.lit {
|
let syn::Lit::Str(lit_str) = &expr_lit.lit else {
|
||||||
syn::Lit::Str(s) => s,
|
return None;
|
||||||
_ => return None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let content = lit_str.value().trim().to_string();
|
let content = lit_str.value().trim().to_string();
|
||||||
|
|
||||||
if content.is_empty() {
|
(!content.is_empty()).then_some(content)
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tool_fn_item(attr: TokenStream, mut input_fn: ItemFn) -> syn::Result<TokenStream> {
|
pub(crate) fn tool_fn_item(attr: TokenStream, mut input_fn: ItemFn) -> syn::Result<TokenStream> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue