Skip to content

Commit

Permalink
fix(php): start class_declaration context from name
Browse files Browse the repository at this point in the history
Fix method_declaration context

Fix for function_definition context

Add test for functions

Test for class and method
  • Loading branch information
przepompownia committed Apr 14, 2024
1 parent ba05c6b commit 18fc627
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions queries/php/context.scm
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

(function_definition
name: (_) @context.start
body: (_ (_) @context.end)
) @context

(method_declaration
name: (_) @context.start
body: (_ (_) @context.end)
) @context

Expand Down Expand Up @@ -32,6 +34,7 @@
) @context

(class_declaration
name: (_) @context.start
body: (_ (_) @context.end)
) @context

Expand Down
12 changes: 12 additions & 0 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*
* comment
*/
#[ReturnTypeWillChange]
function foo($a, $b) {
//loop, between low & high
while ($a <= $b) {
Expand Down Expand Up @@ -70,11 +71,22 @@ function foo($a, $b) {
return null;
}

#[Attribute]
class Fruit {




#[ReturnTypeWillChange]
public function rot(): void
{


return;
}



// comment


Expand Down
67 changes: 67 additions & 0 deletions test/ts_context_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('ts_context', function()
"markdown_inline",
"html",
"javascript",
"php",
},
sync_install = true,
}
Expand Down Expand Up @@ -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()]]
Expand Down

0 comments on commit 18fc627

Please sign in to comment.