View Source merlin_annotations (merlin v3.0.1)
This module allows for a unified handling of vanilla annotations and user annotations.
It maintains the representation of the given syntax node as much as possible, This means that if you given it a vanilla syntax node and set/3
an erl_anno
annotation, it will return a vanilla syntax node with the given annotation.
erl_syntax
node or set a erl_syntax user annotation, it will return an erl_syntax
node.
Summary
Types
Represents a list of annotations.
Functions
Returns the given syntax node without the given annotation.
Returns all annotations for the given syntax node.
See also: get/2.
Returns the annotation for the given syntax node.
true
if the given syntax node has the given annotation, false
otherwise.See also: erl_anno, erl_syntax:set_ann/2, erl_syntax:set_pos/2.
Returns the given node with the given annotation.
Types
-type erl_annotation() :: {line, erl_anno:line()} | {column, erl_anno:column()} | {file, file:filename_all()} | {generated, boolean()} | {location, erl_anno:location()} | {record, boolean()} | {text, string()}.
-type erl_annotation_key() :: line | column | file | generated | location | record | text.
-type erl_annotations() :: [erl_annotation()].
Represents a list of annotations.
This is also the internal format oferl_anno
if some other annotation than erl_anno:line()
and/or erl_anno:line()
has been set.
Functions
-spec delete(Node, Key) -> Node when Node :: merlin:ast(), Key :: atom().
Returns the given syntax node without the given annotation.
You are not allowed to deleteline
or location
.
-spec get(merlin:ast()) -> #{column => erl_anno:column(), file => file:filename(), generated => boolean(), line := erl_anno:line(), location := erl_anno:location(), record => boolean(), text => string(), atom() => term()}.
Returns all annotations for the given syntax node.
This mergeserl_anno
annotations with erl_syntax
user annotations. Notably, it always includes both line
and location
.
-spec get(Node, Annotation) -> term() when Node :: merlin:ast(), Annotation :: atom().
-spec get(Node, Key, Default) -> term() when Node :: merlin:ast(), Key :: atom(), Default :: term().
See also: get/2.
-spec get_anno(merlin:ast()) -> erl_anno:anno().
Returns the annotation for the given syntax node.
This is just a wrapper arounderl_syntax:get_pos/1
, added for completeness.
-spec has(Node, Key) -> boolean() when Node :: merlin:ast(), Key :: atom().
true
if the given syntax node has the given annotation, false
otherwise.
-spec merge(Node, erl_annotations() | #{atom() => term()}) -> Node when Node :: merlin:ast().
-spec set(Node, Key, Value) -> Node when Node :: merlin:ast(), Key :: atom(), Value :: term().
See also: erl_anno, erl_syntax:set_ann/2, erl_syntax:set_pos/2.
-spec set_anno(Node, erl_anno:anno()) -> Node when Node :: merlin:ast().
Returns the given node with the given annotation.
Similar toerl_syntax:set_pos/2
, but preserves the representation of the given syntax node.