diff --git a/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts b/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts index 07d9035a1b..a9e8aadf98 100644 --- a/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts +++ b/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts @@ -7,7 +7,6 @@ import { LegacyLanguageId } from "./LegacyLanguageId"; import { getNodeMatcher } from "./getNodeMatcher"; import { stringTextFragmentExtractor as htmlStringTextFragmentExtractor } from "./html"; import { stringTextFragmentExtractor as jsonStringTextFragmentExtractor } from "./json"; -import { stringTextFragmentExtractor as phpStringTextFragmentExtractor } from "./php"; import { stringTextFragmentExtractor as rubyStringTextFragmentExtractor } from "./ruby"; import { stringTextFragmentExtractor as scssStringTextFragmentExtractor } from "./scss"; import { stringTextFragmentExtractor as typescriptStringTextFragmentExtractor } from "./typescript"; @@ -155,10 +154,6 @@ const textFragmentExtractors: Record< ), latex: fullDocumentTextFragmentExtractor, markdown: fullDocumentTextFragmentExtractor, - php: constructDefaultTextFragmentExtractor( - "php", - phpStringTextFragmentExtractor, - ), ruby: constructDefaultTextFragmentExtractor( "ruby", rubyStringTextFragmentExtractor, diff --git a/packages/cursorless-engine/src/languages/php.ts b/packages/cursorless-engine/src/languages/php.ts index c710a9b50c..9a19538108 100644 --- a/packages/cursorless-engine/src/languages/php.ts +++ b/packages/cursorless-engine/src/languages/php.ts @@ -1,11 +1,7 @@ import { Selection, TextEditor } from "@cursorless/common"; import type { SyntaxNode } from "web-tree-sitter"; import { SimpleScopeTypeType } from "@cursorless/common"; -import { - NodeMatcherAlternative, - SelectionWithContext, - SelectionWithEditor, -} from "../typings/Types"; +import { NodeMatcherAlternative, SelectionWithContext } from "../typings/Types"; import { patternFinder } from "../util/nodeFinders"; import { argumentMatcher, @@ -17,40 +13,6 @@ import { } from "../util/nodeMatchers"; import { getNodeRange } from "../util/nodeSelectors"; -// Generated by the following command: -// > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-php/0ce134234214427b6aeb2735e93a307881c6cd6f/src/node-types.json \ -// | jq '[.[] | select(.type == "_statement") | .subtypes[].type]' -const STATEMENT_TYPES = [ - "break_statement", - "class_declaration", - "compound_statement", - "const_declaration", - "continue_statement", - "declare_statement", - "do_statement", - "echo_statement", - "empty_statement", - "enum_declaration", - "expression_statement", - "for_statement", - "foreach_statement", - "function_definition", - "function_static_declaration", - "global_declaration", - "goto_statement", - "if_statement", - "interface_declaration", - "named_label_statement", - "namespace_definition", - "namespace_use_declaration", - "return_statement", - "switch_statement", - "trait_declaration", - "try_statement", - "unset_statement", - "while_statement", -]; - // Taken from https://www.php.net/manual/en/language.operators.assignment.php const assignmentOperators = [ "=", @@ -101,38 +63,17 @@ function castTypeExtractor( const nodeMatchers: Partial< Record > = { - statement: STATEMENT_TYPES, - ifStatement: "if_statement", - class: "class_declaration", - className: "class_declaration[name]", name: [ "assignment_expression[left]", "class_declaration[name]", "function_definition[name]", "method_declaration[name]", ], - comment: "comment", - string: "string", type: cascadingMatcher( trailingMatcher(["~cast_expression[type]"]), matcher(patternFinder("cast_expression[type]"), castTypeExtractor), ), - namedFunction: trailingMatcher( - [ - "function_definition", - "assignment_expression.anonymous_function_creation_expression", - "assignment_expression.arrow_function", - ], - [";"], - ), - anonymousFunction: [ - "anonymous_function_creation_expression", - "arrow_function", - ], - functionCall: ["function_call_expression", "object_creation_expression"], - functionName: ["function_definition[name]", "method_declaration[name]"], - value: leadingMatcher( [ "array_element_initializer[1]", @@ -149,14 +90,3 @@ const nodeMatchers: Partial< argumentOrParameter: argumentMatcher("arguments", "formal_parameters"), }; export default createPatternMatchers(nodeMatchers); - -export function stringTextFragmentExtractor( - node: SyntaxNode, - _selection: SelectionWithEditor, -) { - if (node.type === "string") { - return getNodeRange(node); - } - - return null; -} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/php/changeFunk2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/php/changeFunk2.yml new file mode 100644 index 0000000000..95170090e1 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/php/changeFunk2.yml @@ -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: |- + 'Hello world'; + selections: + - anchor: {line: 2, character: 24} + active: {line: 2, character: 24} + marks: {} +finalState: + documentContents: | + '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: |+