diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2023-06-12 09:54:30 -0600 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | 692b051b09935653befdb8f7ba8afdb640adf17b (patch) | |
| tree | 167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/sway | |
| parent | feat(c-family): inherit injections (diff) | |
| download | nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2 nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip | |
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/sway')
| -rw-r--r-- | runtime/queries/sway/folds.scm | 20 | ||||
| -rw-r--r-- | runtime/queries/sway/highlights.scm | 336 | ||||
| -rw-r--r-- | runtime/queries/sway/indents.scm | 95 | ||||
| -rw-r--r-- | runtime/queries/sway/injections.scm | 5 | ||||
| -rw-r--r-- | runtime/queries/sway/locals.scm | 16 |
5 files changed, 472 insertions, 0 deletions
diff --git a/runtime/queries/sway/folds.scm b/runtime/queries/sway/folds.scm new file mode 100644 index 000000000..ba8474aa2 --- /dev/null +++ b/runtime/queries/sway/folds.scm @@ -0,0 +1,20 @@ +[ + (mod_item) + (function_item) + (struct_item) + (trait_item) + (enum_item) + (impl_item) + (type_item) + (const_item) + (let_declaration) + (for_expression) + (while_expression) + (if_expression) + (match_expression) + (call_expression) + (array_expression) + (attribute_item) + (block) + (use_declaration)+ +] @fold diff --git a/runtime/queries/sway/highlights.scm b/runtime/queries/sway/highlights.scm new file mode 100644 index 000000000..e408464fe --- /dev/null +++ b/runtime/queries/sway/highlights.scm @@ -0,0 +1,336 @@ +(type_identifier) @type + +(identifier) @variable + +(field_identifier) @variable.member + +(escape_sequence) @string.escape + +(primitive_type) @type.builtin + +(boolean_literal) @boolean + +(integer_literal) @number + +(float_literal) @number.float + +(char_literal) @character + +; ------- +; Paths +; ------- +(use_declaration + argument: (identifier) @module) + +(use_wildcard + (identifier) @module) + +(mod_item + name: (identifier) @module) + +(scoped_use_list + path: (identifier)? @module) + +(use_list + (identifier) @module) + +(use_as_clause + path: (identifier)? @module + alias: (identifier) @module) + +; --- +; Remaining Paths +; --- +(scoped_identifier + path: (identifier)? @module + name: (identifier) @module) + +(scoped_type_identifier + path: (identifier) @module) + +[ + "*" + "'" + "->" + "=>" + "<=" + "=" + "==" + "!" + "!=" + "%" + "%=" + "&" + "&=" + "&&" + "|" + "|=" + "||" + "^" + "^=" + "*" + "*=" + "-" + "-=" + "+" + "+=" + "/" + "/=" + ">" + "<" + ">=" + ">>" + "<<" + ">>=" + "<<=" + "@" + ".." + "..=" + "'" + "?" +] @operator + +(use_wildcard + "*" @character.special) + +[ + (string_literal) + (raw_string_literal) +] @string + +[ + (line_comment) + (block_comment) +] @comment + +; --- +; Extraneous +; --- +(self) @variable.builtin + +(enum_variant + (identifier) @constant) + +(field_initializer + (field_identifier) @variable.member) + +(shorthand_field_initializer + (identifier) @variable.member) + +(shorthand_field_identifier) @variable.member + +(loop_label + "'" @label + (identifier) @label) + +; --- +; Punctuation +; --- +[ + "::" + ":" + "." + ";" + "," +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" + "#" +] @punctuation.bracket + +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +(closure_parameters + "|" @punctuation.bracket) + +(let_declaration + pattern: [ + (identifier) @variable + (tuple_pattern + (identifier) @variable) + ]) + +; It needs to be anonymous to not conflict with `call_expression` further below. +(_ + value: (field_expression + value: (identifier)? @variable + field: (field_identifier) @variable.member)) + +(parameter + pattern: (identifier) @variable.parameter) + +(parameter + pattern: (ref_pattern + [ + (mut_pattern + (identifier) @variable.parameter) + (identifier) @variable.parameter + ])) + +(closure_parameters + (identifier) @variable.parameter) + +(for_expression + "for" @keyword.repeat) + +"in" @keyword.repeat + +[ + "match" + "if" + "else" +] @keyword.conditional + +"while" @keyword.repeat + +[ + "break" + "continue" + "return" + "yield" +] @keyword.return + +"use" @keyword.import + +(mod_item + "mod" @keyword.import + !body) + +(use_as_clause + "as" @keyword.import) + +(type_cast_expression + "as" @keyword.operator) + +[ + "as" + "mod" + "abi" + "impl" + "where" + "trait" + "for" + "let" + "contract" + "script" + "predicate" + "library" +] @keyword + +[ + "struct" + "enum" + "storage" + "configurable" + "type" +] @keyword.type + +[ + "fn" + "abi" +] @keyword.function + +[ + (mutable_specifier) + "const" + "ref" + "deref" + "move" + "pub" +] @keyword.modifier + +(reference_type + "&" @keyword.modifier) + +(self_parameter + "&" @keyword.modifier) + +; ------- +; Guess Other Types +; ------- +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +; --- +; PascalCase identifiers in call_expressions (e.g. `Ok()`) +; are assumed to be enum constructors. +; --- +(call_expression + function: [ + ((identifier) @constant + (#lua-match? @constant "^[A-Z]")) + (scoped_identifier + name: ((identifier) @constant + (#lua-match? @constant "^[A-Z]"))) + ]) + +; --- +; Assume that types in match arms are enums and not +; tuple structs. Same for `if let` expressions. +; --- +(match_pattern + (scoped_identifier + name: (identifier) @constructor)) + +(tuple_struct_pattern + type: [ + (identifier) @constructor + (scoped_identifier + name: (identifier) @constructor) + ]) + +(struct_pattern + type: [ + (type_identifier) @constructor + (scoped_type_identifier + name: (type_identifier) @constructor) + ]) + +; --- +; Other PascalCase identifiers are assumed to be structs. +; --- +((identifier) @type + (#lua-match? @type "^[A-Z]")) + +; ------- +; Functions +; ------- +(call_expression + function: [ + (identifier) @function.call + (scoped_identifier + name: (identifier) @function.call) + (field_expression + field: (field_identifier) @function.method.call) + ]) + +(generic_function + function: [ + (identifier) @function.call + (scoped_identifier + name: (identifier) @function.call) + (field_expression + field: (field_identifier) @function.method.call) + ]) + +(function_item + name: (identifier) @function) + +(function_signature_item + name: (identifier) @function) diff --git a/runtime/queries/sway/indents.scm b/runtime/queries/sway/indents.scm new file mode 100644 index 000000000..151d8b20b --- /dev/null +++ b/runtime/queries/sway/indents.scm @@ -0,0 +1,95 @@ +[ + (mod_item) + (struct_item) + (enum_item) + (impl_item) + (struct_expression) + (struct_pattern) + (tuple_struct_pattern) + (tuple_expression) + (tuple_type) + (tuple_pattern) + (match_block) + (call_expression) + (asm_block) + (asm_parameters) + (assignment_expression) + (arguments) + (block) + (where_clause) + (use_list) + (array_expression) + (ordered_field_declaration_list) + (field_declaration_list) + (enum_variant_list) + (parameters) + (token_tree) +] @indent.begin + +(trait_item + body: (_) @indent.begin) + +(string_literal + (escape_sequence)) @indent.begin + +(block + "}" @indent.end) + +(asm_block + "}" @indent.end) + +(enum_item + body: (enum_variant_list + "}" @indent.end)) + +(impl_item + body: (declaration_list + "}" @indent.end)) + +(match_expression + body: (match_block + "}" @indent.end)) + +(struct_item + body: (field_declaration_list + "}" @indent.end)) + +(struct_expression + body: (field_initializer_list + "}" @indent.end)) + +(struct_pattern + "}" @indent.end) + +(tuple_struct_pattern + ")" @indent.end) + +(tuple_type + ")" @indent.end) + +(tuple_pattern + ")" @indent.end) + +(trait_item + body: (declaration_list + "}" @indent.end)) + +(impl_item + (where_clause) @indent.dedent) + +[ + "where" + ")" + "]" + "}" +] @indent.branch + +(impl_item + (declaration_list) @indent.branch) + +[ + (line_comment) + (string_literal) +] @indent.ignore + +(raw_string_literal) @indent.auto diff --git a/runtime/queries/sway/injections.scm b/runtime/queries/sway/injections.scm new file mode 100644 index 000000000..3cd6aac8e --- /dev/null +++ b/runtime/queries/sway/injections.scm @@ -0,0 +1,5 @@ +([ + (line_comment) + (block_comment) +] @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/sway/locals.scm b/runtime/queries/sway/locals.scm new file mode 100644 index 000000000..5c2ade83a --- /dev/null +++ b/runtime/queries/sway/locals.scm @@ -0,0 +1,16 @@ +; Scopes +[ + (function_item) + (closure_expression) + (block) +] @local.scope + +; Definitions +(parameter + (identifier) @local.definition) + +(closure_parameters + (identifier) @local.definition) + +; References +(identifier) @local.reference |
