Skip to content

Commit e8aa8ac

Browse files
authored
Merge pull request #655 from kkoomen/release/v4.6.3
v4.6.3
2 parents 622736c + 34b2130 commit e8aa8ac

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.6.2
1+
4.6.3

helper/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vim-doge-helper"
3-
version = "4.6.2"
3+
version = "4.6.3"
44
edition = "2021"
55
publish = false
66
include = ["src"]

helper/src/python/parser.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@ impl<'a> BaseParser for PythonParser<'a> {
2525
fn postprocess_line(&self, line: usize) -> usize {
2626
for node in traverse::PreOrder::new(self.tree.root_node().walk()) {
2727
if node.start_position().row + 1 == line {
28-
// Find the body of the function,
29-
// that's where the insert position is.
30-
let body_node = node
28+
// Find the body of the function, that's where the insert
29+
// position should be, but rather finding the actual body, we
30+
// find the colon after the return type, because there might be
31+
// a docblock after the colon and before the body and we still
32+
// want to insert before this.
33+
//
34+
// Example:
35+
// def foo() -> int: <-- insert after here
36+
// # Comment <-- considered separate from body
37+
// pass <-- start of the body
38+
let colon_node = node
3139
.children(&mut node.walk())
32-
.filter(|node| node.kind() == "block")
40+
.filter(|node| node.kind() == ":")
3341
.next();
3442

35-
if body_node.is_some() {
36-
return body_node.unwrap().prev_sibling().unwrap().start_position().row + 1;
43+
if colon_node.is_some() {
44+
return colon_node.unwrap().start_position().row + 1;
3745
}
3846
}
3947
}
@@ -78,7 +86,10 @@ impl<'a> PythonParser<'a> {
7886
for child_node in node.children(&mut node.walk()) {
7987
match child_node.kind() {
8088
"type" => {
81-
tokens.insert("return_type".to_string(), Value::String(self.get_node_text(&child_node)));
89+
let value = Value::String(self.get_node_text(&child_node));
90+
if value != "None" {
91+
tokens.insert("return_type".to_string(), value);
92+
}
8293
},
8394
"parameters" => {
8495
let mut params = Vec::new();

test/filetypes/python/functions.vader

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
# Functions without parameters.
33
# ==============================================================================
44
Given python (function without parameters):
5-
def myFunc(): # inline comment
5+
def myFunc():
6+
# inline comment
67
pass
78

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

1112
Expect python (no changes):
12-
def myFunc(): # inline comment
13+
def myFunc():
1314
"""
1415
[TODO:description]
1516
"""
17+
# inline comment
1618
pass
1719

1820
# ==============================================================================
@@ -57,14 +59,14 @@ Expect python (generated comment with :param tags):
5759
# Functions with parameters.
5860
# ==============================================================================
5961
Given python (function with parameters):
60-
def myFunc(p1: str = 'string', p2: int = 5):
62+
def myFunc(p1: str = 'string', p2: int = 5) -> None:
6163
pass
6264

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

6668
Expect python (generated comment with :param tags):
67-
def myFunc(p1: str = 'string', p2: int = 5):
69+
def myFunc(p1: str = 'string', p2: int = 5) -> None:
6870
"""
6971
[TODO:description]
7072

0 commit comments

Comments
 (0)