Skip to content

Commit

Permalink
Support tag query for reference
Browse files Browse the repository at this point in the history
  • Loading branch information
malkoG committed Nov 3, 2024
1 parent 968612b commit c2cc099
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 89 deletions.
127 changes: 40 additions & 87 deletions queries/tags.scm
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
;;;;;;;;;; Reference treesitter python
;(module (expression_statement (assignment left: (identifier) @name) @definition.constant))
;
;(class_definition
; name: (identifier) @name) @definition.class
;
;(function_definition
; name: (identifier) @name) @definition.function
;
;(call
; function: [
; (identifier) @name
; (attribute
; attribute: (identifier) @name)
; ]) @reference.call

(class_definition
name: (identifier) @name) @definition.class
Expand Down Expand Up @@ -59,81 +44,49 @@
(new_expression
(type_identifier) @name) @reference.class

;(scoped_identifier
; scope: (identifier) @type
; name: (identifier) @type)
; (#match? @type "^[a-zA-Z]")
;@definition.type
;@property

;(call
; function: [
; (identifier) @name
; (attribute
; attribute: (identifier) @name)
; ]) @reference.call



;;;;;;;;;;;;;;;;; Reference treesitter elixir
;; Definitions
;
;; * modules and protocols
;(call
; target: (identifier) @ignore
; (arguments (alias) @name)
; (#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
;
;; * functions/macros
;(call
; target: (identifier) @ignore
; (arguments
; [
; ; zero-arity functions with no parentheses
; (identifier) @name
; ; regular function clause
; (call target: (identifier) @name)
; ; function clause with a guard clause
; (binary_operator
; left: (call target: (identifier) @name)
; operator: "when")
; ])
; (#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @definition.function
;
;; References
;
;; ignore calls to kernel/special-forms keywords
;(call
; target: (identifier) @ignore
; (#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defmodule|defprotocol|defimpl|defstruct|defexception|defoverridable|alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
;
;; ignore module attributes
;(unary_operator
; operator: "@"
; operand: (call
; target: (identifier) @ignore))
;
;; * function call
;(call
; target: [
; ; local
; (identifier) @name
; ; remote
; (dot
; right: (identifier) @name)
; ]) @reference.call
;
;; * pipe into function call
;(binary_operator
; operator: "|>"
; right: (identifier) @name) @reference.call
;
;; * modules
;(alias) @name @reference.module

(enum_declaration
name: (identifier) @name) @definition.enum

(function_signature
name: (identifier) @name) @definition.function

(initialized_variable_definition
name: (identifier)
value: (identifier) @name
value: (selector
"!"?
(argument_part
(arguments
(argument)*))?)?) @reference.class

(assignment_expression
left: (assignable_expression
(identifier)
(unconditional_assignable_selector
"."
(identifier) @name))) @reference.call

(assignment_expression
left: (assignable_expression
(identifier)
(conditional_assignable_selector
"?."
(identifier) @name))) @reference.call

((identifier) @name
(selector
"!"?
(conditional_assignable_selector
"?." (identifier) @name)?
(unconditional_assignable_selector
"."? (identifier) @name)?
(argument_part
(arguments
(argument)*))?)*
(cascade_section
(cascade_selector
(identifier)) @name
(argument_part
(arguments
(argument)*))?)?) @reference.call

24 changes: 22 additions & 2 deletions test/tags/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,36 @@ extension SomeExtension on SomeClass {
}

void main() {
final instance = SomeClass();
final instance = SomeClass(1, 2, 3).method();
// ^ @reference.class
// ^ @reference.call
SomeClass().getter;
instance.str;
instance.getter;
// ^ @reference.call
instance?.getter;
// ^ @reference.call
instance.setter = 12;
// ^ @reference.call
instance?.setter = 12;
// ^ @reference.call
instance.method();
topLevelFn();
// ^ @reference.call
instance?.method()!.length();
// ^ @reference.call
topLevelFn(1, 2)!.length?.toString();
// ^ @reference.call
topLevelFn;
// ^ @reference.call
instance.extensionMethod();
instance!.extensionMethod();
// ^ @reference.call
instance
..method()
// ^ @reference.call
..str
// ^ @reference.call
..getter;
// ^ @reference.call
}

0 comments on commit c2cc099

Please sign in to comment.