From c0285d96ff84dd75672d6caebf9148a34e8ce7f5 Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Fri, 14 Jan 2022 15:16:58 -0600 Subject: [PATCH 1/3] Add Elm language support --- .gitmodules | 4 ++ helix-syntax/languages/tree-sitter-elm | 1 + languages.toml | 11 ++++ runtime/queries/elm/highlights.scm | 88 ++++++++++++++++++++++++++ runtime/queries/elm/injections.scm | 4 ++ runtime/queries/elm/locals.scm | 14 ++++ runtime/queries/elm/tags.scm | 19 ++++++ 7 files changed, 141 insertions(+) create mode 160000 helix-syntax/languages/tree-sitter-elm create mode 100644 runtime/queries/elm/highlights.scm create mode 100644 runtime/queries/elm/injections.scm create mode 100644 runtime/queries/elm/locals.scm create mode 100644 runtime/queries/elm/tags.scm diff --git a/.gitmodules b/.gitmodules index 3442652a65a2..b7bfe76f8a0f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -202,3 +202,7 @@ path = helix-syntax/languages/tree-sitter-git-config url = https://github.com/the-mikedavis/tree-sitter-git-config.git shallow = true +[submodule "helix-syntax/languages/tree-sitter-elm"] + path = helix-syntax/languages/tree-sitter-elm + url = https://github.com/elm-tooling/tree-sitter-elm + shallow = true diff --git a/helix-syntax/languages/tree-sitter-elm b/helix-syntax/languages/tree-sitter-elm new file mode 160000 index 000000000000..bd50ccf66b42 --- /dev/null +++ b/helix-syntax/languages/tree-sitter-elm @@ -0,0 +1 @@ +Subproject commit bd50ccf66b42c55252ac8efc1086af4ac6bab8cd diff --git a/languages.toml b/languages.toml index 2c870ab24c0d..adacaaac3403 100644 --- a/languages.toml +++ b/languages.toml @@ -555,3 +555,14 @@ file-types = [".gitmodules", ".gitconfig"] injection-regex = "git-config" comment-token = "#" indent = { tab-width = 4, unit = "\t" } + +[[language]] +name = "elm" +scope = "source.elm" +injection-regex = "elm" +file-types = ["elm"] +roots = ["elm.json"] +auto-format = true +comment-token = "--" +language-server = { command = "elm-language-server" } +indent = { tab-width = 4, unit = " " } diff --git a/runtime/queries/elm/highlights.scm b/runtime/queries/elm/highlights.scm new file mode 100644 index 000000000000..06894a4445f4 --- /dev/null +++ b/runtime/queries/elm/highlights.scm @@ -0,0 +1,88 @@ +; Keywords +[ + "if" + "then" + "else" + "let" + "in" + ] @keyword.control +(case) @keyword.control +(of) @keyword.control + +(colon) @keyword.operator +(backslash) @keyword +(as) @keyword +(port) @keyword +(exposing) @keyword +(alias) @keyword +(infix) @keyword + +(arrow) @keyword.operator +(dot) @keyword.operator + +(port) @keyword + +(type_annotation(lower_case_identifier) @function) +(port_annotation(lower_case_identifier) @function) +(file (value_declaration (function_declaration_left(lower_case_identifier) @function))) + +(field name: (lower_case_identifier) @attribute) +(field_access_expr(lower_case_identifier) @attribute) + +(operator_identifier) @keyword.operator +(eq) @keyword.operator.assignment + + +"(" @punctuation.braces +")" @punctuation.braces + +"[" @punctuation.braces +"]" @punctuation.braces + +"{" @punctuation.braces +"}" @punctuation.braces + +"|" @keyword +"," @punctuation.delimiter + +[ + "|>" +] @keyword + + +(import) @keyword.other +(module) @keyword.other + +(number_constant_expr) @constant.numeric + +(type) @type + +(type_declaration(upper_case_identifier) @type) +(type_ref) @type +(type_alias_declaration name: (upper_case_identifier) @type) + +(union_pattern constructor: (upper_case_qid (upper_case_identifier) @label (dot) (upper_case_identifier) @variable.other.member)) +(union_pattern constructor: (upper_case_qid (upper_case_identifier) @variable.other.member)) + +(union_variant(upper_case_identifier) @variable.other.member) +(value_expr name: (value_qid (upper_case_identifier) @label)) +(value_expr (upper_case_qid (upper_case_identifier) @label (dot) (upper_case_identifier) @variable.other.member)) +(value_expr(upper_case_qid(upper_case_identifier)) @variable.other.member) + +; comments +(line_comment) @comment +(block_comment) @comment + +; strings +(string_escape) @constant.character + +(open_quote) @string +(close_quote) @string +(regular_string_part) @string + +(open_char) @constant.character +(close_char) @constant.character + + +; glsl +(glsl_content) @source.glsl diff --git a/runtime/queries/elm/injections.scm b/runtime/queries/elm/injections.scm new file mode 100644 index 000000000000..83f8245caa2b --- /dev/null +++ b/runtime/queries/elm/injections.scm @@ -0,0 +1,4 @@ +; Parse glsl where defined + +((glsl_content) @injection.content + (#set! injection.language "glsl")) diff --git a/runtime/queries/elm/locals.scm b/runtime/queries/elm/locals.scm new file mode 100644 index 000000000000..ab1031156c6a --- /dev/null +++ b/runtime/queries/elm/locals.scm @@ -0,0 +1,14 @@ +(value_declaration) @local.scope +(type_alias_declaration) @local.scope +(type_declaration) @local.scope +(type_annotation) @local.scope +(port_annotation) @local.scope +(infix_declaration) @local.scope +(let_in_expr) @local.scope + +(function_declaration_left (lower_pattern (lower_case_identifier)) @local.definition) +(function_declaration_left (lower_case_identifier) @local.definition) + +(value_expr(value_qid(upper_case_identifier)) @local.reference) +(value_expr(value_qid(lower_case_identifier)) @local.reference) +(type_ref (upper_case_qid) @local.reference) diff --git a/runtime/queries/elm/tags.scm b/runtime/queries/elm/tags.scm new file mode 100644 index 000000000000..03999fb17312 --- /dev/null +++ b/runtime/queries/elm/tags.scm @@ -0,0 +1,19 @@ +(value_declaration (function_declaration_left (lower_case_identifier) @name)) @definition.function + +(function_call_expr (value_expr (value_qid) @name)) @reference.function +(exposed_value (lower_case_identifier) @name) @reference.function +(type_annotation ((lower_case_identifier) @name) (colon)) @reference.function + +(type_declaration ((upper_case_identifier) @name) ) @definition.type + +(type_ref (upper_case_qid (upper_case_identifier) @name)) @reference.type +(exposed_type (upper_case_identifier) @name) @reference.type + +(type_declaration (union_variant (upper_case_identifier) @name)) @definition.union + +(value_expr (upper_case_qid (upper_case_identifier) @name)) @reference.union + + +(module_declaration + (upper_case_qid (upper_case_identifier)) @name +) @definition.module From 3914f66a23477ccffa3838bcae0fe5d84cb8d5c7 Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Sat, 15 Jan 2022 12:23:43 -0800 Subject: [PATCH 2/3] Fix docs gen --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 8b599f6b4dc7..37d4b632cd32 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -10,6 +10,7 @@ | dart | ✓ | | ✓ | `dart` | | dockerfile | ✓ | | | `docker-langserver` | | elixir | ✓ | | | `elixir-ls` | +| elm | ✓ | | | `elm-language-server` | | fish | ✓ | ✓ | ✓ | | | git-commit | ✓ | | | | | git-config | ✓ | | | | From 2d155d8ee60043dff96c323d72e5bfc26db43d5f Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Mon, 17 Jan 2022 11:05:34 -0800 Subject: [PATCH 3/3] Updates based on PR feedback --- runtime/queries/elm/highlights.scm | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/runtime/queries/elm/highlights.scm b/runtime/queries/elm/highlights.scm index 06894a4445f4..3c8fd12d87a9 100644 --- a/runtime/queries/elm/highlights.scm +++ b/runtime/queries/elm/highlights.scm @@ -32,15 +32,14 @@ (operator_identifier) @keyword.operator (eq) @keyword.operator.assignment - -"(" @punctuation.braces -")" @punctuation.braces - -"[" @punctuation.braces -"]" @punctuation.braces - -"{" @punctuation.braces -"}" @punctuation.braces +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket "|" @keyword "," @punctuation.delimiter @@ -50,7 +49,7 @@ ] @keyword -(import) @keyword.other +(import) @keyword.contol.import (module) @keyword.other (number_constant_expr) @constant.numeric @@ -74,7 +73,7 @@ (block_comment) @comment ; strings -(string_escape) @constant.character +(string_escape) @constant.character.escape (open_quote) @string (close_quote) @string @@ -82,7 +81,3 @@ (open_char) @constant.character (close_char) @constant.character - - -; glsl -(glsl_content) @source.glsl