diff --git a/languages.toml b/languages.toml index 0aca142a8..aa43784f6 100644 --- a/languages.toml +++ b/languages.toml @@ -2199,7 +2199,7 @@ language-servers = [ "cairo-language-server" ] [[grammar]] name = "cairo" -source = { git = "https://github.com/starkware-libs/tree-sitter-cairo", rev = "e3a0212261c125cb38248458cd856c0ffee2b398" } +source = { git = "https://github.com/starkware-libs/tree-sitter-cairo", rev = "4c6a25680546761b80a710ead1dd34e76c203125" } [[language]] name = "cpon" diff --git a/runtime/queries/cairo/highlights.scm b/runtime/queries/cairo/highlights.scm index 16918c141..fb62c5053 100644 --- a/runtime/queries/cairo/highlights.scm +++ b/runtime/queries/cairo/highlights.scm @@ -71,6 +71,8 @@ "<" ">" ] @punctuation.bracket) +(closure_parameters + "|" @punctuation.bracket) ; --- ; Variables @@ -92,6 +94,8 @@ (parameter pattern: (identifier) @variable.parameter) +(closure_parameters + (identifier) @variable.parameter) ; ------- ; Keywords ; ------- diff --git a/runtime/queries/cairo/indents.scm b/runtime/queries/cairo/indents.scm index b20317ab0..8c6abd10a 100644 --- a/runtime/queries/cairo/indents.scm +++ b/runtime/queries/cairo/indents.scm @@ -115,6 +115,16 @@ (#not-same-line? @expr-start @pattern-guard) ) @indent +; Align closure parameters if they span more than one line +(closure_parameters + "|" + . + (_) @anchor + (_) @expr-end + . + (#not-same-line? @anchor @expr-end) +) @align + (for_expression "in" @in . diff --git a/runtime/queries/cairo/locals.scm b/runtime/queries/cairo/locals.scm index 35acb55c6..68c41a46b 100644 --- a/runtime/queries/cairo/locals.scm +++ b/runtime/queries/cairo/locals.scm @@ -7,6 +7,7 @@ (type_item) (trait_item) (impl_item) + (closure_expression) (block) ] @local.scope @@ -20,6 +21,8 @@ (constrained_type_parameter left: (type_identifier) @local.definition) +(closure_parameters (identifier) @local.definition) + ; References (identifier) @local.reference (type_identifier) @local.reference diff --git a/runtime/queries/cairo/textobjects.scm b/runtime/queries/cairo/textobjects.scm index 4031873de..1bb89234e 100644 --- a/runtime/queries/cairo/textobjects.scm +++ b/runtime/queries/cairo/textobjects.scm @@ -1,6 +1,9 @@ (function_item body: (_) @function.inside) @function.around +(closure_expression + body: (_) @function.inside) @function.around + (struct_item body: (_) @class.inside) @class.around @@ -16,6 +19,9 @@ (parameters ((_) @parameter.inside . ","? @parameter.around) @parameter.around) +(closure_parameters + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + (type_parameters ((_) @parameter.inside . ","? @parameter.around) @parameter.around)