fix(php): start class_declaration context from name

Fix method_declaration context

Fix for function_definition context

Add test for functions

Test for class and method
This commit is contained in:
przepompownia 2024-03-27 15:30:53 +01:00 committed by Lewis Russell
parent ba05c6b753
commit 29fcd4a9ad
3 changed files with 82 additions and 0 deletions

View file

@ -1,9 +1,11 @@
(function_definition
name: (_) @context.start
body: (_ (_) @context.end)
) @context
(method_declaration
name: (_) @context.start
body: (_ (_) @context.end)
) @context
@ -32,6 +34,7 @@
) @context
(class_declaration
name: (_) @context.start
body: (_ (_) @context.end)
) @context

View file

@ -2,6 +2,7 @@
/*
* comment
*/
#[ReturnTypeWillChange]
function foo($a, $b) {
//loop, between low & high
while ($a <= $b) {
@ -70,11 +71,22 @@ function foo($a, $b) {
return null;
}
#[Attribute]
class Fruit {
#[ReturnTypeWillChange]
public function rot(): void
{
return;
}
// comment

View file

@ -45,6 +45,7 @@ describe('ts_context', function()
"markdown_inline",
"html",
"javascript",
"php",
},
sync_install = true,
}
@ -296,6 +297,72 @@ describe('ts_context', function()
]]}
end)
it('php', function()
cmd('edit test/test.php')
exec_lua [[vim.treesitter.start()]]
feed'7<C-e>'
screen:expect{grid=[[
{1:function}{2: }{3:foo}{14:(}{3:$a}{14:,}{2: }{3:$b}{14:)}{2: }{14:{}{2: }|
{2: }{1:while}{2: }{14:(}{3:$a}{2: }{1:<=}{2: }{3:$b}{14:)}{2: }{14:{}{2: }|
{5:$index} {4:=} {5:$low} {4:+} {5:floor}{15:((}{5:$hi}|
{8:// comment} |
{5:$indexValue} {4:=} {5:$a}{15:;} |
^ {4:if} {15:(}{5:$indexValue} {4:===} {5:$a}{15:)} {15:{} |
{8:// comment} |
|
|
{5:$position} {4:=} {5:$index}{15:;} |
{4:return} {15:(}{9:int}{15:)} {5:$position}{15:;} |
{15:}} |
{4:if} {15:(}{5:$indexValue} {4:<} {5:$key}{15:)} {15:{} |
{8:// comment} |
|
|
]]}
feed'67<C-e>'
screen:expect{grid=[[
{1:class}{2: }{7:Fruit}{2: }{14:{}{2: }|
|
|
|
|
^ {15:#[}ReturnTypeWillChange{15:]} |
{9:public} {4:function} {5:rot}{15:():} {9:voi}|
{15:{} |
|
|
{4:return}{15:;} |
{15:}} |
|
|
|
|
]]}
feed'5<C-e>'
screen:expect{grid=[[
{1:class}{2: }{7:Fruit}{2: }{14:{}{2: }|
{2: }{7:public}{2: }{1:function}{2: }{3:rot}{14:():}{2: }{7:voi}|
{2: }{14:{}{2: }|
|
|
^ {4:return}{15:;} |
{15:}} |
|
|
|
{8:// comment} |
|
|
|
|
|
]]}
end)
it('typescript', function()
cmd('edit test/test.ts')
exec_lua [[vim.treesitter.start()]]