diff --git a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts index 1b33483e8b..48930a0b82 100644 --- a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts +++ b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts @@ -2,12 +2,6 @@ * The language IDs that we have full tree-sitter support for using our legacy * modifiers. */ -export const legacyLanguageIds = [ - "clojure", - "latex", - "ruby", - "rust", - "scala", -] as const; +export const legacyLanguageIds = ["clojure", "latex", "ruby", "rust"] as const; export type LegacyLanguageId = (typeof legacyLanguageIds)[number]; diff --git a/packages/cursorless-engine/src/languages/getNodeMatcher.ts b/packages/cursorless-engine/src/languages/getNodeMatcher.ts index e7b2b5f40a..1eccabd85e 100644 --- a/packages/cursorless-engine/src/languages/getNodeMatcher.ts +++ b/packages/cursorless-engine/src/languages/getNodeMatcher.ts @@ -13,7 +13,6 @@ import type { LegacyLanguageId } from "./LegacyLanguageId"; import latex from "./latex"; import { patternMatchers as ruby } from "./ruby"; import rust from "./rust"; -import scala from "./scala"; export function getNodeMatcher( languageId: string, @@ -47,7 +46,6 @@ export const languageMatchers: Record< latex, ruby, rust, - scala, }; function matcherIncludeSiblings(matcher: NodeMatcher): NodeMatcher { diff --git a/packages/cursorless-engine/src/languages/scala.ts b/packages/cursorless-engine/src/languages/scala.ts deleted file mode 100644 index 86dcb4f896..0000000000 --- a/packages/cursorless-engine/src/languages/scala.ts +++ /dev/null @@ -1,86 +0,0 @@ -import type { SimpleScopeTypeType } from "@cursorless/common"; -import type { NodeMatcherAlternative } from "../typings/Types"; -import { patternFinder } from "../util/nodeFinders"; -import { - argumentMatcher, - createPatternMatchers, - leadingMatcher, - matcher, -} from "../util/nodeMatchers"; -import { childRangeSelector } from "../util/nodeSelectors"; - -const nodeMatchers: Partial< - Record -> = { - argumentOrParameter: argumentMatcher( - "arguments", - "parameters", - "class_parameters", - "bindings", - ), - branch: matcher( - patternFinder("case_clause"), - childRangeSelector([], [], { - includeUnnamedChildren: true, - }), - ), - - // *[type] does not work here because while we want most of these we don't want "compound" types, - // eg `generic_type[type]`, because that will grab just the inner generic (the String of List[String]) - // and as a rule we want to grab entire type definitions. - type: leadingMatcher( - [ - "upper_bound[type]", - "lower_bound[type]", - "view_bound[type]", - "context_bound[type]", - "val_definition[type]", - "val_declaration[type]", - "var_definition[type]", - "var_declaration[type]", - "type_definition", - "extends_clause[type]", - "class_parameter[type]", - "parameter[type]", - "function_definition[return_type]", - "typed_pattern[type]", - "binding[type]", - ], - [":"], - ), - value: leadingMatcher( - ["*[value]", "*[default_value]", "type_definition[type]"], - ["="], - ), - - // Scala features unsupported in Cursorless terminology - // - Pattern matching - - // Cursorless terminology not yet supported in this Scala implementation - /* - lists and maps basic definition are just function calls to constructors, eg List(1,2,3,4) - These types are also basically arbitrary, so we can't really hard-code them - There is also fancy list style: val foo = 1 :: (2 :: (3 :: Nil)) // List(1,2,3) - */ - // list: 'call_expression', - // map: 'call_expression', - - /* infix_expression, key on left, item on right, operator = "->" - // collectionItem: "???" - // collectionKey: "???", - - /* "foo".r <-, value of type field_expression, value of type string, field of type identifier = "r", - // regularExpression: "???", - - /* - none of this stuff is defined well in the tree sitter (it's all just infix expressions etc), - and native XML/HTML is deprecated in Scala 3 - */ - // attribute: "???", - // xmlElement: "???", - // xmlStartTag: "???", - // xmlEndTag: "???", - // xmlBothTags: "???", -}; - -export default createPatternMatchers(nodeMatchers); diff --git a/queries/scala.scm b/queries/scala.scm index 8f90ea34e7..f1e6e46f0d 100644 --- a/queries/scala.scm +++ b/queries/scala.scm @@ -54,6 +54,123 @@ ) ) @_.domain +;;!! type Vector = (Int, Int) +;;! ^^^^^^^^^^ +(type_definition + name: (_) @_.leading.endOf + type: (_) @value +) @_.domain + +;;!! class Example(foo: String = "foo") {} +;;! ^^^^^ +(_ + (_) @_.leading.endOf + . + default_value: (_) @value +) @_.domain + +;;!! val bar = "bar" +;;! ^^^^^ +(_ + (_) @_.leading.endOf + . + value: (_) @value +) @_.domain + +;;!! type Vector = (Int, Int) +;;! ^^^^^^^^^^^^^^^^^^^^^^^^ +(type_definition) @type + +;;!! def str(bar: String) +;;! ^^^^^^ +;;!! val foo: String = "foo" +;;! ^^^^^^ +( + (_ + (_) @_.leading.endOf + . + type: (_) @type + ) @_.domain + (#not-type? @_.domain type_definition) +) + +;;!! def str(): String = "bar" +;;! ^^^^^^ +(function_definition + (parameters) @_.leading.endOf + return_type: (_) @type +) @_.domain + +;;!! case 0 => "zero" +;;! ^^^^^^^^^^^^^^^^ +( + (case_clause) @branch + (#trim-end! @branch) +) + +;;!! class Foo(aaa: Int, bbb: Int) {} +;;! ^^^^^^^^ ^^^^^^^^ +( + (class_parameters + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) + +;;!! def foo(aaa: Int, bbb: Int) = x +;;! ^^^^^^^^ ^^^^^^^^ +( + (parameters + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) + +;;!! foo(aaa, bbb) +;;! ^^^ ^^^ +( + (arguments + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) + +(_ + (class_parameters + "(" @argumentList.start.endOf @argumentOrParameter.iteration.start.endOf + ")" @argumentList.end.startOf @argumentOrParameter.iteration.end.startOf + ) @_dummy + (#empty-single-multi-delimiter! @argumentList.start.endOf @_dummy "" ", " ",\n") +) @argumentList.domain @argumentOrParameter.iteration.domain + +(_ + (parameters + "(" @argumentList.start.endOf @argumentOrParameter.iteration.start.endOf + ")" @argumentList.end.startOf @argumentOrParameter.iteration.end.startOf + ) @_dummy + (#empty-single-multi-delimiter! @argumentList.start.endOf @_dummy "" ", " ",\n") +) @argumentList.domain @argumentOrParameter.iteration.domain + +(_ + (arguments + "(" @argumentList.start.endOf @argumentOrParameter.iteration.start.endOf + ")" @argumentList.end.startOf @argumentOrParameter.iteration.end.startOf + ) @_dummy + (#empty-single-multi-delimiter! @argumentList.start.endOf @_dummy "" ", " ",\n") +) @argumentList.domain @argumentOrParameter.iteration.domain + operator: (operator_identifier) @disqualifyDelimiter (enumerator "<-" @disqualifyDelimiter