Skip to content

Commit 918aa5b

Browse files
authored
Merge pull request #50 from emacs-php/fix/functions-indentation
Fix functions indentation
2 parents 9f8b43a + 31d51ea commit 918aa5b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

php-ts-mode.el

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
((parent-is "program") column-0 0)
7474
((parent-is "comment") parent-bol 1)
7575
((parent-is "declaration_list") parent-bol ,offset)
76-
((parent-is "function_definition") parent-bol ,offset)
76+
;; "compound_statement" contains the body of many statements.
77+
;; For example function_definition, foreach_statement, etc.
7778
((parent-is "compound_statement") parent-bol ,offset)
7879
((parent-is "array_creation_expression") parent-bol ,offset)
7980
((parent-is "base_clause") parent-bol ,offset)
@@ -85,8 +86,7 @@
8586
((parent-is "switch_block") parent-bol ,offset)
8687
((parent-is "case_statement") parent-bol ,offset)
8788
((parent-is "assignment_expression") parent-bol ,offset)
88-
((parent-is "return_statement") parent-bol ,offset)
89-
)))
89+
((parent-is "return_statement") parent-bol ,offset))))
9090
"Tree-sitter indent rules.")
9191

9292
(defvar php-ts-mode--keywords

tests/php-ts-mode-resources/indent.erts

+27
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,30 @@ function ns_func(): void {
6464
return;
6565
}
6666
=-=-=
67+
68+
Name: Function with an attribute
69+
70+
=-=
71+
<?php
72+
73+
namespace Ns;
74+
75+
#[Attribute]
76+
function with_an_attr(): void {
77+
return;
78+
}
79+
=-=-=
80+
81+
Name: Function with two attributes
82+
83+
=-=
84+
<?php
85+
86+
namespace Ns;
87+
88+
#[Attribute]
89+
#[Attribute]
90+
function with_two_attrs(): void {
91+
return;
92+
}
93+
=-=-=

0 commit comments

Comments
 (0)