View Source merlin_bindings (merlin v3.0.1)
Summary
Types
Represents a set of bindings.
Represents the state a binding can be in.
Functions
Returns the given node annotated with detailed information about its bindings.
See also: erl_syntax_lib:annotate_bindings/2.
Returns the state()
for given binding in the given node.
Returns the bindings for the given node in the given state.
true
if the given node has a binding with the given name.true
if the given node has a binding with the given name in the given state.Returns a new variable binding guaranteed to be unique with respect to the current set of bindings in the given node.
Returns new variable(s) binding according to the given options.
Types
-type bindings() :: ordsets:ordset(atom()).
Represents a set of bindings.
Each binding is its name as an atom.-type state() :: env | bound | free.
Represents the state a binding can be in.
env
- Bindings from the surrounding scope, i.e. a
fun
's closure. bound
- Bindings with value.
free
- Bindings without a value. It's a compile time error to try to access them.
-type variable() :: merlin:ast().
Functions
-spec annotate(merlin:ast() | [merlin:ast()]) -> merlin:ast() | [merlin:ast()].
Returns the given node annotated with detailed information about its bindings.
Fetches the starting (env
) bindings from the node itself, defaulting to an empty set if none are found. This is in contrast to erl_syntax_lib:annotate_bindings/1
that crashes if no such bindings can be found.See also: annotate/1, annotate/2.
-spec annotate(merlin:ast() | [merlin:ast()], bindings()) -> merlin:ast() | [merlin:ast()].
See also: erl_syntax_lib:annotate_bindings/2.
-spec get(merlin:ast(), Binding) -> state() | unbound when Binding :: atom() | string().
Returns the state()
for given binding in the given node.
Prefers bound
over env
over free
over unbound
. The latter means that the given binding does not occur in the given node, unlike free which means that the binding will occur later.
-spec get_by_state(merlin:ast(), state()) -> bindings().
Returns the bindings for the given node in the given state.
The given node, or one of its ancestors, must have been annotated with its bindings.-spec has(merlin:ast()) -> boolean().
true
if the given node has been annotated with its bindings.
-spec has(merlin:ast(), Binding) -> boolean() when Binding :: atom() | string().
true
if the given node has a binding with the given name.
-spec has(merlin:ast(), Binding, state()) -> boolean() when Binding :: atom() | string().
true
if the given node has a binding with the given name in the given state.
-spec new(Node) -> {Node, variable()} when Node :: merlin:ast().
Returns a new variable binding guaranteed to be unique with respect to the current set of bindings in the given node.
The variable will have its attributes copied from the given node. This means both user annotations, position information, and comments are taken from the given node. In practice it means that stacktraces will point to a more correct location rather then the top of the file.
The given node's bindings will be updated to reflect the new variable.-spec new(Node, Format | Total | Options) -> {Node, variable() | [variable()]} when Node :: merlin:ast(), Format :: io:format(), Total :: pos_integer(), Options :: #{file => string(), format => Format, location => erl_anno:location(), total => Total}.
Returns new variable(s) binding according to the given options.
The options may specify a format
string, which is used to generate the variable name. The format string must contain a single ~tp
which is used to ensure uniqueness.
You may also specify a total
option, which is used to generate multiple variables.
See also: new/1.