aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb White <cdwhite3@pm.me>2024-08-18 05:30:04 -0500
committerGitHub <noreply@github.com>2024-08-18 12:30:04 +0200
commitec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631 (patch)
treec7ba6a551dc8fa364104378872d2cad5ff0b6d9b
parentbot(lockfile): update go, html, json, python, rust, swift, vhs (diff)
downloadnvim-treesitter-ec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631.tar
nvim-treesitter-ec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631.tar.gz
nvim-treesitter-ec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631.tar.bz2
nvim-treesitter-ec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631.tar.lz
nvim-treesitter-ec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631.tar.xz
nvim-treesitter-ec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631.tar.zst
nvim-treesitter-ec8776ed9ef56ffe7a61e67b64d5d6b6aba2c631.zip
feat(php): php 8.4 support (#6741)
* chore(php): update maintainers * feat(php): update php rules, highlight imported functions/consts * feat(php): indent inside property hooks * chore: update php and php_only revision
-rw-r--r--README.md4
-rw-r--r--lockfile.json4
-rw-r--r--lua/nvim-treesitter/parsers.lua4
-rw-r--r--queries/php_only/highlights.scm25
-rw-r--r--queries/php_only/indents.scm6
-rw-r--r--queries/php_only/locals.scm2
-rw-r--r--tests/indent/php/property-hooks.php13
-rw-r--r--tests/indent/php_spec.lua5
-rw-r--r--tests/query/highlights/php/keywords.php35
9 files changed, 85 insertions, 13 deletions
diff --git a/README.md b/README.md
index 8e2e992bb..721816dcc 100644
--- a/README.md
+++ b/README.md
@@ -343,8 +343,8 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [passwd](https://github.com/ath3/tree-sitter-passwd) (maintained by @amaanq)
- [x] [pem](https://github.com/ObserverOfTime/tree-sitter-pem) (maintained by @ObserverOfTime)
- [x] [perl](https://github.com/tree-sitter-perl/tree-sitter-perl) (maintained by @RabbiVeesh, @LeoNerd)
-- [x] [php](https://github.com/tree-sitter/tree-sitter-php) (maintained by @tk-shirasaka)
-- [x] [php_only](https://github.com/tree-sitter/tree-sitter-php) (maintained by @tk-shirasaka)
+- [x] [php](https://github.com/tree-sitter/tree-sitter-php) (maintained by @tk-shirasaka, @calebdw)
+- [x] [php_only](https://github.com/tree-sitter/tree-sitter-php) (maintained by @tk-shirasaka, @calebdw)
- [x] [phpdoc](https://github.com/claytonrcarter/tree-sitter-phpdoc) (experimental, maintained by @mikehaertl)
- [x] [pioasm](https://github.com/leo60228/tree-sitter-pioasm) (maintained by @leo60228)
- [x] [po](https://github.com/erasin/tree-sitter-po) (maintained by @amaanq)
diff --git a/lockfile.json b/lockfile.json
index 7d2b220e2..decd07eb9 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -510,10 +510,10 @@
"revision": "3a21d9cb2a20a062c17f8f53d5983fd473c4673c"
},
"php": {
- "revision": "c07d69739ba71b5a449bdbb7735991f8aabf8546"
+ "revision": "71605bf96303144c2ecfc2c0b69d95c716ed9e13"
},
"php_only": {
- "revision": "c07d69739ba71b5a449bdbb7735991f8aabf8546"
+ "revision": "71605bf96303144c2ecfc2c0b69d95c716ed9e13"
},
"phpdoc": {
"revision": "1d0e255b37477d0ca46f1c9e9268c8fa76c0b3fc"
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 77e059841..67fdb418c 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -1495,7 +1495,7 @@ list.php = {
location = "php",
files = { "src/parser.c", "src/scanner.c" },
},
- maintainers = { "@tk-shirasaka" },
+ maintainers = { "@tk-shirasaka", "@calebdw" },
}
list.php_only = {
@@ -1504,7 +1504,7 @@ list.php_only = {
location = "php_only",
files = { "src/parser.c", "src/scanner.c" },
},
- maintainers = { "@tk-shirasaka" },
+ maintainers = { "@tk-shirasaka", "@calebdw" },
}
-- Parsers for injections
diff --git a/queries/php_only/highlights.scm b/queries/php_only/highlights.scm
index 2b9e4ea95..790bd088f 100644
--- a/queries/php_only/highlights.scm
+++ b/queries/php_only/highlights.scm
@@ -221,10 +221,26 @@
(name) @type
(qualified_name
(name) @type)
+ alias: (name) @type.definition
])
-(namespace_aliasing_clause
- (name) @type.definition)
+(namespace_use_clause
+ type: "function"
+ [
+ (name) @function
+ (qualified_name
+ (name) @function)
+ alias: (name) @function
+ ])
+
+(namespace_use_clause
+ type: "const"
+ [
+ (name) @constant
+ (qualified_name
+ (name) @constant)
+ alias: (name) @constant
+ ])
(class_interface_clause
[
@@ -369,9 +385,8 @@
name: (namespace_name
(name) @module))
-(namespace_name_as_prefix
- (namespace_name
- (name) @module))
+(namespace_name
+ (name) @module)
; Attributes
(attribute_list) @attribute
diff --git a/queries/php_only/indents.scm b/queries/php_only/indents.scm
index fef026757..1755d4285 100644
--- a/queries/php_only/indents.scm
+++ b/queries/php_only/indents.scm
@@ -13,12 +13,13 @@
(match_block)
(case_statement)
(default_statement)
+ (property_hook_list)
] @indent.begin
(return_statement
[
(object_creation_expression)
- (anonymous_function_creation_expression)
+ (anonymous_function)
(arrow_function)
(match_expression)
]) @indent.dedent
@@ -49,6 +50,9 @@
(return_statement
";" @indent.end)
+(property_hook_list
+ "}" @indent.end)
+
(ERROR
"(" @indent.align
.
diff --git a/queries/php_only/locals.scm b/queries/php_only/locals.scm
index aff2b3dae..6739b383d 100644
--- a/queries/php_only/locals.scm
+++ b/queries/php_only/locals.scm
@@ -12,7 +12,7 @@
name: (name) @local.definition.function) @local.scope
(#set! definition.function.scope "parent"))
-(anonymous_function_creation_expression
+(anonymous_function
(anonymous_function_use_clause
(variable_name
(name) @local.definition.var))) @local.scope
diff --git a/tests/indent/php/property-hooks.php b/tests/indent/php/property-hooks.php
new file mode 100644
index 000000000..e4aea4fdd
--- /dev/null
+++ b/tests/indent/php/property-hooks.php
@@ -0,0 +1,13 @@
+<?php
+
+class Foo
+{
+ private string $_baz;
+
+ public string $baz {
+ &get => $this->_baz;
+ set {
+ $this->_baz = strtoupper($value);
+ }
+ }
+}
diff --git a/tests/indent/php_spec.lua b/tests/indent/php_spec.lua
index 2a41079ff..c3f84e6e2 100644
--- a/tests/indent/php_spec.lua
+++ b/tests/indent/php_spec.lua
@@ -67,5 +67,10 @@ describe("indent PHP:", function()
run:new_line("issue-6888.php", { on_line = 6, text = "$a;", indent = 0 })
run:new_line("issue-6888.php", { on_line = 8, text = "$a;", indent = 4 })
run:new_line("issue-6888.php", { on_line = 11, text = "$a;", indent = 0 })
+ run:new_line("property-hooks.php", { on_line = 7, text = "get;", indent = 8 })
+ run:new_line("property-hooks.php", { on_line = 8, text = "set;", indent = 8 })
+ run:new_line("property-hooks.php", { on_line = 9, text = "$a;", indent = 12 })
+ run:new_line("property-hooks.php", { on_line = 11, text = "get;", indent = 8 })
+ run:new_line("property-hooks.php", { on_line = 12, text = "get;", indent = 4 })
end)
end)
diff --git a/tests/query/highlights/php/keywords.php b/tests/query/highlights/php/keywords.php
index f3d3f95a7..6b938c43f 100644
--- a/tests/query/highlights/php/keywords.php
+++ b/tests/query/highlights/php/keywords.php
@@ -1,5 +1,40 @@
<?php
+namespace Foo\Bar;
+//^^^^^^^ @keyword.type
+// ^^^ @module
+// ^^^ @module
+
+use Foo\Baz as Baaz;
+//^ @keyword.import
+// ^^^ @module
+// ^^^ @type
+// ^^ @keyword.operator
+// ^^^^ @type.definition
+
+use function Foo\foo as fooo;
+// ^^^^^^^^ @keyword.function
+// ^^^ @function
+// ^^^^ @function
+
+use const Foo\FOO as FOOO;
+// ^^^^^ @keyword.modifier
+// ^^^ @constant
+// ^^^^ @constant
+
+use Foo\Baz\{
+// ^^^ @module
+// ^^^ @module
+ Bar,
+//^^^ @type
+ function foo,
+//^^^^^^^^ @keyword.function
+// ^^^ @function
+ const FOO,
+//^^^^^ @keyword.modifier
+// ^^^ @constant
+};
+
abstract class A
{
protected readonly static $a;