Skip to content

Commit

Permalink
Move named functions to scm
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanheffley committed Oct 31, 2023
1 parent 929ee4a commit 41b2e63
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 24 deletions.
9 changes: 0 additions & 9 deletions packages/cursorless-engine/src/languages/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,6 @@ const nodeMatchers: Partial<
matcher(patternFinder("cast_expression[type]"), castTypeExtractor),
),

namedFunction: trailingMatcher(
[
"function_definition",
"assignment_expression.anonymous_function_creation_expression",
"assignment_expression.arrow_function",
],
[";"],
),

value: leadingMatcher(
[
"array_element_initializer[1]",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
languageId: php
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
<?php
class MyClass
{
public function helloWorld()
{
}
}
selections:
- anchor: {line: 6, character: 0}
active: {line: 6, character: 0}
marks: {}
finalState:
documentContents: |-
<?php
class MyClass
{
}
selections:
- anchor: {line: 4, character: 4}
active: {line: 4, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: php
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
<?php
$myFunk = function() {
};
selections:
- anchor: {line: 3, character: 0}
active: {line: 3, character: 0}
marks: {}
finalState:
documentContents: |-
<?php
;
selections:
- anchor: {line: 2, character: 0}
active: {line: 2, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: php
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |
<?php
$myFunk = fn() => 'Hello world';
selections:
- anchor: {line: 2, character: 24}
active: {line: 2, character: 24}
marks: {}
finalState:
documentContents: |
<?php
;
selections:
- anchor: {line: 2, character: 0}
active: {line: 2, character: 0}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
languageId: php
command:
version: 1
version: 6
spokenForm: chuck funk
action: remove
targets:
- type: primitive
modifier: {type: containingScope, scopeType: namedFunction, includeSiblings: false}
action:
name: remove
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
<?php
$myFunc = function() {
$myFunk = function() {
};
selections:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
languageId: php
command:
version: 1
version: 6
spokenForm: chuck funk
action: remove
targets:
- type: primitive
modifier: {type: containingScope, scopeType: namedFunction, includeSiblings: false}
action:
name: remove
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
documentContents: |
<?php
$myFunc = fn() => 'Hello world';
$myFunk = fn() => 'Hello world';
selections:
- anchor: {line: 2, character: 25}
active: {line: 2, character: 25}
- anchor: {line: 2, character: 24}
active: {line: 2, character: 24}
marks: {}
finalState:
documentContents: |+
<?php
selections:
- anchor: {line: 2, character: 0}
active: {line: 2, character: 0}
17 changes: 17 additions & 0 deletions queries/php.scm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@
name: (_) @className
) @class @className.domain

[
(function_definition) @namedFunction
(method_declaration) @namedFunction
(expression_statement
(assignment_expression
right: (anonymous_function_creation_expression)
) @namedFunction
";" @_.trailing
)
(expression_statement
(assignment_expression
right: (arrow_function)
) @namedFunction
";" @_.trailing
)
] @namedFunction.domain

[
(anonymous_function_creation_expression)
(arrow_function)
Expand Down

0 comments on commit 41b2e63

Please sign in to comment.