Merlin_analysis.Type_enclosing
SourceProvides type information around the cursor.
The information comes from two sources: 1. enclosing AST nodes: we just retrieve the types in the typedtree 2. if the cursor is on an identifier, by typing it in the current environment
(2) is primarily useful in the following situations:
'a
).Furthermore, (2) has a finer granularity than (1): when the cursor is in the middle of a longident, e.g. Foo.B|ar.Baz.lol
(with | being the cursor), then we'll have one AST node covering the whole ident. But what we reconstruct gives us: Foo.Bar
, Foo.Bar.Baz
, Foo.Bar.Baz.lol
; and we return the type for each of them. These are what we call "small enclosings".
There are however some issues with the small enclosings:
one has to be careful of the context (obviously that information won't be available in case of parse errors); because a given identifier could exist in different namespaces, for instance:
type t
module type t = sig val t : t end
let t (t : t) : (module t) = (module struct let t = t end)
type type_info =
| Modtype of Ocaml_typing.Env.t * Ocaml_typing.Types.module_type
| Type of Ocaml_typing.Env.t * Ocaml_typing.Types.type_expr
| Type_decl of Ocaml_typing.Env.t
* Ocaml_typing.Ident.t
* Ocaml_typing.Types.type_declaration
| String of string
type typed_enclosings =
(Ocaml_parsing.Location.t * type_info * Query_protocol.is_tail_position) list
val from_nodes :
path:
(Ocaml_typing.Env.t
* Merlin_specific.Browse_raw.node
* Query_protocol.is_tail_position)
list ->
typed_enclosings
val from_reconstructed :
nodes:(Ocaml_typing.Env.t * Merlin_specific.Browse_raw.node) list ->
cursor:Lexing.position ->
verbosity:Merlin_kernel.Mconfig.Verbosity.t ->
string Ocaml_parsing.Location.loc list ->
typed_enclosings