Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust): handle destructured params case (#617) #618

Merged
merged 3 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading