Skip to content

Commit

Permalink
Merge pull request #618 from kkoomen/feature/rust-destructured-params
Browse files Browse the repository at this point in the history
fix(rust): handle destructured params case (#617)
  • Loading branch information
kkoomen authored Sep 10, 2023
2 parents 4a1b44f + 90cd80a commit 39dc181
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
vim-version: [v7.4.2119, v8.2.5172, head]
vim-version: [v7.4.2119, v8.2.5172, v9.0.1500]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout kkoomen/vim-doge
Expand Down
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 39dc181

Please sign in to comment.