Skip to content

Commit

Permalink
Merge pull request #655 from kkoomen/release/v4.6.3
Browse files Browse the repository at this point in the history
v4.6.3
  • Loading branch information
kkoomen authored Mar 9, 2024
2 parents 622736c + 34b2130 commit e8aa8ac
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.6.2
4.6.3
2 changes: 1 addition & 1 deletion helper/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion helper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vim-doge-helper"
version = "4.6.2"
version = "4.6.3"
edition = "2021"
publish = false
include = ["src"]
Expand Down
25 changes: 18 additions & 7 deletions helper/src/python/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 6 additions & 4 deletions test/filetypes/python/functions.vader
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
# Functions without parameters.
# ==============================================================================
Given python (function without parameters):
def myFunc(): # inline comment
def myFunc():
# inline comment
pass

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

Expect python (no changes):
def myFunc(): # inline comment
def myFunc():
"""
[TODO:description]
"""
# inline comment
pass

# ==============================================================================
Expand Down Expand Up @@ -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):
\<C-d>

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]

Expand Down

0 comments on commit e8aa8ac

Please sign in to comment.