Skip to content

Commit

Permalink
feat(queries): add folds, indents, injections, locals, and tags, upda…
Browse files Browse the repository at this point in the history
…te highlights
  • Loading branch information
amaanq committed Mar 23, 2023
1 parent 20f972a commit f3122c6
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 2 deletions.
39 changes: 39 additions & 0 deletions queries/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
(use_statement)
(actor_definition)
(class_definition)
(primitive_definition)
(interface_definition)
(trait_definition)
(struct_definition)

(constructor)
(method)
(behavior)

(parameters)

(type)

(if_statement)
(iftype_statement)
(elseif_block)
(elseiftype_block)
(else_block)
(for_statement)
(while_statement)
(try_statement)
(with_statement)
(repeat_statement)
(recover_statement)
(match_statement)
(case_statement)
(parenthesized_expression)
(tuple_expression)

(array_literal)
(object_literal)
(string)

(block_comment)
] @fold
6 changes: 4 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

(iftype_statement "end" @conditional)

(match_expression "end" @conditional)
(match_statement "end" @conditional)

; Repeats

Expand All @@ -99,7 +99,7 @@

(try_statement "end" @exception)

(recover_expression "end" @exception)
(recover_statement "end" @exception)

; Attributes

Expand Down Expand Up @@ -147,6 +147,8 @@

; Types

(type_alias (identifier) @type.definition)

(base_type name: (identifier) @type)

(generic_parameter (identifier) @type)
Expand Down
60 changes: 60 additions & 0 deletions queries/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
(use_statement)
(actor_definition)
(class_definition)
(primitive_definition)
(interface_definition)
(trait_definition)
(struct_definition)

(constructor)
(method)
(behavior)

(parameters)

(if_block)
(then_block)
(elseif_block)
(else_block)
(iftype_statement)
(elseiftype_block)
(do_block)
(match_statement)
(parenthesized_expression)
(tuple_expression)

(array_literal)
(object_literal)
] @indent

(try_statement (block) @indent)

(repeat_statement (block) @indent)

(recover_statement (block) @indent)

(return_statement (block) @indent)

(continue_statement (block) @indent)

(break_statement (block) @indent)

[
"}"
"]"
")"
] @indent_end

[ "{" "}" ] @branch

[ "[" "]" ] @branch

[ "(" ")" ] @branch

[
(ERROR)
(string)
(line_comment)
(block_comment)
] @auto
4 changes: 4 additions & 0 deletions queries/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
(line_comment)
(block_comment)
] @comment
79 changes: 79 additions & 0 deletions queries/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
; Scopes

[
(use_statement)
(actor_definition)
(class_definition)
(primitive_definition)
(interface_definition)
(trait_definition)
(struct_definition)

(constructor)
(method)
(behavior)

(if_statement)
(iftype_statement)
(elseif_block)
(elseiftype_block)
(else_block)
(for_statement)
(while_statement)
(try_statement)
(with_statement)
(repeat_statement)
(recover_statement)
(match_statement)
(case_statement)
(parenthesized_expression)
(tuple_expression)

(array_literal)
(object_literal)
] @scope

; References

(identifier) @reference

; Definitions

(field
name: (identifier) @definition.field)

(use_statement
(identifier) @definition.import)

(constructor
(identifier) @definition.method)

(method
(identifier) @definition.method)

(behavior
(identifier) @definition.method)

(actor_definition
(identifier) @definition.type)

(type_alias
(identifier) @definition.type)

(class_definition
(identifier) @definition.type)

(primitive_definition
(identifier) @definition.type)

(interface_definition
(identifier) @definition.type)

(trait_definition
(identifier) @definition.type)

(struct_definition
(identifier) @definition.type)

(parameter
name: (identifier) @definition.parameter)
38 changes: 38 additions & 0 deletions queries/tags.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;Class definitions @definition.class
;Function definitions @definition.function
;Interface definitions @definition.interface
;Method definitions @definition.method
;Module definitions @definition.module
;Function/method calls @reference.call
;Class reference @reference.class
;Interface implementation @reference.implementation
(
(identifier) @reference.class
(#match? @reference.class "^_*[A-Z][a-zA-Z0-9_]*$")
)

(class_definition (identifier) @name) @definition.class
(actor_definition (identifier) @name) @definition.class
(primitive_definition (identifier) @name) @definition.class
(struct_definition (identifier) @name) @definition.class
(type_alias (identifier) @name) @definition.class

(trait_definition (identifier) @name) @definition.interface
(interface_definition (identifier) @name) @definition.interface

(method (identifier) @name) @definition.method
(behavior (identifier) @name) @definition.method

(class_definition (type) @name) @reference.implementation
(actor_definition (type) @name) @reference.implementation
(primitive_definition (type) @name) @reference.implementation
(struct_definition (type) @name) @reference.implementation
(type_alias (type) @name) @reference.implementation

; calls - not catching all possible call cases of callees for capturing the method name
(call_expression callee: [(identifier) (ffi_identifier)] @name) @reference.call
(call_expression callee: (generic_expression [(identifier) (ffi_identifier)] @name)) @reference.call
(call_expression callee: (member_expression (identifier) @name .)) @reference.call
(call_expression callee: (member_expression (generic_expression [(identifier) (ffi_identifier)] @name) .)) @reference.call
; TODO: add more possible callee expressions
(call_expression) @reference.call

0 comments on commit f3122c6

Please sign in to comment.