From db9624783a2b33963a2c6d4b777195916cfdeaa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Dudr?= Date: Tue, 15 Apr 2025 07:55:55 +0200 Subject: [PATCH] nvim: kcl treesitter goodies --- dot_config/nvim/after/queries/kcl/indents.scm | 14 ++ dot_config/nvim/queries/kcl/highlights.scm | 169 ++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 dot_config/nvim/after/queries/kcl/indents.scm create mode 100644 dot_config/nvim/queries/kcl/highlights.scm diff --git a/dot_config/nvim/after/queries/kcl/indents.scm b/dot_config/nvim/after/queries/kcl/indents.scm new file mode 100644 index 0000000..f2a8c1d --- /dev/null +++ b/dot_config/nvim/after/queries/kcl/indents.scm @@ -0,0 +1,14 @@ +[ + (config_expr) + (list_expr) + (config_entry) + (schema_stmt) + (assign_stmt) +] @indent.begin + +[ + "}" + "]" + ")" +] @indent.branch + diff --git a/dot_config/nvim/queries/kcl/highlights.scm b/dot_config/nvim/queries/kcl/highlights.scm new file mode 100644 index 0000000..2c9140d --- /dev/null +++ b/dot_config/nvim/queries/kcl/highlights.scm @@ -0,0 +1,169 @@ +(identifier) @variable + +( config_entry (identifier) @field (_)) +( config_entry (selector_expr (identifier)) @field (_)) + +; Reset highlighting in string interpolations +(interpolation) @none + +(import_stmt + (dotted_name + (identifier) @namespace)) + +(import_stmt + (dotted_name + (identifier) @namespace) + (identifier) @namespace) + +(basic_type) @type + +(schema_type + (dotted_name + (identifier) @type)) + +(schema_type + (dotted_name + (identifier) @namespace + (identifier) @type)) + +(schema_expr + (identifier) @type) + +(protocol_stmt + (identifier) @type) + +(rule_stmt + (identifier) @type) + +(schema_stmt + (identifier) @type) + +(lambda_expr + (typed_parameter (identifier) @parameter)) + +(lambda_expr + (identifier) @parameter) + +(selector_expr + (select_suffix + (identifier) @property)) + +(comment) @comment +(string) @string +(escape_sequence) @string.escape + +(schema_stmt + body: (block + . + (string + (string_content) @string.documentation))) + +(decorator + (identifier) @attribute) + +(call_expr + function: (identifier) @function) + +(call_expr + function: (selector_expr + (select_suffix + (identifier) @function))) + +[ + (integer) + (float) +] @number + +[ + (true) + (false) + (none) + (undefined) +] @constant.builtin + +[ + "all" + "any" + "assert" + "as" + "check" + "elif" + "else" + "filter" + "for" + "if" + "import" + "lambda" + "map" + "mixin" + "protocol" + "rule" + "schema" + "type" +] @keyword + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(interpolation + "${" @punctuation.special + "}" @punctuation.special) + +[ + "+" + "-" + "*" + "**" + "/" + "//" + "%" + "<<" + ">>" + "&" + "|" + "^" + "<" + ">" + "~" + "<=" + ">=" + "==" + "!=" + "@" + "and" + "or" + "not" + "in" + "is" + "=" + ":" +] @operator + +; second argument is a regex in all regex functions with at least two arguments +(call_expr + function: (selector_expr + (identifier) @_regex) + arguments: (argument_list + (_) + . + (string + (string_content) @string.regexp)) + (#eq? @_regex "regex")) + +; first argument is a regex in 'regex.compile' function +(call_expr + . + function: (selector_expr + (identifier) @_regex + (select_suffix + (identifier) @_fn (#eq? @_fn "compile"))) + arguments: (argument_list + (string + (string_content) @string.regexp)) + (#eq? @_regex "regex"))