From f786eebd46e1a6a9a8c664cf33bfc65a1f8caf43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Lehmann?= Date: Tue, 2 Apr 2024 18:10:56 +0200 Subject: [PATCH] add earthfile language configuration --- book/src/generated/lang-support.md | 1 + languages.toml | 17 ++++++ runtime/queries/earthfile/highlights.scm | 74 +++++++++++++++++++++++ runtime/queries/earthfile/indents.scm | 1 + runtime/queries/earthfile/injections.scm | 9 +++ runtime/queries/earthfile/textobjects.scm | 1 + 6 files changed, 103 insertions(+) create mode 100644 runtime/queries/earthfile/highlights.scm create mode 100644 runtime/queries/earthfile/indents.scm create mode 100644 runtime/queries/earthfile/injections.scm create mode 100644 runtime/queries/earthfile/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 6bbea10aceb4..a4e2a84a2123 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -37,6 +37,7 @@ | dockerfile | ✓ | | | `docker-langserver` | | dot | ✓ | | | `dot-language-server` | | dtd | ✓ | | | | +| earthfile | ✓ | ✓ | ✓ | `earthlyls` | | edoc | ✓ | | | | | eex | ✓ | | | | | ejs | ✓ | | | | diff --git a/languages.toml b/languages.toml index 43bb90259bcd..cbaa1b70c28f 100644 --- a/languages.toml +++ b/languages.toml @@ -28,6 +28,7 @@ dhall-lsp-server = { command = "dhall-lsp-server" } docker-langserver = { command = "docker-langserver", args = ["--stdio"] } docker-compose-langserver = { command = "docker-compose-langserver", args = ["--stdio"]} dot-language-server = { command = "dot-language-server", args = ["--stdio"] } +earthlyls = { command = "earthlyls" } elixir-ls = { command = "elixir-ls", config = { elixirLS.dialyzerEnabled = false } } elm-language-server = { command = "elm-language-server" } elvish = { command = "elvish", args = ["-lsp"] } @@ -3442,3 +3443,19 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "ohm" source = { git = "https://github.com/novusnota/tree-sitter-ohm", rev = "80f14f0e477ddacc1e137d5ed8e830329e3fb7a3" } + +[[language]] +name = "earthfile" +scope = "source.earthfile" +injection-regex = "earthfile" +roots = ["Earthfile"] +file-types = [ + { glob = "Earthfile" }, +] +comment-token = "#" +indent = { tab-width = 2, unit = " " } +language-servers = ["earthlyls"] + +[[grammar]] +name = "earthfile" +source = { git = "https://github.com/glehmann/tree-sitter-earthfile", rev = "2a6ab191f5f962562e495a818aa4e7f45f8a556a" } diff --git a/runtime/queries/earthfile/highlights.scm b/runtime/queries/earthfile/highlights.scm new file mode 100644 index 000000000000..a0191174fea1 --- /dev/null +++ b/runtime/queries/earthfile/highlights.scm @@ -0,0 +1,74 @@ +(string_array "," @punctuation.delimiter) +(string_array ["[" "]"] @punctuation.bracket) + +(arg_command "ARG" @keyword) +(build_command "BUILD" @keyword) +(cache_command "CACHE" @keyword) +(cmd_command "CMD" @keyword) +(copy_command "COPY" @keyword) +(do_command "DO" @keyword) +(entrypoint_command "ENTRYPOINT" @keyword) +(env_command "ENV" @keyword) +(expose_command "EXPOSE" @keyword) +(from_command "FROM" @keyword) +(from_dockerfile_command "FROM DOCKERFILE" @keyword) +(function_command "FUNCTION" @keyword) +(git_clone_command "GIT CLONE" @keyword) +(host_command "HOST" @keyword) +(import_command "IMPORT" @keyword) +(label_command "LABEL" @keyword) +(let_command "LET" @keyword) +(project_command "PROJECT" @keyword) +(run_command "RUN" @keyword) +(save_artifact_command ["SAVE ARTIFACT" "AS LOCAL"] @keyword) +(save_image_command "SAVE IMAGE" @keyword) +(set_command "SET" @keyword) +(user_command "USER" @keyword) +(version_command "VERSION" @keyword) +(volume_command "VOLUME" @keyword) +(with_docker_command "WITH DOCKER" @keyword) +(workdir_command "WORKDIR" @keyword) + +(for_command ["FOR" "IN" "END"] @keyword.control.repeat) +(if_command ["IF" "END"] @keyword.control.conditional) +(elif_block ["ELSE IF"] @keyword.control.conditional) +(else_block ["ELSE"] @keyword.control.conditional) +(import_command ["IMPORT" "AS"] @keyword.control.import) +(try_command ["TRY" "FINALLY" "END"] @keyword.control.exception) +(wait_command ["WAIT" "END"] @keyword.control) + + +[ + (comment) + (line_continuation_comment) +] @comment + +(line_continuation) @operator + +[ + (target_ref) + (target_artifact) + (function_ref) +] @function + +(target (identifier) @function) + +[ + (double_quoted_string) + (single_quoted_string) +] @string +(unquoted_string) @string.special +(escape_sequence) @constant.character.escape + +(variable) @variable +(expansion ["$" "{" "}" "(" ")"] @punctuation.special) +(build_arg) @variable +(options (_) @variable.parameter) + +(options (_ "=" @operator)) +(build_arg "=" @operator) +(arg_command "=" @operator) +(env_command "=" @operator) +(label "=" @operator) +(set_command "=" @operator) +(let_command "=" @operator) diff --git a/runtime/queries/earthfile/indents.scm b/runtime/queries/earthfile/indents.scm new file mode 100644 index 000000000000..2bee23e84201 --- /dev/null +++ b/runtime/queries/earthfile/indents.scm @@ -0,0 +1 @@ +(target) @indent diff --git a/runtime/queries/earthfile/injections.scm b/runtime/queries/earthfile/injections.scm new file mode 100644 index 000000000000..7435a400e729 --- /dev/null +++ b/runtime/queries/earthfile/injections.scm @@ -0,0 +1,9 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +((line_continuation_comment) @injection.content + (#set! injection.language "comment")) + +((shell_fragment) @injection.content + (#set! injection.language "bash") + (#set! injection.include-children)) diff --git a/runtime/queries/earthfile/textobjects.scm b/runtime/queries/earthfile/textobjects.scm new file mode 100644 index 000000000000..ae0364a2de04 --- /dev/null +++ b/runtime/queries/earthfile/textobjects.scm @@ -0,0 +1 @@ +(target (block) @function.inside) @function.around