From 843c058f0bdd9d821cb2d51114389ab2727c7c6f Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Wed, 20 Nov 2024 14:38:15 -0800 Subject: [PATCH] Use latest tree-sitter-bicep, support bicepparams (#11525) Co-authored-by: Michael Davis --- languages.toml | 4 +- runtime/queries/bicep/highlights.scm | 265 +++++++++++++++++++++------ 2 files changed, 214 insertions(+), 55 deletions(-) diff --git a/languages.toml b/languages.toml index 500273d87..5bb3d298d 100644 --- a/languages.toml +++ b/languages.toml @@ -2811,7 +2811,7 @@ source = { git = "https://github.com/inko-lang/tree-sitter-inko", rev = "7860637 [[language]] name = "bicep" scope = "source.bicep" -file-types = ["bicep"] +file-types = ["bicep","bicepparam"] auto-format = true comment-token = "//" block-comment-tokens = { start = "/*", end = "*/" } @@ -2820,7 +2820,7 @@ language-servers = [ "bicep-langserver" ] [[grammar]] name = "bicep" -source = { git = "https://github.com/the-mikedavis/tree-sitter-bicep", rev = "d8e097fcfa143854861ef737161163a09cc2916b" } +source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-bicep", rev = "0092c7d1bd6bb22ce0a6f78497d50ea2b87f19c0" } [[language]] name = "qml" diff --git a/runtime/queries/bicep/highlights.scm b/runtime/queries/bicep/highlights.scm index b6f928726..b80de7fd7 100644 --- a/runtime/queries/bicep/highlights.scm +++ b/runtime/queries/bicep/highlights.scm @@ -1,73 +1,232 @@ -; Keywords - +; Includes [ - "module" - "var" - "param" "import" - "resource" - "existing" - "if" - "targetScope" - "output" -] @keyword + "provider" + "with" + "as" + "from" +] @keyword.control.import + +; Namespaces +(module_declaration + (identifier) @namespace) + +; Builtins +(primitive_type) @type.builtin + +((member_expression + object: (identifier) @type.builtin) + (#eq? @type.builtin "sys")) ; Functions +(call_expression + function: (identifier) @function) -(decorator) @function.builtin +(user_defined_function + name: (identifier) @function) -(functionCall) @function +; Properties +(object_property + (identifier) @function.method + ":" @punctuation.delimiter + (_)) -(functionCall - (functionArgument - (variableAccess) @variable)) +(object_property + (compatible_identifier) @function.method + ":" @punctuation.delimiter + (_)) -; Literals/Types +(property_identifier) @function.method + +; Attributes +(decorator + "@" @attribute) + +(decorator + (call_expression + (identifier) @attribute)) + +(decorator + (call_expression + (member_expression + object: (identifier) @attribute + property: (property_identifier) @attribute))) + +; Types +(type_declaration + (identifier) @type) + +(type_declaration + (identifier) + "=" + (identifier) @type) + +(type + (identifier) @type) + +(resource_declaration + (identifier) @type) + +(resource_expression + (identifier) @type) + +; Parameters +(parameter_declaration + (identifier) @variable.parameter + (_)) + +(call_expression + function: (_) + (arguments + (identifier) @variable.parameter)) + +(call_expression + function: (_) + (arguments + (member_expression + object: (identifier) @variable.parameter))) + +(parameter + . + (identifier) @variable.parameter) + +; Variables +(variable_declaration + (identifier) @variable + (_)) + +(metadata_declaration + (identifier) @variable + (_)) + +(output_declaration + (identifier) @variable + (_)) + +(object_property + (_) + ":" + (identifier) @variable) + +(for_statement + "for" + (for_loop_parameters + (loop_variable) @variable + (loop_enumerator) @variable)) + +; Conditionals +"if" @keyword.conditional + +(ternary_expression + "?" @keyword.control.conditional + ":" @keyword.control.conditional) + +; Loops +(for_statement + "for" @keyword.control.repeat + "in" + ":" @punctuation.delimiter) + +; Keywords +[ + "module" + "metadata" + "output" + "param" + "resource" + "existing" + "targetScope" + "type" + "var" + "using" + "test" +] @keyword + +"func" @keyword.function + +"assert" @keyword.control.exception + +; Operators +[ + "+" + "-" + "*" + "/" + "%" + "||" + "&&" + "|" + "==" + "!=" + "=~" + "!~" + ">" + ">=" + "<=" + "<" + "??" + "=" + "!" + ".?" +] @operator + +(subscript_expression + "?" @operator) + +(nullable_type + "?" @operator) + +"in" @keyword.operator + +; Literals +(string) @string + +(escape_sequence) @constant.character + +(number) @constant.number + +(boolean) @constant.builtin.boolean + +(null) @constant.builtin + +; Misc +(compatible_identifier + "?" @punctuation.special) + +(nullable_return_type) @punctuation.special [ - "(" - ")" - "[" - "]" "{" "}" ] @punctuation.bracket -(resourceDeclaration - (string - (stringLiteral) @string.special)) - -(moduleDeclaration - (string - (stringLiteral) @string.special)) +[ + "[" + "]" +] @punctuation.bracket [ - (string) - (stringLiteral) -] @string + "(" + ")" +] @punctuation.bracket -(nullLiteral) @keyword -(booleanLiteral) @constant.builtin.boolean -(integerLiteral) @constant.numeric.integer -(comment) @comment +[ + "." + ":" + "::" + "=>" +] @punctuation.delimiter -(string - (variableAccess - (identifier) @variable)) +; Interpolation +(interpolation + "${" @punctuation.special + "}" @punctuation.special) -(type) @type +(interpolation + (identifier) @variable) -; Variables - -(localVariable) @variable - -; Statements - -(object - (objectProperty - (identifier) @identifier)) - -(propertyAccess - (identifier) @identifier) - -(ifCondition) @keyword.control.conditional +; Comments +[ + (comment) + (diagnostic_comment) +] @comment