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.

However if you either give it an erl_syntax node or set a erl_syntax user annotation, it will return an erl_syntax node.

Summary

Types

Reprensent a single builtin annotation property.
The different types of builtin annotations.

Represents a list of annotations.

Functions

Returns the given syntax node without the given annotation.

Returns all annotations for the given syntax node.

Get the value of the given annotation from the given syntax node.
Get the value of the given annotation from the given syntax node. If the annotation is not present, return the given default value.

See also: get/2.

Returns the annotation for the given syntax node.

Returns true if the given syntax node has the given annotation, false otherwise.
Returns the given syntax node with its existing annotations merged with the given ones.
Set the given annotation to the given value on the given syntax node.

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()}.
Reprensent a single builtin annotation property.
-type erl_annotation_key() :: line | column | file | generated | location | record | text.
The different types of builtin annotations.
-type erl_annotations() :: [erl_annotation()].

Represents a list of annotations.

This is also the internal format of erl_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 delete line 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 merges erl_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().
Get the value of the given annotation from the given syntax node.
-spec get(Node, Key, Default) -> term() when Node :: merlin:ast(), Key :: atom(), Default :: term().
Get the value of the given annotation from the given syntax node. If the annotation is not present, return the given default value.

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 around erl_syntax:get_pos/1, added for completeness.
-spec has(Node, Key) -> boolean() when Node :: merlin:ast(), Key :: atom().
Returns true if the given syntax node has the given annotation, false otherwise.
Link to this function

merge(Node, Annotations)

View Source
-spec merge(Node, erl_annotations() | #{atom() => term()}) -> Node when Node :: merlin:ast().
Returns the given syntax node with its existing annotations merged with the given ones.
-spec set(Node, Key, Value) -> Node when Node :: merlin:ast(), Key :: atom(), Value :: term().
Set the given annotation to the given value on the given syntax node.

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 to erl_syntax:set_pos/2, but preserves the representation of the given syntax node.