aboutsummaryrefslogtreecommitdiff
path: root/helix-22.03-x86_64-windows/runtime/queries/rust
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /helix-22.03-x86_64-windows/runtime/queries/rust
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'helix-22.03-x86_64-windows/runtime/queries/rust')
-rw-r--r--helix-22.03-x86_64-windows/runtime/queries/rust/highlights.scm356
-rw-r--r--helix-22.03-x86_64-windows/runtime/queries/rust/indents.toml28
-rw-r--r--helix-22.03-x86_64-windows/runtime/queries/rust/injections.scm26
-rw-r--r--helix-22.03-x86_64-windows/runtime/queries/rust/locals.scm17
-rw-r--r--helix-22.03-x86_64-windows/runtime/queries/rust/textobjects.scm35
5 files changed, 462 insertions, 0 deletions
diff --git a/helix-22.03-x86_64-windows/runtime/queries/rust/highlights.scm b/helix-22.03-x86_64-windows/runtime/queries/rust/highlights.scm
new file mode 100644
index 0000000..26496c6
--- /dev/null
+++ b/helix-22.03-x86_64-windows/runtime/queries/rust/highlights.scm
@@ -0,0 +1,356 @@
+; -------
+; Tree-Sitter doesn't allow overrides in regards to captures,
+; though it is possible to affect the child node of a captured
+; node. Thus, the approach here is to flip the order so that
+; overrides are unnecessary.
+; -------
+
+
+
+; -------
+; Types
+; -------
+
+; ---
+; Primitives
+; ---
+
+(escape_sequence) @constant.character.escape
+(primitive_type) @type.builtin
+(boolean_literal) @constant.builtin.boolean
+(integer_literal) @constant.numeric.integer
+(float_literal) @constant.numeric.float
+(char_literal) @constant.character
+[
+ (string_literal)
+ (raw_string_literal)
+] @string
+[
+ (line_comment)
+ (block_comment)
+] @comment
+
+; ---
+; Extraneous
+; ---
+
+(self) @variable.builtin
+(enum_variant (identifier) @type.enum.variant)
+
+(field_initializer
+ (field_identifier) @variable.other.member)
+(shorthand_field_initializer
+ (identifier) @variable.other.member)
+(shorthand_field_identifier) @variable.other.member
+
+(lifetime
+ "'" @label
+ (identifier) @label)
+(loop_label
+ (identifier) @type)
+
+; ---
+; Punctuation
+; ---
+
+[
+ "::"
+ "."
+ ";"
+] @punctuation.delimiter
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+(type_arguments
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
+(type_parameters
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
+
+; ---
+; Variables
+; ---
+
+(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.other.member))
+
+(arguments
+ (identifier) @variable.parameter)
+(parameter
+ pattern: (identifier) @variable.parameter)
+(closure_parameters
+ (identifier) @variable.parameter)
+
+
+
+; -------
+; Keywords
+; -------
+
+(for_expression
+ "for" @keyword.control)
+((identifier) @keyword.control
+ (#match? @keyword.control "^yield$"))
+[
+ "while"
+ "loop"
+ "in"
+ "break"
+ "continue"
+
+ "match"
+ "if"
+ "else"
+ "return"
+
+ "await"
+] @keyword.control
+
+"use" @keyword.control.import
+(mod_item "mod" @keyword.control.import !body)
+(use_as_clause "as" @keyword.control.import)
+
+(type_cast_expression "as" @keyword.operator)
+
+[
+ (crate)
+ (super)
+ "as"
+ "pub"
+ "mod"
+ "extern"
+
+ "fn"
+ "struct"
+ "enum"
+ "impl"
+ "where"
+ "trait"
+ "for"
+
+ "type"
+ "union"
+ "unsafe"
+ "default"
+ "macro_rules!"
+
+ "let"
+ "ref"
+ "move"
+
+ "dyn"
+ "static"
+ "const"
+ "async"
+] @keyword
+
+(mutable_specifier) @keyword.mut
+
+; TODO: variable.mut to highlight mutable identifiers via locals.scm
+
+; -------
+; Guess Other Types
+; -------
+
+((identifier) @constant
+ (#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) @type.variant
+ (#match? @type.variant "^[A-Z]"))
+ (scoped_identifier
+ name: ((identifier) @type.variant
+ (#match? @type.variant "^[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
+ (#match? @type "^[A-Z]"))
+
+
+
+; -------
+; Functions
+; -------
+
+(call_expression
+ function: [
+ ((identifier) @function)
+ (scoped_identifier
+ name: (identifier) @function)
+ (field_expression
+ field: (field_identifier) @function)
+ ])
+(generic_function
+ function: [
+ ((identifier) @function)
+ (scoped_identifier
+ name: (identifier) @function)
+ (field_expression
+ field: (field_identifier) @function.method)
+ ])
+
+(function_item
+ name: (identifier) @function)
+
+; ---
+; Macros
+; ---
+(meta_item
+ (identifier) @function.macro)
+
+(inner_attribute_item) @attribute
+
+(macro_definition
+ name: (identifier) @function.macro)
+(macro_invocation
+ macro: [
+ ((identifier) @function.macro)
+ (scoped_identifier
+ name: (identifier) @function.macro)
+ ]
+ "!" @function.macro)
+
+(metavariable) @variable.parameter
+(fragment_specifier) @type
+
+
+
+; -------
+; Operators
+; -------
+
+[
+ "*"
+ "'"
+ "->"
+ "=>"
+ "<="
+ "="
+ "=="
+ "!"
+ "!="
+ "%"
+ "%="
+ "&"
+ "&="
+ "&&"
+ "|"
+ "|="
+ "||"
+ "^"
+ "^="
+ "*"
+ "*="
+ "-"
+ "-="
+ "+"
+ "+="
+ "/"
+ "/="
+ ">"
+ "<"
+ ">="
+ ">>"
+ "<<"
+ ">>="
+ "@"
+ ".."
+ "..="
+ "'"
+] @operator
+
+
+
+; -------
+; Paths
+; -------
+
+(use_declaration
+ argument: (identifier) @namespace)
+(use_wildcard
+ (identifier) @namespace)
+(extern_crate_declaration
+ name: (identifier) @namespace)
+(mod_item
+ name: (identifier) @namespace)
+(scoped_use_list
+ path: (identifier)? @namespace)
+(use_list
+ (identifier) @namespace)
+(use_as_clause
+ path: (identifier)? @namespace
+ alias: (identifier) @namespace)
+
+; ---
+; Remaining Paths
+; ---
+
+(scoped_identifier
+ path: (identifier)? @namespace
+ name: (identifier) @namespace)
+(scoped_type_identifier
+ path: (identifier) @namespace)
+
+
+
+; -------
+; Remaining Identifiers
+; -------
+
+"?" @special
+
+(type_identifier) @type
+(identifier) @variable
+(field_identifier) @variable.other.member
diff --git a/helix-22.03-x86_64-windows/runtime/queries/rust/indents.toml b/helix-22.03-x86_64-windows/runtime/queries/rust/indents.toml
new file mode 100644
index 0000000..51a0cee
--- /dev/null
+++ b/helix-22.03-x86_64-windows/runtime/queries/rust/indents.toml
@@ -0,0 +1,28 @@
+indent = [
+ "use_list",
+ "block",
+ "match_block",
+ "arguments",
+ "parameters",
+ "declaration_list",
+ "field_declaration_list",
+ "field_initializer_list",
+ "struct_pattern",
+ "tuple_pattern",
+ "unit_expression",
+ "enum_variant_list",
+ "call_expression",
+ "binary_expression",
+ "field_expression",
+ "tuple_expression",
+ "array_expression",
+ "where_clause",
+ "macro_invocation"
+]
+
+outdent = [
+ "where",
+ "}",
+ "]",
+ ")"
+]
diff --git a/helix-22.03-x86_64-windows/runtime/queries/rust/injections.scm b/helix-22.03-x86_64-windows/runtime/queries/rust/injections.scm
new file mode 100644
index 0000000..77c7080
--- /dev/null
+++ b/helix-22.03-x86_64-windows/runtime/queries/rust/injections.scm
@@ -0,0 +1,26 @@
+([(line_comment) (block_comment)] @injection.content
+ (#set! injection.language "comment"))
+
+((macro_invocation
+ (token_tree) @injection.content)
+ (#set! injection.language "rust")
+ (#set! injection.include-children))
+
+((macro_rule
+ (token_tree) @injection.content)
+ (#set! injection.language "rust")
+ (#set! injection.include-children))
+
+(call_expression
+ function: (scoped_identifier
+ path: (identifier) @_regex (#eq? @_regex "Regex")
+ name: (identifier) @_new (#eq? @_new "new"))
+ arguments: (arguments (raw_string_literal) @injection.content)
+ (#set! injection.language "regex"))
+
+(call_expression
+ function: (scoped_identifier
+ path: (scoped_identifier (identifier) @_regex (#eq? @_regex "Regex") .)
+ name: (identifier) @_new (#eq? @_new "new"))
+ arguments: (arguments (raw_string_literal) @injection.content)
+ (#set! injection.language "regex"))
diff --git a/helix-22.03-x86_64-windows/runtime/queries/rust/locals.scm b/helix-22.03-x86_64-windows/runtime/queries/rust/locals.scm
new file mode 100644
index 0000000..6428f9b
--- /dev/null
+++ b/helix-22.03-x86_64-windows/runtime/queries/rust/locals.scm
@@ -0,0 +1,17 @@
+; Scopes
+
+(block) @local.scope
+
+; Definitions
+
+(parameter
+ (identifier) @local.definition)
+
+(let_declaration
+ pattern: (identifier) @local.definition)
+
+(closure_parameters (identifier)) @local.definition
+
+; References
+(identifier) @local.reference
+
diff --git a/helix-22.03-x86_64-windows/runtime/queries/rust/textobjects.scm b/helix-22.03-x86_64-windows/runtime/queries/rust/textobjects.scm
new file mode 100644
index 0000000..086db67
--- /dev/null
+++ b/helix-22.03-x86_64-windows/runtime/queries/rust/textobjects.scm
@@ -0,0 +1,35 @@
+(function_item
+ body: (_) @function.inside) @function.around
+
+(struct_item
+ body: (_) @class.inside) @class.around
+
+(enum_item
+ body: (_) @class.inside) @class.around
+
+(union_item
+ body: (_) @class.inside) @class.around
+
+(trait_item
+ body: (_) @class.inside) @class.around
+
+(impl_item
+ body: (_) @class.inside) @class.around
+
+(parameters
+ (_) @parameter.inside)
+
+(closure_parameters
+ (_) @parameter.inside)
+
+(arguments
+ (_) @parameter.inside)
+
+[
+ (line_comment)
+ (block_comment)
+] @comment.inside
+
+(line_comment)+ @comment.around
+
+(block_comment) @comment.around