From c2abe003e19ee1f529f1076ec8ba77011627a318 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Fri, 12 Jul 2024 09:52:14 +0200 Subject: [PATCH] Migrate php value scope --- .../recorded/languages/php/changeValue.yml | 28 -------------- .../recorded/languages/php/changeValue2.yml | 28 -------------- .../recorded/languages/php/changeValue3.yml | 28 -------------- .../recorded/languages/php/changeValue4.yml | 28 -------------- .../recorded/languages/php/changeValue5.yml | 28 -------------- .../recorded/languages/php/changeValue6.yml | 28 -------------- .../recorded/languages/php/changeValue7.yml | 28 -------------- .../recorded/languages/php/chuckValue.yml | 28 -------------- .../recorded/languages/php/chuckValue10.yml | 28 -------------- .../recorded/languages/php/chuckValue2.yml | 28 -------------- .../recorded/languages/php/chuckValue3.yml | 28 -------------- .../recorded/languages/php/chuckValue4.yml | 28 -------------- .../recorded/languages/php/chuckValue5.yml | 28 -------------- .../recorded/languages/php/chuckValue6.yml | 28 -------------- .../recorded/languages/php/chuckValue7.yml | 28 -------------- .../recorded/languages/php/chuckValue8.yml | 28 -------------- .../recorded/languages/php/chuckValue9.yml | 28 -------------- data/fixtures/scopes/php/key.mapPair.scope | 21 ++++++++++ .../fixtures/scopes/php/name.assignment.scope | 21 ++++++++++ .../scopes/php/name.assignment2.scope | 21 ++++++++++ data/fixtures/scopes/php/name.variable.scope | 21 ++++++++++ .../scopes/php/value.assignment.scope | 21 ++++++++++ .../scopes/php/value.assignment2.scope | 21 ++++++++++ data/fixtures/scopes/php/value.mapPair.scope | 21 ++++++++++ data/fixtures/scopes/php/value.return.scope | 21 ++++++++++ data/fixtures/scopes/php/value.variable.scope | 21 ++++++++++ data/fixtures/scopes/php/value.yield.scope | 21 ++++++++++ packages/common/src/scopeSupportFacets/php.ts | 11 ++++++ .../cursorless-engine/src/languages/php.ts | 38 +------------------ queries/php.scm | 37 +++++++++++++++++- 30 files changed, 258 insertions(+), 514 deletions(-) delete mode 100644 data/fixtures/recorded/languages/php/changeValue.yml delete mode 100644 data/fixtures/recorded/languages/php/changeValue2.yml delete mode 100644 data/fixtures/recorded/languages/php/changeValue3.yml delete mode 100644 data/fixtures/recorded/languages/php/changeValue4.yml delete mode 100644 data/fixtures/recorded/languages/php/changeValue5.yml delete mode 100644 data/fixtures/recorded/languages/php/changeValue6.yml delete mode 100644 data/fixtures/recorded/languages/php/changeValue7.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue10.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue2.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue3.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue4.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue5.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue6.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue7.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue8.yml delete mode 100644 data/fixtures/recorded/languages/php/chuckValue9.yml create mode 100644 data/fixtures/scopes/php/key.mapPair.scope create mode 100644 data/fixtures/scopes/php/name.assignment.scope create mode 100644 data/fixtures/scopes/php/name.assignment2.scope create mode 100644 data/fixtures/scopes/php/name.variable.scope create mode 100644 data/fixtures/scopes/php/value.assignment.scope create mode 100644 data/fixtures/scopes/php/value.assignment2.scope create mode 100644 data/fixtures/scopes/php/value.mapPair.scope create mode 100644 data/fixtures/scopes/php/value.return.scope create mode 100644 data/fixtures/scopes/php/value.variable.scope create mode 100644 data/fixtures/scopes/php/value.yield.scope diff --git a/data/fixtures/recorded/languages/php/changeValue.yml b/data/fixtures/recorded/languages/php/changeValue.yml deleted file mode 100644 index c19b9adf22..0000000000 --- a/data/fixtures/recorded/languages/php/changeValue.yml +++ /dev/null @@ -1,28 +0,0 @@ -languageId: php -command: - version: 5 - spokenForm: change value - action: {name: clearAndSetSelection} - targets: - - type: primitive - modifiers: - - type: containingScope - scopeType: {type: value} - usePrePhraseSnapshot: false -initialState: - documentContents: |- - 1]; - selections: - - anchor: {line: 2, character: 9} - active: {line: 2, character: 9} - marks: {} -finalState: - documentContents: |- - ]; - selections: - - anchor: {line: 2, character: 10} - active: {line: 2, character: 10} diff --git a/data/fixtures/recorded/languages/php/changeValue2.yml b/data/fixtures/recorded/languages/php/changeValue2.yml deleted file mode 100644 index 01036fe422..0000000000 --- a/data/fixtures/recorded/languages/php/changeValue2.yml +++ /dev/null @@ -1,28 +0,0 @@ -languageId: php -command: - version: 5 - spokenForm: change value - action: {name: clearAndSetSelection} - targets: - - type: primitive - modifiers: - - type: containingScope - scopeType: {type: value} - usePrePhraseSnapshot: false -initialState: - documentContents: |- - 1]; - selections: - - anchor: {line: 2, character: 3} - active: {line: 2, character: 3} - marks: {} -finalState: - documentContents: |- - ]; - selections: - - anchor: {line: 2, character: 10} - active: {line: 2, character: 10} diff --git a/data/fixtures/recorded/languages/php/changeValue6.yml b/data/fixtures/recorded/languages/php/changeValue6.yml deleted file mode 100644 index 202292f65a..0000000000 --- a/data/fixtures/recorded/languages/php/changeValue6.yml +++ /dev/null @@ -1,28 +0,0 @@ -languageId: php -command: - version: 5 - spokenForm: change value - action: {name: clearAndSetSelection} - targets: - - type: primitive - modifiers: - - type: containingScope - scopeType: {type: value} - usePrePhraseSnapshot: false -initialState: - documentContents: |- - 1]; - selections: - - anchor: {line: 2, character: 9} - active: {line: 2, character: 9} - marks: {} -finalState: - documentContents: |- - 1]; - selections: - - anchor: {line: 2, character: 3} - active: {line: 2, character: 3} - marks: {} -finalState: - documentContents: |- - 1]; +--- + +[Content] = 1:1-1:6 + >-----< +1| ['num' => 1]; + +[Removal] = 1:1-1:10 + >---------< +1| ['num' => 1]; + +[Trailing delimiter] = 1:6-1:10 + >----< +1| ['num' => 1]; + +[Domain] = 1:1-1:11 + >----------< +1| ['num' => 1]; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/name.assignment.scope b/data/fixtures/scopes/php/name.assignment.scope new file mode 100644 index 0000000000..48e6748c89 --- /dev/null +++ b/data/fixtures/scopes/php/name.assignment.scope @@ -0,0 +1,21 @@ +------< +1| $value = 2; + +[Removal] = 1:0-1:7 + >-------< +1| $value = 2; + +[Trailing delimiter] = 1:6-1:7 + >-< +1| $value = 2; + +[Domain] = 1:0-1:10 + >----------< +1| $value = 2; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/name.assignment2.scope b/data/fixtures/scopes/php/name.assignment2.scope new file mode 100644 index 0000000000..1b7b07952f --- /dev/null +++ b/data/fixtures/scopes/php/name.assignment2.scope @@ -0,0 +1,21 @@ +------< +1| $value += 2; + +[Removal] = 1:0-1:7 + >-------< +1| $value += 2; + +[Trailing delimiter] = 1:6-1:7 + >-< +1| $value += 2; + +[Domain] = 1:0-1:11 + >-----------< +1| $value += 2; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/name.variable.scope b/data/fixtures/scopes/php/name.variable.scope new file mode 100644 index 0000000000..48e6748c89 --- /dev/null +++ b/data/fixtures/scopes/php/name.variable.scope @@ -0,0 +1,21 @@ +------< +1| $value = 2; + +[Removal] = 1:0-1:7 + >-------< +1| $value = 2; + +[Trailing delimiter] = 1:6-1:7 + >-< +1| $value = 2; + +[Domain] = 1:0-1:10 + >----------< +1| $value = 2; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/value.assignment.scope b/data/fixtures/scopes/php/value.assignment.scope new file mode 100644 index 0000000000..af2d33face --- /dev/null +++ b/data/fixtures/scopes/php/value.assignment.scope @@ -0,0 +1,21 @@ +-< +1| $value = 2; + +[Removal] = 1:6-1:10 + >----< +1| $value = 2; + +[Leading delimiter] = 1:6-1:9 + >---< +1| $value = 2; + +[Domain] = 1:0-1:10 + >----------< +1| $value = 2; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/value.assignment2.scope b/data/fixtures/scopes/php/value.assignment2.scope new file mode 100644 index 0000000000..2a5ef68f37 --- /dev/null +++ b/data/fixtures/scopes/php/value.assignment2.scope @@ -0,0 +1,21 @@ +-< +1| $value += 2; + +[Removal] = 1:6-1:11 + >-----< +1| $value += 2; + +[Leading delimiter] = 1:6-1:10 + >----< +1| $value += 2; + +[Domain] = 1:0-1:11 + >-----------< +1| $value += 2; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/value.mapPair.scope b/data/fixtures/scopes/php/value.mapPair.scope new file mode 100644 index 0000000000..48aea39d02 --- /dev/null +++ b/data/fixtures/scopes/php/value.mapPair.scope @@ -0,0 +1,21 @@ + 1]; +--- + +[Content] = 1:10-1:11 + >-< +1| ['num' => 1]; + +[Removal] = 1:6-1:11 + >-----< +1| ['num' => 1]; + +[Leading delimiter] = 1:6-1:10 + >----< +1| ['num' => 1]; + +[Domain] = 1:1-1:11 + >----------< +1| ['num' => 1]; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/value.return.scope b/data/fixtures/scopes/php/value.return.scope new file mode 100644 index 0000000000..7579bb7450 --- /dev/null +++ b/data/fixtures/scopes/php/value.return.scope @@ -0,0 +1,21 @@ +-< +1| return 2; + +[Removal] = 1:6-1:8 + >--< +1| return 2; + +[Leading delimiter] = 1:6-1:7 + >-< +1| return 2; + +[Domain] = 1:0-1:9 + >---------< +1| return 2; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/value.variable.scope b/data/fixtures/scopes/php/value.variable.scope new file mode 100644 index 0000000000..af2d33face --- /dev/null +++ b/data/fixtures/scopes/php/value.variable.scope @@ -0,0 +1,21 @@ +-< +1| $value = 2; + +[Removal] = 1:6-1:10 + >----< +1| $value = 2; + +[Leading delimiter] = 1:6-1:9 + >---< +1| $value = 2; + +[Domain] = 1:0-1:10 + >----------< +1| $value = 2; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/php/value.yield.scope b/data/fixtures/scopes/php/value.yield.scope new file mode 100644 index 0000000000..98c90414a3 --- /dev/null +++ b/data/fixtures/scopes/php/value.yield.scope @@ -0,0 +1,21 @@ +-< +1| yield 2; + +[Removal] = 1:5-1:7 + >--< +1| yield 2; + +[Leading delimiter] = 1:5-1:6 + >-< +1| yield 2; + +[Domain] = 1:0-1:7 + >-------< +1| yield 2; + +[Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/php.ts b/packages/common/src/scopeSupportFacets/php.ts index 36c3a0e5e9..ebb77f4fee 100644 --- a/packages/common/src/scopeSupportFacets/php.ts +++ b/packages/common/src/scopeSupportFacets/php.ts @@ -10,4 +10,15 @@ export const phpScopeSupport: LanguageScopeSupportFacetMap = { "comment.line": supported, "comment.block": supported, "textFragment.string.singleLine": supported, + + "name.variable": supported, + "name.assignment": supported, + + "key.mapPair": supported, + + "value.variable": supported, + "value.assignment": supported, + "value.mapPair": supported, + "value.return": supported, + "value.yield": supported, }; diff --git a/packages/cursorless-engine/src/languages/php.ts b/packages/cursorless-engine/src/languages/php.ts index 72b3defebc..e8a2a7642d 100644 --- a/packages/cursorless-engine/src/languages/php.ts +++ b/packages/cursorless-engine/src/languages/php.ts @@ -1,39 +1,16 @@ -import { Selection, TextEditor } from "@cursorless/common"; +import { Selection, SimpleScopeTypeType, TextEditor } from "@cursorless/common"; import type { SyntaxNode } from "web-tree-sitter"; -import { SimpleScopeTypeType } from "@cursorless/common"; import { NodeMatcherAlternative, SelectionWithContext } from "../typings/Types"; import { patternFinder } from "../util/nodeFinders"; import { argumentMatcher, cascadingMatcher, createPatternMatchers, - leadingMatcher, matcher, trailingMatcher, } from "../util/nodeMatchers"; import { getNodeRange } from "../util/nodeSelectors"; -// Taken from https://www.php.net/manual/en/language.operators.assignment.php -const assignmentOperators = [ - "=", - // Arithmetic - "+=", - "-=", - "*=", - "/=", - "%=", - "**=", - // Bitwise - "&=", - "|=", - "^=", - "<<=", - ">>=", - // Other - ".=", - "??=", -]; - /** * Given a node representing the text of a type cast, will return the * content range as the text inner type, and the outside range includes @@ -68,19 +45,6 @@ const nodeMatchers: Partial< matcher(patternFinder("cast_expression[type]"), castTypeExtractor), ), - value: leadingMatcher( - [ - "array_element_initializer[1]", - "assignment_expression[right]", - "augmented_assignment_expression[right]", - "return_statement[0]", - "yield_expression[0]", - ], - assignmentOperators.concat(["=>"]), - ), - - collectionKey: trailingMatcher(["array_element_initializer[0]"], ["=>"]), - argumentOrParameter: argumentMatcher("arguments", "formal_parameters"), }; export default createPatternMatchers(nodeMatchers); diff --git a/queries/php.scm b/queries/php.scm index 18847739cc..a398257497 100644 --- a/queries/php.scm +++ b/queries/php.scm @@ -107,9 +107,22 @@ (object_creation_expression) ] @functionCall +;;!! $value = 2; +;;! ^^^^^^ +;;! ^ (assignment_expression - left: (_) @name + left: (_) @name @value.leading.endOf + right: (_) @value ) @_.domain + +;;!! $value += 2; +;;! ^^^^^^ +;;! ^ +(augmented_assignment_expression + left: (_) @name @value.leading.endOf + right: (_) @value +) @_.domain + (class_declaration name: (_) @name ) @_.domain @@ -119,3 +132,25 @@ (method_declaration name: (_) @name ) @_.domain + +;;!! ['num' => 1]; +;;! ^^^^^ +;;! ^ +(array_element_initializer + (_) @collectionKey @value.leading.endOf + (_) @value @collectionKey.trailing.startOf +) @_.domain + +;;!! return 2; +;;! ^ +(return_statement + "return" @_.leading.endOf + (_) @value +) @_.domain + +;;!! yield 2; +;;! ^ +(yield_expression + "yield" @_.leading.endOf + (_) @value +) @_.domain