Unnamed repository; edit this file 'description' to name the repository.
languages: add Caddyfile support (#13859)
Co-authored-by: Michael Davis <[email protected]>
| -rw-r--r-- | book/src/generated/lang-support.md | 1 | ||||
| -rw-r--r-- | languages.toml | 14 | ||||
| -rw-r--r-- | runtime/queries/caddyfile/highlights.scm | 72 | ||||
| -rw-r--r-- | runtime/queries/caddyfile/indents.scm | 8 | ||||
| -rw-r--r-- | runtime/queries/caddyfile/injections.scm | 2 | ||||
| -rw-r--r-- | runtime/queries/caddyfile/locals.scm | 5 | ||||
| -rw-r--r-- | runtime/queries/caddyfile/textobjects.scm | 16 |
7 files changed, 118 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index dad557d9..f16644a1 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -18,6 +18,7 @@ | c | ✓ | ✓ | ✓ | `clangd` | | c-sharp | ✓ | ✓ | | `OmniSharp` | | cabal | | | | `haskell-language-server-wrapper` | +| caddyfile | ✓ | ✓ | ✓ | | | cairo | ✓ | ✓ | ✓ | `cairo-language-server` | | capnp | ✓ | | ✓ | | | cel | ✓ | | | | diff --git a/languages.toml b/languages.toml index a5015dd2..032fbc0b 100644 --- a/languages.toml +++ b/languages.toml @@ -4436,3 +4436,17 @@ language-servers = [ "luau" ] [[grammar]] name = "luau" source = { git = "https://github.com/polychromatist/tree-sitter-luau", rev = "ec187cafba510cddac265329ca7831ec6f3b9955" } + +[[language]] +name = "caddyfile" +scope = "source.caddyfile" +injection-regex = "caddyfile" +file-types = [{ glob = "Caddyfile" }] +comment-tokens = ["#"] +indent = { tab-width = 4, unit = " " } +formatter = { command = "caddy", args = ["fmt", "-"] } +auto-format = true + +[[grammar]] +name = "caddyfile" +source = { git = "https://github.com/caddyserver/tree-sitter-caddyfile", rev = "b04bdb4ec53e40c44afbf001e15540f60a296aef" } diff --git a/runtime/queries/caddyfile/highlights.scm b/runtime/queries/caddyfile/highlights.scm new file mode 100644 index 00000000..492d2aec --- /dev/null +++ b/runtime/queries/caddyfile/highlights.scm @@ -0,0 +1,72 @@ +(comment) @comment +[ + (environment_variable) + (placeholder) +] @constant + +[ + (network_address) + (ip_address_or_cidr) +] @string.special.url + +(path) @string.special.path + +[ + (snippet_name) + (named_route_identifier) + (site_address) +] @keyword + +(directive (directive_name) @variable.other.member) + +; declaration of a named matcher +(named_matcher (matcher_identifier (matcher_name)) @function.macro) + +; reference to a named matcher +(matcher (matcher_identifier (matcher_name)) @function.macro) + +; directive within a named matcher declaration +(matcher_directive (matcher_directive_name) @function.method) + +; any other matcher (wildcard and path) +(matcher) @function.macro + +[ + (interpreted_string_literal) + (raw_string_literal) + (heredoc) + (cel_expression) +] @string +(escape_sequence) @constant.character.escape + +[ + (duration_literal) + (int_literal) +] @constant.numeric + +[ + "{" + "}" +] @punctuation.bracket + +(global_options + (directive) @keyword.directive) + +(directive + name: (directive_name) + (argument) @type) + +; matches directive arguments that looks like an absolute path +; e.g. +; log { +; output file /var/log/caddy.log +; } +(directive + (argument) @string.special.path + (#match? @string.special.path "^/")) + +((argument) @constant.builtin.boolean + (#any-of? @constant.builtin.boolean "on" "off")) + +((argument) @type.enum.variant + (#any-of? @type.enum.variant "tcp" "udp" "ipv4" "ipv6")) diff --git a/runtime/queries/caddyfile/indents.scm b/runtime/queries/caddyfile/indents.scm new file mode 100644 index 00000000..46b17f3a --- /dev/null +++ b/runtime/queries/caddyfile/indents.scm @@ -0,0 +1,8 @@ +[ + (block) + (matcher_block) +] @indent + +((global_options) @indent) + +"}" @outdent diff --git a/runtime/queries/caddyfile/injections.scm b/runtime/queries/caddyfile/injections.scm new file mode 100644 index 00000000..321c90ad --- /dev/null +++ b/runtime/queries/caddyfile/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/caddyfile/locals.scm b/runtime/queries/caddyfile/locals.scm new file mode 100644 index 00000000..1a27ccea --- /dev/null +++ b/runtime/queries/caddyfile/locals.scm @@ -0,0 +1,5 @@ +(block) @local.scope + +(named_matcher (matcher_identifier (matcher_name)) @local.definition.function.macro) + +(matcher) @local.reference diff --git a/runtime/queries/caddyfile/textobjects.scm b/runtime/queries/caddyfile/textobjects.scm new file mode 100644 index 00000000..8a9fd7e9 --- /dev/null +++ b/runtime/queries/caddyfile/textobjects.scm @@ -0,0 +1,16 @@ +(comment) @comment.inside +(comment)+ @comment.around + +(directive + name: (directive_name) @parameter.inside) @parameter.around + +(global_options + "{" (_)* @class.inside "}") @class.around + +(snippet_definition + (block) @class.inside) @class.around + +(named_route + (block) @class.inside) @class.around + +(site_definition (block) @class.inside) @class.around |