11open Std
2+ open Type_utils
23
34let log_section = " type-enclosing"
45let { Logger. log } = Logger. for_section log_section
@@ -7,11 +8,34 @@ type type_info =
78 | Modtype of Env .t * Types .module_type
89 | Type of Env .t * Types .type_expr
910 | Type_decl of Env .t * Ident .t * Types .type_declaration
11+ | Type_constr of Env .t * Types .constructor_description
1012 | String of string
1113
1214type typed_enclosings =
1315 (Location .t * type_info * Query_protocol .is_tail_position ) list
1416
17+ let print_type ~verbosity type_info =
18+ let ppf = Format. str_formatter in
19+ let wrap_printing_env = Printtyp. wrap_printing_env ~verbosity in
20+ match type_info with
21+ | Type (env , t ) ->
22+ wrap_printing_env env (fun () ->
23+ print_type_with_decl ~verbosity env ppf t;
24+ Format. flush_str_formatter () )
25+ | Type_decl (env , id , t ) ->
26+ wrap_printing_env env (fun () ->
27+ Printtyp. type_declaration env id ppf t;
28+ Format. flush_str_formatter () )
29+ | Type_constr (env , cd ) ->
30+ wrap_printing_env env (fun () ->
31+ print_constr ~verbosity env ppf cd;
32+ Format. flush_str_formatter () )
33+ | Modtype (env , m ) ->
34+ wrap_printing_env env (fun () ->
35+ Printtyp. modtype env ppf m;
36+ Format. flush_str_formatter () )
37+ | String s -> s
38+
1539let from_nodes ~path =
1640 let aux (env , node , tail ) =
1741 let open Browse_raw in
@@ -89,14 +113,10 @@ let from_reconstructed ~nodes ~cursor ~verbosity exprs =
89113 (* Retrieve the type from the AST when it is possible *)
90114 | Some (Context. Constructor (cd , loc )) ->
91115 log ~title: " from_reconstructed" " ctx: constructor %s" cd.cstr_name;
92- let ppf, to_string = Format. to_string () in
93- Type_utils. print_constr ~verbosity env ppf cd;
94- Some (loc, String (to_string () ), `No )
116+ Some (loc, Type_constr (env, cd), `No )
95117 | Some (Context. Label { lbl_name; lbl_arg; _ } ) ->
96118 log ~title: " from_reconstructed" " ctx: label %s" lbl_name;
97- let ppf, to_string = Format. to_string () in
98- Type_utils. print_type_with_decl ~verbosity env ppf lbl_arg;
99- Some (loc, String (to_string () ), `No )
119+ Some (loc, Type (env, lbl_arg), `No )
100120 | Some Context. Constant -> None
101121 | _ -> (
102122 let context = Option. value ~default: Context. Expr context in
0 commit comments