Skip to content

Commit cc4d853

Browse files
author
姚临倾
committed
fix impl doc
1 parent 27a7459 commit cc4d853

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

crates/rmcp-macros/src/tool.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,27 @@ pub enum ToolItem {
190190

191191
impl Parse for ToolItem {
192192
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
193-
let lookahead = input.lookahead1();
194-
if lookahead.peek(Token![impl]) {
195-
let item = input.parse::<ItemImpl>()?;
196-
Ok(ToolItem::Impl(item))
197-
} else {
198-
let item = input.parse::<ItemFn>()?;
199-
Ok(ToolItem::Fn(item))
193+
if let Ok(item)=input.parse::<ItemImpl>(){
194+
return Ok(ToolItem::Impl(item));
195+
}
196+
if let Ok(item) = input.parse::<ItemFn>() {
197+
return Ok(ToolItem::Fn(item));
200198
}
199+
Err(syn::Error::new(
200+
input.span(),
201+
"expected function or impl block",
202+
))
201203
}
202204
}
203205

204206
// dispatch impl function item and impl block item
205207
pub(crate) fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
206208
let tool_item = syn::parse2::<ToolItem>(input)?;
207209
match tool_item {
208-
ToolItem::Fn(item) => tool_fn_item(attr, item),
210+
ToolItem::Fn(item) => {
211+
println!("{:#?}",&item);
212+
tool_fn_item(attr, item)
213+
},
209214
ToolItem::Impl(item) => tool_impl_item(attr, item),
210215
}
211216
}
@@ -225,7 +230,6 @@ pub(crate) fn tool_impl_item(attr: TokenStream, mut input: ItemImpl) -> syn::Res
225230
.filter_map(extract_doc_line)
226231
.collect::<Vec<_>>()
227232
.join("\n");
228-
229233
parse_quote! {
230234
#doc_content.trim().to_string()
231235
}

examples/servers/src/common/calculator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pub struct SumRequest {
1212
}
1313
#[derive(Debug, Clone)]
1414
pub struct Calculator;
15-
#[tool(tool_box,description = "A simple calculator")]
15+
16+
#[tool(tool_box,description="A simple calculator")]
1617
impl Calculator {
1718
#[tool(description = "Calculate the sum of two numbers")]
1819
fn sum(&self, sum: SumRequest) -> String {

0 commit comments

Comments
 (0)