Skip to content

Commit

Permalink
fix(rust): handle destructured params case (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Sep 10, 2023
1 parent 4a1b44f commit 054d109
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 9 additions & 5 deletions helper/src/rust/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@ impl<'a> RustParser<'a> {
.for_each(|node| {
let mut param = Map::new();

let func_name = node
let name = node
.children(&mut node.walk())
.filter(|node| node.kind() == "identifier")
.next()
.and_then(|node| Some(self.get_node_text(&node)))
.unwrap();
param.insert("name".to_string(), Value::String(func_name));
.and_then(|node| Some(self.get_node_text(&node)));

params.push(Value::Object(param));
if name.is_some() {
param.insert("name".to_string(), Value::String(name.unwrap()));
}

if !param.is_empty() {
params.push(Value::Object(param));
}
});

if !params.is_empty() {
Expand Down
23 changes: 23 additions & 0 deletions test/filetypes/rust/functions.vader
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ Expect rust (generated comments with Arguments and Examples sections):
}
}

# ==============================================================================
# Functions parameter destruction
# ==============================================================================
Given rust (function with destructured params):
pub fn do_thing((i, j): (u8, u8)) -> u8 {
i * j
}

Do (trigger doge):
\<C-d>

Expect rust (generated comments):
/// [TODO:description]
///
/// # Examples
///
/// ```
/// [TODO:write some example code]
/// ```
pub fn do_thing((i, j): (u8, u8)) -> u8 {
i * j
}

# ==============================================================================
# Functions with errors and safety section
# ==============================================================================
Expand Down

0 comments on commit 054d109

Please sign in to comment.