Skip to content

Commit 17fd299

Browse files
committed
prefer attaching docstring to the statement
1 parent 1d14cc7 commit 17fd299

File tree

4 files changed

+68
-28
lines changed

4 files changed

+68
-28
lines changed

queries/gdscript.scm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@
192192
(comment)
193193
(region_start)
194194
(region_end)
195-
(annotation)] @allow_blank_line_before)
195+
(annotation)
196+
(function_definition)
197+
(class_definition)
198+
(constructor_definition)] @allow_blank_line_before)
196199

197200
(setget) @prepend_indent_start @append_indent_end
198201
(setget ":" @prepend_antispace)

src/formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Formatter {
166166
// - must contain at least one new line character between `extends_name` and optional doc comment
167167
// - may contain multiple doc comment lines that starts with `##` and ends with a new line character
168168
let re = RegexBuilder::new(
169-
r#"(?P<extends_line>^extends )(?P<extends_name>([a-zA-Z0-9]+|".*?"))\n+(?P<doc>(?:^##.*\n)*)\n*(?P<EOF>\z)?"#,
169+
r#"(?P<extends_line>^extends )(?P<extends_name>([a-zA-Z0-9]+|".*?"))\n+((?P<doc>(?:^##.*\n)+)(?:\z|\n))?\n*(?P<EOF>\z)?"#,
170170
)
171171
.multi_line(true)
172172
.build()
Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
1-
class_name Player
21
extends CharacterBody2D
3-
## A brief description of the class's role and functionality.
2+
## Blankline after docstring
43
##
54
## The description of script
65

7-
class_name Player
6+
var a = 10
87
extends CharacterBody2D
9-
## A brief description of the class's role and functionality.
8+
## Blankline before and after docstring
109
##
1110
## The description of script
1211

13-
class_name Player
12+
var a = 10
1413
extends CharacterBody2D
15-
## A brief description of the class's role and functionality.
14+
15+
## Blankline before docstring
1616
##
17-
## The description of script
17+
## The description of a variable
18+
var a = 10
19+
extends CharacterBody2D
1820

21+
## No blankline around docstring
22+
##
23+
## The description of a variable
1924
var a = 10
20-
class_name Player
2125
extends CharacterBody2D
22-
## A brief description of the class's role and functionality.
26+
27+
## Blanklink before function docstring
28+
##
29+
## The description of a variable
30+
func foo():
31+
pass
32+
extends CharacterBody2D
33+
## Blankline between docstring and function definition
2334
##
24-
## The description of script
35+
## The description of a variable
36+
37+
func foo():
38+
pass
39+
extends CharacterBody2D
2540

2641
var a = 10
27-
class_name Player
2842
extends CharacterBody2D
29-
## A brief description of the class's role and functionality.
3043

3144
var a = 10
45+
extends CharacterBody2D
46+
## Docstring at the end of file
47+
##
48+
## The description of script

tests/input/class_doc_comment.gd

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,47 @@
1-
class_name Player extends CharacterBody2D
2-
3-
## A brief description of the class's role and functionality.
4-
##
5-
## The description of script
6-
class_name Player extends CharacterBody2D
7-
## A brief description of the class's role and functionality.
1+
extends CharacterBody2D
2+
## Blankline after docstring
83
##
94
## The description of script
10-
class_name Player extends CharacterBody2D
11-
## A brief description of the class's role and functionality.
5+
6+
var a = 10
7+
extends CharacterBody2D
8+
9+
## Blankline before and after docstring
1210
##
1311
## The description of script
1412

1513
var a = 10
16-
class_name Player
1714
extends CharacterBody2D
1815

19-
## A brief description of the class's role and functionality.
16+
## Blankline before docstring
2017
##
21-
## The description of script
18+
## The description of a variable
19+
var a = 10
20+
extends CharacterBody2D
21+
## No blankline around docstring
22+
##
23+
## The description of a variable
24+
var a = 10
25+
extends CharacterBody2D
26+
## Blanklink before function docstring
27+
##
28+
## The description of a variable
29+
func foo():
30+
pass
31+
extends CharacterBody2D
32+
## Blankline between docstring and function definition
33+
##
34+
## The description of a variable
35+
36+
func foo():
37+
pass
38+
extends CharacterBody2D
2239

2340
var a = 10
24-
class_name Player
2541
extends CharacterBody2D
26-
## A brief description of the class's role and functionality.
2742
var a = 10
43+
44+
extends CharacterBody2D
45+
## Docstring at the end of file
46+
##
47+
## The description of script

0 commit comments

Comments
 (0)