aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb White <cdwhite3@pm.me>2024-03-16 19:50:13 -0500
committerGitHub <noreply@github.com>2024-03-16 20:50:13 -0400
commit143ca5ce17ae21233101246b5785b90d53aa8329 (patch)
tree3508a12c877818427060c9ae219bd1195454e465
parentfeat(hyprlang): add bash injections (diff)
downloadnvim-treesitter-143ca5ce17ae21233101246b5785b90d53aa8329.tar
nvim-treesitter-143ca5ce17ae21233101246b5785b90d53aa8329.tar.gz
nvim-treesitter-143ca5ce17ae21233101246b5785b90d53aa8329.tar.bz2
nvim-treesitter-143ca5ce17ae21233101246b5785b90d53aa8329.tar.lz
nvim-treesitter-143ca5ce17ae21233101246b5785b90d53aa8329.tar.xz
nvim-treesitter-143ca5ce17ae21233101246b5785b90d53aa8329.tar.zst
nvim-treesitter-143ca5ce17ae21233101246b5785b90d53aa8329.zip
feat(php): improve indents in return statements & chained methods
-rw-r--r--queries/php_only/indents.scm22
-rw-r--r--tests/indent/php/issue-4848.php66
-rw-r--r--tests/indent/php_spec.lua38
3 files changed, 126 insertions, 0 deletions
diff --git a/queries/php_only/indents.scm b/queries/php_only/indents.scm
index a81faed62..9ee04e770 100644
--- a/queries/php_only/indents.scm
+++ b/queries/php_only/indents.scm
@@ -1,7 +1,9 @@
[
(array_creation_expression)
+ (parenthesized_expression)
(compound_statement)
(declaration_list)
+ (member_call_expression)
(binary_expression)
(return_statement)
(arguments)
@@ -12,6 +14,17 @@
(case_statement)
] @indent.begin
+(return_statement
+ [
+ (object_creation_expression)
+ (anonymous_function_creation_expression)
+ (arrow_function)
+ (match_expression)
+ ]) @indent.dedent
+
+(member_call_expression
+ object: (member_call_expression) @indent.branch)
+
[
")"
"}"
@@ -20,9 +33,18 @@
(comment) @indent.auto
+(arguments
+ ")" @indent.end)
+
+(formal_parameters
+ ")" @indent.end)
+
(compound_statement
"}" @indent.end)
+(return_statement
+ ";" @indent.end)
+
(ERROR
"(" @indent.align
.
diff --git a/tests/indent/php/issue-4848.php b/tests/indent/php/issue-4848.php
new file mode 100644
index 000000000..8d112ea14
--- /dev/null
+++ b/tests/indent/php/issue-4848.php
@@ -0,0 +1,66 @@
+<?php
+
+if (
+) {
+}
+
+return (
+);
+
+return true
+ ;
+
+return fn () => (
+);
+
+return fn (
+) => (
+);
+
+return function (
+) {
+};
+
+return function () {
+};
+
+return match (
+) {
+};
+
+return match () {
+};
+
+return new class
+{
+ public function up()
+ {
+ }
+
+ public function down(
+ ) {
+ }
+};
+
+$this->foo()
+ ->bar(
+ )
+ ->baz();
+
+$this->get()
+ ->each(function () {
+ })
+ ->each(
+ function (
+ ) {
+ },
+ );
+
+return $this->get()
+ ->each(function () {
+ })
+ ->each(
+ function (
+ ) {
+ },
+ );
diff --git a/tests/indent/php_spec.lua b/tests/indent/php_spec.lua
index f7067501e..3fc681c29 100644
--- a/tests/indent/php_spec.lua
+++ b/tests/indent/php_spec.lua
@@ -24,5 +24,43 @@ describe("indent PHP:", function()
run:new_line("unfinished-call.php", { on_line = 6, text = "$a =", indent = 4 })
run:new_line("issue-3591.php", { on_line = 4, text = "$a =", indent = 8 })
run:new_line("enum-indent.php", { on_line = 4, text = "case", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 3, text = "true", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 4, text = "return;", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 7, text = "true", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 10, text = "|| false", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 11, text = "$a = 0;", indent = 0 })
+ run:new_line("issue-4848.php", { on_line = 13, text = "true", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 16, text = "$a,", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 17, text = "true", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 20, text = "$a,", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 21, text = "return $a;", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 24, text = "return;", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 27, text = "true", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 28, text = "true => null,", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 31, text = "true => null,", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 35, text = "function a() {}", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 37, text = "return;", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 40, text = "$a,", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 41, text = "return $a;", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 45, text = "->foo()", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 46, text = "$a,", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 47, text = "->foo()", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 48, text = "$a;", indent = 0 })
+ run:new_line("issue-4848.php", { on_line = 50, text = "->foo()", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 51, text = "return $a;", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 52, text = "->foo()", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 53, text = "$a,", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 54, text = "$a,", indent = 12 })
+ run:new_line("issue-4848.php", { on_line = 55, text = "return $a;", indent = 12 })
+ run:new_line("issue-4848.php", { on_line = 56, text = "$a,", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 57, text = "$a;", indent = 0 })
+ run:new_line("issue-4848.php", { on_line = 59, text = "->foo()", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 60, text = "return $a;", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 61, text = "->foo()", indent = 4 })
+ run:new_line("issue-4848.php", { on_line = 62, text = "$a,", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 63, text = "$a,", indent = 12 })
+ run:new_line("issue-4848.php", { on_line = 64, text = "return $a;", indent = 12 })
+ run:new_line("issue-4848.php", { on_line = 65, text = "$a,", indent = 8 })
+ run:new_line("issue-4848.php", { on_line = 66, text = "$a;", indent = 0 })
end)
end)