View Source merlin_module (merlin v3.0.1)
Helpers for working with forms representing a module.
They also work with lists of pretty much any node, but most makes only sense if you have a list of forms representing a module.Summary
Types
erl_syntax_lib:analyze_forms/1.Represents a list of forms.
FunctionName/Arity pair.Functions
Similar to erl_syntax_lib:analyze_forms/1 with some differences noted below.
analyze/1, but also extracts and appends any inline -compile options to the given one.Annotate the given module forms according to the given options.
Returns the given Forms with an -export attribute for the given functions.
-file attribute in Forms, or none if no such attribute is found.undefined if it can't be found.-file attribute in Forms, or none if no such attribute is found.-module attribute in Forms, or '' if not found.Types
-type analysis() :: #{attributes := #{spec => #{function_name() := {Arguments :: [merlin:ast()], Guard :: none | merlin:ast(), Return :: merlin:ast()}}, type => #{function_name() := {TypeArguments :: [merlin:ast()], Type :: merlin:ast()}}, opaque => #{function_name() := {TypeArguments :: [merlin:ast()], Type :: merlin:ast()}}, compile => [compile:option()], AttributeName :: atom() => AttributeArguments :: [term()]}, exports := ordsets:ordset(extended_function_name()), export_types := ordsets:ordset(function_name()), file := string(), functions := ordsets:ordset(function_name()), imports := #{module() := ordsets:ordset(extended_function_name())}, module_imports := ordsets:ordset(module()), records := #{RecordTag :: atom() := #{Field :: atom() := {Default :: none | merlin:ast(), Type :: none | merlin:ast()}}}, module => module(), errors => [merlin:ast()], warnings => [merlin:ast()]}.
-type extended_function_name() :: atom() | {atom(), arity()} | {module(), atom()}.
erl_syntax_lib:analyze_forms/1.
-type forms() :: [merlin:ast()].
Represents a list of forms.
That is, a list of nodes that represents top level constructs. For example an attribute (-module) or a function definition.
. (period).
-type function_name() :: {atom(), arity()}.
FunctionName/Arity pair.
Functions
-spec analyze([merlin:ast()]) -> analysis().
Similar to erl_syntax_lib:analyze_forms/1 with some differences noted below.
First off it returns maps instead of lists when possible, all fields except module are present. The latter is left alone to make it easy to determine if the module attribute is missing. There's a couple of extra fields, namely file with the value of the first -file attribute or "", and export_types as an analogue of exports but for -export_type.
The attributes are returned as a map from attribute name to a list of attribute nodes, except for spec, type and opaque. These are returned as map from {Function, Arity} to a simplified form of their attribute arguments.
erl_syntax_lib:analyze_forms/1, this guarantees that most lists are sorted and contain no duplicates. This is accomplished by turning them into ordsets.See also: analysis().
-spec analyze([merlin:ast()], [compile:option()]) -> {analysis(), [compile:option()]}.
analyze/1, but also extracts and appends any inline -compile options to the given one.
-spec annotate([merlin:ast()]) -> merlin:parse_transform_return().
Equivalent to annotate(ModuleForms, [bindings, file, resolve_calls, resolve_types]).
-spec annotate(ModuleForms, Options) -> merlin:parse_transform_return(ModuleForms) when ModuleForms :: [merlin:ast()], Options :: [Option | {Option, boolean()}], Option :: bindings | file | resolve_calls | resolve_types.
Annotate the given module forms according to the given options.
It always annotates each function definition with a is_exportedannotation.
bindings- See
erl_syntax_lib:annotate_bindings/2 compile- The analysis contains a
compilekey that merges then given compile options with all-compileattributes inModuleForms. Seeanalyze/2 file- Each node is annotated with the current file, as determined by the most recent
-fileattribute. resolve_calls- Resolves local and remote calls according to the
-importattributes, if any. For all successfully resolved calls, this sets both amoduleandis_exportedannotation on theapplicationnode. resolve_types- Marks exported local types with
is_exportedannotation onuser_type_applicationnodes.
Returns the given Forms with an -export attribute for the given functions.
If the -module attribute is present in the given Forms, then the -export is inserted just after the -module. In addition, if the -module attribute form has an analysis annotation, i.e. from annotate/2, then it is used to avoid re-exporting any functions already exported.
-export is prepended to the given forms.
-spec file([merlin:ast()]) -> file:filename().
-file attribute in Forms, or none if no such attribute is found.
-spec find_source(module()) -> file:filename() | undefined.
undefined if it can't be found.
-spec line([merlin:ast()]) -> erl_anno:line().
-file attribute in Forms, or none if no such attribute is found.
-spec name([merlin:ast()]) -> module() | ''.
-module attribute in Forms, or '' if not found.