Skip to content

Commit 054d109

Browse files
committed
fix(rust): handle destructured params case (#617)
1 parent 4a1b44f commit 054d109

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

helper/src/rust/parser.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,19 @@ impl<'a> RustParser<'a> {
100100
.for_each(|node| {
101101
let mut param = Map::new();
102102

103-
let func_name = node
103+
let name = node
104104
.children(&mut node.walk())
105105
.filter(|node| node.kind() == "identifier")
106106
.next()
107-
.and_then(|node| Some(self.get_node_text(&node)))
108-
.unwrap();
109-
param.insert("name".to_string(), Value::String(func_name));
107+
.and_then(|node| Some(self.get_node_text(&node)));
110108

111-
params.push(Value::Object(param));
109+
if name.is_some() {
110+
param.insert("name".to_string(), Value::String(name.unwrap()));
111+
}
112+
113+
if !param.is_empty() {
114+
params.push(Value::Object(param));
115+
}
112116
});
113117

114118
if !params.is_empty() {

test/filetypes/rust/functions.vader

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ Expect rust (generated comments with Arguments and Examples sections):
5959
}
6060
}
6161

62+
# ==============================================================================
63+
# Functions parameter destruction
64+
# ==============================================================================
65+
Given rust (function with destructured params):
66+
pub fn do_thing((i, j): (u8, u8)) -> u8 {
67+
i * j
68+
}
69+
70+
Do (trigger doge):
71+
\<C-d>
72+
73+
Expect rust (generated comments):
74+
/// [TODO:description]
75+
///
76+
/// # Examples
77+
///
78+
/// ```
79+
/// [TODO:write some example code]
80+
/// ```
81+
pub fn do_thing((i, j): (u8, u8)) -> u8 {
82+
i * j
83+
}
84+
6285
# ==============================================================================
6386
# Functions with errors and safety section
6487
# ==============================================================================

0 commit comments

Comments
 (0)