diff --git a/.version b/.version index c78c4964..83da99bc 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -4.6.2 +4.6.3 diff --git a/helper/Cargo.lock b/helper/Cargo.lock index c9d11779..89996efb 100644 --- a/helper/Cargo.lock +++ b/helper/Cargo.lock @@ -744,7 +744,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vim-doge-helper" -version = "4.6.2" +version = "4.6.3" dependencies = [ "clap", "regex", diff --git a/helper/Cargo.toml b/helper/Cargo.toml index 806fcdb0..8ec38327 100644 --- a/helper/Cargo.toml +++ b/helper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vim-doge-helper" -version = "4.6.2" +version = "4.6.3" edition = "2021" publish = false include = ["src"] diff --git a/helper/src/python/parser.rs b/helper/src/python/parser.rs index cf292609..d8aef63e 100644 --- a/helper/src/python/parser.rs +++ b/helper/src/python/parser.rs @@ -25,15 +25,23 @@ impl<'a> BaseParser for PythonParser<'a> { fn postprocess_line(&self, line: usize) -> usize { for node in traverse::PreOrder::new(self.tree.root_node().walk()) { if node.start_position().row + 1 == line { - // Find the body of the function, - // that's where the insert position is. - let body_node = node + // Find the body of the function, that's where the insert + // position should be, but rather finding the actual body, we + // find the colon after the return type, because there might be + // a docblock after the colon and before the body and we still + // want to insert before this. + // + // Example: + // def foo() -> int: <-- insert after here + // # Comment <-- considered separate from body + // pass <-- start of the body + let colon_node = node .children(&mut node.walk()) - .filter(|node| node.kind() == "block") + .filter(|node| node.kind() == ":") .next(); - if body_node.is_some() { - return body_node.unwrap().prev_sibling().unwrap().start_position().row + 1; + if colon_node.is_some() { + return colon_node.unwrap().start_position().row + 1; } } } @@ -78,7 +86,10 @@ impl<'a> PythonParser<'a> { for child_node in node.children(&mut node.walk()) { match child_node.kind() { "type" => { - tokens.insert("return_type".to_string(), Value::String(self.get_node_text(&child_node))); + let value = Value::String(self.get_node_text(&child_node)); + if value != "None" { + tokens.insert("return_type".to_string(), value); + } }, "parameters" => { let mut params = Vec::new(); diff --git a/test/filetypes/python/functions.vader b/test/filetypes/python/functions.vader index 37e70020..39ae39ad 100644 --- a/test/filetypes/python/functions.vader +++ b/test/filetypes/python/functions.vader @@ -2,17 +2,19 @@ # Functions without parameters. # ============================================================================== Given python (function without parameters): - def myFunc(): # inline comment + def myFunc(): + # inline comment pass Do (trigger doge): \ Expect python (no changes): - def myFunc(): # inline comment + def myFunc(): """ [TODO:description] """ + # inline comment pass # ============================================================================== @@ -57,14 +59,14 @@ Expect python (generated comment with :param tags): # Functions with parameters. # ============================================================================== Given python (function with parameters): - def myFunc(p1: str = 'string', p2: int = 5): + def myFunc(p1: str = 'string', p2: int = 5) -> None: pass Do (trigger doge): \ Expect python (generated comment with :param tags): - def myFunc(p1: str = 'string', p2: int = 5): + def myFunc(p1: str = 'string', p2: int = 5) -> None: """ [TODO:description]