From 5c87d7b8ce4cc89213604975b150a6574b9e587c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Tue, 15 Aug 2023 10:27:57 +0200 Subject: [PATCH] fix(cpp): resolve default param case --- helper/Cargo.lock | 2 +- helper/src/cpp/parser.rs | 13 +++++++++---- test/filetypes/cpp/functions.vader | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/helper/Cargo.lock b/helper/Cargo.lock index bf6a5789..132ac0ad 100644 --- a/helper/Cargo.lock +++ b/helper/Cargo.lock @@ -805,7 +805,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vim-doge-helper" -version = "4.2.0" +version = "4.3.0" dependencies = [ "clap", "regex", diff --git a/helper/src/cpp/parser.rs b/helper/src/cpp/parser.rs index 669894bd..0b56fc88 100644 --- a/helper/src/cpp/parser.rs +++ b/helper/src/cpp/parser.rs @@ -160,12 +160,17 @@ impl<'a> CppParser<'a> { } } } - - if node.kind() == "identifier" { - param.insert("name".to_string(), Value::String(self.get_node_text(&node))); - } }); + let name = node + .children(&mut node.walk()) + .filter(|node| node.kind() == "identifier") + .next() + .and_then(|node| Some(self.get_node_text(&node))); + if name.is_some(){ + param.insert("name".to_string(), Value::String(name.unwrap())); + } + params.push(Value::Object(param)); }); diff --git a/test/filetypes/cpp/functions.vader b/test/filetypes/cpp/functions.vader index 76e046a9..593e1c7b 100644 --- a/test/filetypes/cpp/functions.vader +++ b/test/filetypes/cpp/functions.vader @@ -88,3 +88,23 @@ Expect cpp (generated comment with @brief and @param tag): int* fun1(int a,int b,int c){ return nullptr; } + +# ============================================================================== +# Functions with a default value +# ============================================================================== +Given cpp (function with a default value): + int y = 5; + void foo( int x = y ); + +Do (trigger doge): + :2\ + \ + +Expect cpp (generated comment with @brief and @param tag): + int y = 5; + /** + * @brief [TODO:summary] + * + * @param[[TODO:direction]] x [TODO:description] + */ + void foo( int x = y );