diff --git a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts index 2e79aac77e..92af7be6fb 100644 --- a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts +++ b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts @@ -6,7 +6,6 @@ export const legacyLanguageIds = [ "clojure", "csharp", "css", - "go", "latex", "markdown", "php", diff --git a/packages/cursorless-engine/src/languages/getNodeMatcher.ts b/packages/cursorless-engine/src/languages/getNodeMatcher.ts index f3a1e1cf6f..9f0198ed7e 100644 --- a/packages/cursorless-engine/src/languages/getNodeMatcher.ts +++ b/packages/cursorless-engine/src/languages/getNodeMatcher.ts @@ -11,7 +11,6 @@ import { selectionWithEditorFromRange } from "../util/selectionUtils"; import clojure from "./clojure"; import { LegacyLanguageId } from "./LegacyLanguageId"; import csharp from "./csharp"; -import go from "./go"; import latex from "./latex"; import markdown from "./markdown"; import php from "./php"; @@ -52,7 +51,6 @@ export const languageMatchers: Record< clojure, csharp, css: scss, - go, latex, markdown, php, diff --git a/packages/cursorless-engine/src/languages/go.ts b/packages/cursorless-engine/src/languages/go.ts deleted file mode 100644 index 208d16e222..0000000000 --- a/packages/cursorless-engine/src/languages/go.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { - createPatternMatchers, - argumentMatcher, - conditionMatcher, - cascadingMatcher, - patternMatcher, -} from "../util/nodeMatchers"; -import { NodeMatcherAlternative } from "../typings/Types"; -import { SimpleScopeTypeType } from "@cursorless/common"; - -const nodeMatchers: Partial< - Record -> = { - ifStatement: "if_statement", - functionCall: ["call_expression", "composite_literal"], - functionCallee: ["call_expression[function]", "composite_literal[type]"], - type: [ - "pointer_type", - "qualified_type", - "type_identifier", - "function_declaration[result]", - "method_declaration[result]", - ], - condition: conditionMatcher("*[condition]"), - argumentOrParameter: cascadingMatcher( - argumentMatcher("argument_list", "parameter_list"), - patternMatcher("parameter_declaration"), - patternMatcher("argument_declaration"), - ), - collectionKey: "keyed_element[0]", - value: cascadingMatcher( - patternMatcher("keyed_element[1]"), - patternMatcher("return_statement.expression_list!"), - ), -}; - -export default createPatternMatchers(nodeMatchers); diff --git a/queries/go.scm b/queries/go.scm index 423bd98394..149c05f5d0 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -277,3 +277,94 @@ (if_statement) @branch.iteration (#not-parent-type? @branch.iteration if_statement) ) + +(if_statement) @ifStatement + +[ + (call_expression) + (composite_literal) +] @functionCall + +(call_expression + function: (_) @functionCallee +) @_.domain +(composite_literal + type: (_) @functionCallee +) @_.domain + +(keyed_element + . + (_) @collectionKey + . + (_) @value +) @_.domain + +(return_statement + (expression_list) @value +) @_.domain + +(literal_value) @collectionKey.iteration @value.iteration + +[ + (pointer_type) + (qualified_type) + (type_identifier) +] @type + +(function_declaration + result: (_) @type +) @_.domain +(method_declaration + result: (_) @type +) @_.domain + +;;!! if true {} +( + (_ + condition: (_) @condition + ) @_.domain + (#not-type? @condition parenthesized_expression) +) + +;;!! if (true) {} +( + (_ + condition: (parenthesized_expression) @condition + ) @_.domain + (#child-range! @condition 0 -1 true true) +) + +;;!! func add(x int, y int) int {} +( + (parameter_list + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @_dummy + (#not-type? @argumentOrParameter "comment") + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) + +;;!! add(1, 2) +( + (argument_list + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @_dummy + (#not-type? @argumentOrParameter "comment") + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) + +(parameter_list + "(" @argumentOrParameter.iteration.start.endOf + ")" @argumentOrParameter.iteration.end.startOf +) @argumentOrParameter.iteration.domain +(argument_list + "(" @argumentOrParameter.iteration.start.endOf + ")" @argumentOrParameter.iteration.end.startOf +) @argumentOrParameter.iteration.domain