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

v4.6.3 #655

Merged
merged 3 commits into from
Mar 9, 2024
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 .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
Loading