Skip to content

Commit 1516959

Browse files
add tags.scm queries (#18)
* add tags.scm queries * mark defimpl modules as references to the interface * mark modules as module references instead of calls * define protocol modules as modules, remove interface references
1 parent 94d6471 commit 1516959

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

queries/tags.scm

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; Definitions
2+
3+
; * modules and protocols
4+
(call
5+
target: (identifier) @ignore
6+
(arguments (alias) @name)
7+
(#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
8+
9+
; * functions/macros
10+
(call
11+
target: (identifier) @ignore
12+
(arguments
13+
[
14+
; zero-arity functions with no parentheses
15+
(identifier) @name
16+
; regular function clause
17+
(call target: (identifier) @name)
18+
; function clause with a guard clause
19+
(binary_operator
20+
left: (call target: (identifier) @name)
21+
operator: "when")
22+
])
23+
(#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @definition.function
24+
25+
; References
26+
27+
; ignore calls to kernel/special-forms keywords
28+
(call
29+
target: (identifier) @ignore
30+
(#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)$"))
31+
32+
; ignore module attributes
33+
(unary_operator
34+
operator: "@"
35+
operand: (call
36+
target: (identifier) @ignore))
37+
38+
; * function call
39+
(call
40+
target: [
41+
; local
42+
(identifier) @name
43+
; remote
44+
(dot
45+
right: (identifier) @name)
46+
]) @reference.call
47+
48+
; * pipe into function call
49+
(binary_operator
50+
operator: "|>"
51+
right: (identifier) @name) @reference.call
52+
53+
; * modules
54+
(alias) @name @reference.module

0 commit comments

Comments
 (0)