From df9c2c3df6b069eba4b522c954c244f1acc84521 Mon Sep 17 00:00:00 2001 From: Vynlar Date: Sun, 31 Mar 2024 19:44:17 -0500 Subject: [PATCH 1/2] Begin adding support for gleam --- data/playground/gleam/gleam.gleam | 33 +++++ .../getLanguageScopeSupport.ts | 3 + .../common/src/scopeSupportFacets/gleam.ts | 34 +++++ .../scopes/gleam/anonymousFunction.scope | 15 ++ .../fixtures/scopes/gleam/functionCall.scope | 11 ++ .../scopes/gleam/functionCallee.scope | 14 ++ .../fixtures/scopes/gleam/name.variable.scope | 24 ++++ .../fixtures/scopes/gleam/type.alias.scope | 27 ++++ .../scopes/gleam/value.variable.scope | 21 +++ queries/gleam.scm | 136 ++++++++++++++++++ 10 files changed, 318 insertions(+) create mode 100644 data/playground/gleam/gleam.gleam create mode 100644 packages/common/src/scopeSupportFacets/gleam.ts create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/anonymousFunction.scope create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCall.scope create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCallee.scope create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/name.variable.scope create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/type.alias.scope create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/value.variable.scope create mode 100644 queries/gleam.scm diff --git a/data/playground/gleam/gleam.gleam b/data/playground/gleam/gleam.gleam new file mode 100644 index 0000000000..0dfaf69186 --- /dev/null +++ b/data/playground/gleam/gleam.gleam @@ -0,0 +1,33 @@ +const another_variable: SchoolPerson = 5 + +const b = "allow_world" + +type SchoolPerson { + Teacher(name: String, subject: String) + Student(String) +} + +fn main(hello: String, bre, a) { + io.debug("hello", bre, a) + let a = 3 +} + +pub fn main(a, bre) { + io.debug("hello") + let a = 3 + case a, b { + 3, "a" -> "a" + _, _ -> "a" + } + let bar = fn(a, b) { 3 } + fn hello() -> Nil { + todo + } + let result = hello() +} + +fn foo() { + use foo <- 3 +} + +type Food = Int \ No newline at end of file diff --git a/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts b/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts index 618a9b3dc4..d03eb2ab44 100644 --- a/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts +++ b/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts @@ -4,6 +4,7 @@ import { javascriptScopeSupport } from "./javascript"; import { jsonScopeSupport } from "./json"; import { pythonScopeSupport } from "./python"; import { luaScopeSupport } from "./lua"; +import { gleamScopeSupport } from "./gleam"; import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { talonScopeSupport } from "./talon"; import { typescriptScopeSupport } from "./typescript"; @@ -28,6 +29,8 @@ export function getLanguageScopeSupport( return typescriptScopeSupport; case "lua": return luaScopeSupport; + case "gleam": + return gleamScopeSupport; } throw Error(`Unsupported language: '${languageId}'`); } diff --git a/packages/common/src/scopeSupportFacets/gleam.ts b/packages/common/src/scopeSupportFacets/gleam.ts new file mode 100644 index 0000000000..aeb0606d9c --- /dev/null +++ b/packages/common/src/scopeSupportFacets/gleam.ts @@ -0,0 +1,34 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +const { supported } = ScopeSupportFacetLevel; + +export const gleamScopeSupport: LanguageScopeSupportFacetMap = { + "name.variable": supported, + "value.variable": supported, + functionCallee: supported, + functionCall: supported, + anonymousFunction: supported, + "type.alias": supported, + "type.formalParameter": supported, + "type.variable": supported, + "type.return": supported, + "branch.switchCase": supported, + statement: supported, + "statement.iteration.document": supported, + namedFunction: supported, + list: supported, + functionName: supported, + "argument.actual": supported, + "argument.actual.iteration": supported, + "argument.formal": supported, + "argument.formal.iteration": supported, + "comment.line": supported, + "string.singleLine": supported, + "condition.switchCase": supported, + "name.function": supported, +}; diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/anonymousFunction.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/anonymousFunction.scope new file mode 100644 index 0000000000..0d28302118 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/anonymousFunction.scope @@ -0,0 +1,15 @@ +fn(a,b) { c } + +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| fn(a,b) { c } + +[Interior] = 0:10-0:11 + >-< +0| fn(a,b) { c } + +[Insertion delimiter] = "\n" diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCall.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCall.scope new file mode 100644 index 0000000000..a4c927eed6 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCall.scope @@ -0,0 +1,11 @@ +aaa(bbb) + +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:8 + >--------< +0| aaa(bbb) + +[Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCallee.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCallee.scope new file mode 100644 index 0000000000..83a56cc070 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/functionCallee.scope @@ -0,0 +1,14 @@ +aaa(bbb) + +--- + +[Content] = +[Removal] = 0:0-0:3 + >---< +0| aaa(bbb) + +[Domain] = 0:0-0:8 + >--------< +0| aaa(bbb) + +[Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/name.variable.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/name.variable.scope new file mode 100644 index 0000000000..7d3b63f128 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/name.variable.scope @@ -0,0 +1,24 @@ +let a = 1 +--- + +[Content] = 0:4-0:5 + >-< +0| let a = 1 + +[Removal] = 0:4-0:6 + >--< +0| let a = 1 + +[Leading delimiter] = 0:3-0:4 + >-< +0| let a = 1 + +[Trailing delimiter] = 0:5-0:6 + >-< +0| let a = 1 + +[Domain] = 0:0-0:9 + >---------< +0| let a = 1 + +[Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/type.alias.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/type.alias.scope new file mode 100644 index 0000000000..cd7807ced0 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/type.alias.scope @@ -0,0 +1,27 @@ +type Aaa = Int + +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| type Aaa = Int + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 0:11-0:14 + >---< +0| type Aaa = Int + +[#2 Removal] = 0:10-0:14 + >----< +0| type Aaa = Int + +[#2 Leading delimiter] = 0:10-0:11 + >-< +0| type Aaa = Int + +[#2 Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/value.variable.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/value.variable.scope new file mode 100644 index 0000000000..1ce84c883b --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/gleam/value.variable.scope @@ -0,0 +1,21 @@ +let a = 3 + +--- + +[Content] = 0:8-0:9 + >-< +0| let a = 3 + +[Removal] = 0:7-0:9 + >--< +0| let a = 3 + +[Leading delimiter] = 0:7-0:8 + >-< +0| let a = 3 + +[Domain] = 0:0-0:9 + >---------< +0| let a = 3 + +[Insertion delimiter] = " " diff --git a/queries/gleam.scm b/queries/gleam.scm new file mode 100644 index 0000000000..e55861947a --- /dev/null +++ b/queries/gleam.scm @@ -0,0 +1,136 @@ +;; Statements +[ + (let) + (constant) + (function) + (type_definition) + (function_call) + (case) + (todo) +] @statement + +(constant + value: (_) @value +) @_.domain + +(constant + name: (_) @name @type.leading.endOf + type: (_) @type +) @_.domain + +(let + value: (_) @value +) @_.domain + +(let + pattern: (_) @name +) @_.domain + +(list) @list +(list_pattern) @list + +(data_constructor + name: (_) @name + arguments: (data_constructor_arguments + [ + ;; if there is a key + (data_constructor_argument + label: (_) @argumentOrParameter @value.leading.endOf + value: (_) @value @argumentOrParameter.trailing.startOf + ) @argumentOrParameter.domain + + ;; if there's no key + (data_constructor_argument + value: (_) @argumentOrParameter + ) + ] + ) @type.iteration +) @type + +(type_definition + (type_name) @name +) @type +(type) @type + +(type_alias + (type_name) @name + (type) @value +) @type + +(function + name: (_) @functionName @name + body: (function_body) @namedFunction.interior +) @namedFunction @functionName.domain + +(anonymous_function + body: (_) @anonymousFunction.interior +) @anonymousFunction + +( + (function_parameters + (_)? @argumentOrParameter.leading.endOf + . + (function_parameter) @argumentOrParameter + . + (_)? @argumentOrParameter.trailing.startOf + ) @argumentOrParameter.iteration @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) + +(function_parameter + name: (_) @type.leading.endOf @name + type: (_) @type +) @name.domain + +( + (function_call + function: (_) @functionCallee + arguments: (arguments) + ) @functionCall @functionCallee.domain +) + +( + (arguments + (_)? @_.leading.endOf + . + (argument) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @argumentOrParameter.iteration @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) + +(case_clause + value: (_) @branch.interior +) @branch + +(case_clause + patterns: (case_clause_patterns + (case_clause_pattern + (_) @condition + ) + ) +) @condition.domain + +( + (case_clause + (case_clause_patterns + (_)? @condition.leading.endOf + . + (case_clause_pattern + (_) @condition + ) + . + (_)? @condition.trailing.startOf + ) @_dummy + ) @condition.domain @condition.iteration + (#single-or-multi-line-delimiter! @condition @_dummy ", " ",\n") +) + +(use + value: (_) @value +) @value.domain + +(use + assignments: (use_assignments) @name +) From f904248394bc34ddfc7be42b896c1170146e9c45 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:34:13 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- data/playground/gleam/gleam.gleam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/playground/gleam/gleam.gleam b/data/playground/gleam/gleam.gleam index 0dfaf69186..2097dfe066 100644 --- a/data/playground/gleam/gleam.gleam +++ b/data/playground/gleam/gleam.gleam @@ -30,4 +30,4 @@ fn foo() { use foo <- 3 } -type Food = Int \ No newline at end of file +type Food = Int