Skip to content
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
15 changes: 14 additions & 1 deletion src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,21 @@ impl Formatter {
if last_comment_is_doc_comment {
let mut comment_node_index = m.captures.len() - 2;

let first_comment_node = m.captures[1].node;
let first_comment_is_inline_comment =
first_comment_node.start_position().row
== first_node.start_position().row;
// ignore n first nodes when searching for the first docstring comment node
// in case if the first comment is an inline comment we ignore
// two nodes: first statement node and inline comment node
// otherwise we ignore only the first statement node
let mut amount_of_nodes_to_ignore = 1;
if first_comment_is_inline_comment {
amount_of_nodes_to_ignore += 1;
}

// find first documentation comment node
while comment_node_index > 2
while comment_node_index > amount_of_nodes_to_ignore
&& m.captures[comment_node_index - 1].node.start_position().row
== m.captures[comment_node_index].node.start_position().row - 1
{
Expand Down
6 changes: 6 additions & 0 deletions tests/expected/two_lines_spacing_with_comments.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ func test2() -> void:
pass


# Multiline docstring
# another line
func test2() -> void:
pass


var a # case 2


Expand Down
5 changes: 5 additions & 0 deletions tests/input/two_lines_spacing_with_comments.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var a
func test2() -> void:
pass

# Multiline docstring
# another line
func test2() -> void:
pass

var a # case 2

func test2() -> void:
Expand Down