mirror of https://github.com/Wilfred/difftastic/
Merge commit '1dabc1c790e07115175057863808085ea60dd08a'
commit
bea5bb235a
@ -0,0 +1,54 @@
|
|||||||
|
; 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
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
|||||||
|
defmodule Foo.Bar.Baz do
|
||||||
|
# ^ definition.module
|
||||||
|
# ^ definition.module
|
||||||
|
# ^ definition.module
|
||||||
|
|
||||||
|
def init(arg) do
|
||||||
|
# ^ definition.function
|
||||||
|
state =
|
||||||
|
arg
|
||||||
|
|> map(&(&1 * 2))
|
||||||
|
# ^ reference.call
|
||||||
|
|> map(&(&1 + 1))
|
||||||
|
# ^ reference.call
|
||||||
|
|
||||||
|
{:ok, arg}
|
||||||
|
end
|
||||||
|
|
||||||
|
def map(list, fun, acc \\ [])
|
||||||
|
# ^ definition.function
|
||||||
|
|
||||||
|
def map([head | rest], fun, acc) do
|
||||||
|
# ^ definition.function
|
||||||
|
map(rest, fun, [fun.(head) | acc])
|
||||||
|
# <- reference.call
|
||||||
|
end
|
||||||
|
|
||||||
|
def map([], _fun, acc), do: Enum.reverse(acc)
|
||||||
|
# ^ definition.function
|
||||||
|
# ^ reference.module
|
||||||
|
# ^ reference.call
|
||||||
|
end
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
defprotocol Countable do
|
||||||
|
# ^ definition.module
|
||||||
|
def count(data)
|
||||||
|
# ^ definition.function
|
||||||
|
end
|
||||||
|
|
||||||
|
defimpl Countable, for: Binary do
|
||||||
|
# ^ reference.module
|
||||||
|
# ^ reference.module
|
||||||
|
def count(binary), do: byte_size(binary)
|
||||||
|
# ^ definition.function
|
||||||
|
# ^ reference.call
|
||||||
|
end
|
||||||
|
|
||||||
|
defimpl Countable, for: List do
|
||||||
|
# ^ reference.module
|
||||||
|
# ^ reference.module
|
||||||
|
def count(list), do: length(list)
|
||||||
|
# ^ definition.function
|
||||||
|
# ^ reference.call
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue