|
@@ -170,19 +170,40 @@ module ExprPreprocessing = struct
|
|
|
end
|
|
|
|
|
|
module DisplayEmitter = struct
|
|
|
- let display_module_type dm mt p = match dm.dms_kind with
|
|
|
+
|
|
|
+ let requires_import ctx path =
|
|
|
+ try
|
|
|
+ let mt' = ctx.g.do_load_type_def ctx null_pos {tpackage = []; tname = snd path; tparams = []; tsub = None} in
|
|
|
+ path <> (t_infos mt').mt_path
|
|
|
+ with _ ->
|
|
|
+ true
|
|
|
+
|
|
|
+ let patch_type ctx t =
|
|
|
+ let rec patch t = match t with
|
|
|
+ | TInst(c,tl) when not (requires_import ctx c.cl_path) -> TInst({c with cl_path = ([],snd c.cl_path)},List.map patch tl)
|
|
|
+ | TEnum(en,tl) when not (requires_import ctx en.e_path) -> TEnum({en with e_path = ([],snd en.e_path)},List.map patch tl)
|
|
|
+ | TType(td,tl) when not (requires_import ctx td.t_path) -> TType({td with t_path = ([],snd td.t_path)},List.map patch tl)
|
|
|
+ | TAbstract(a,tl) when not (requires_import ctx a.a_path) -> TAbstract({a with a_path = ([],snd a.a_path)},List.map patch tl)
|
|
|
+ | _ -> Type.map patch t
|
|
|
+ in
|
|
|
+ patch t
|
|
|
+
|
|
|
+ let display_module_type ctx mt p = match ctx.com.display.dms_kind with
|
|
|
| DMDefinition -> raise_position [(t_infos mt).mt_name_pos];
|
|
|
| DMUsage _ -> reference_position := (t_infos mt).mt_name_pos
|
|
|
- | DMHover -> raise_type (type_of_module_type mt) p None
|
|
|
+ | DMHover -> raise_type (patch_type ctx (type_of_module_type mt)) p None
|
|
|
| _ -> ()
|
|
|
|
|
|
- let rec display_type dm t p = match dm.dms_kind with
|
|
|
- | DMHover -> raise_type t p None
|
|
|
+ let rec display_type ctx t p =
|
|
|
+ let dm = ctx.com.display in
|
|
|
+ match dm.dms_kind with
|
|
|
+ | DMHover ->
|
|
|
+ raise_type (patch_type ctx t) p None
|
|
|
| _ ->
|
|
|
- try display_module_type dm (module_type_of_type t) p
|
|
|
+ try display_module_type ctx (module_type_of_type t) p
|
|
|
with Exit -> match follow t,follow !t_dynamic_def with
|
|
|
| _,TDynamic _ -> () (* sanity check in case it's still t_dynamic *)
|
|
|
- | TDynamic _,_ -> display_type dm !t_dynamic_def p
|
|
|
+ | TDynamic _,_ -> display_type ctx !t_dynamic_def p
|
|
|
| _ -> ()
|
|
|
|
|
|
let check_display_type ctx t p =
|
|
@@ -192,20 +213,20 @@ module DisplayEmitter = struct
|
|
|
in
|
|
|
let maybe_display_type () =
|
|
|
if ctx.is_display_file && is_display_position p then
|
|
|
- display_type ctx.com.display t p
|
|
|
+ display_type ctx t p
|
|
|
in
|
|
|
match ctx.com.display.dms_kind with
|
|
|
| DMStatistics -> add_type_hint()
|
|
|
| DMUsage _ -> add_type_hint(); maybe_display_type()
|
|
|
| _ -> maybe_display_type()
|
|
|
|
|
|
- let display_variable dm v p = match dm.dms_kind with
|
|
|
+ let display_variable ctx v p = match ctx.com.display.dms_kind with
|
|
|
| DMDefinition -> raise_position [v.v_pos]
|
|
|
| DMUsage _ -> reference_position := v.v_pos
|
|
|
- | DMHover -> raise_type v.v_type p None
|
|
|
+ | DMHover -> raise_type (patch_type ctx v.v_type) p None
|
|
|
| _ -> ()
|
|
|
|
|
|
- let display_field dm c cf p = match dm.dms_kind with
|
|
|
+ let display_field ctx c cf p = match ctx.com.display.dms_kind with
|
|
|
| DMDefinition -> raise_position [cf.cf_name_pos]
|
|
|
| DMUsage _ -> reference_position := cf.cf_name_pos
|
|
|
| DMHover ->
|
|
@@ -218,16 +239,16 @@ module DisplayEmitter = struct
|
|
|
| Some c,TFun(tl,_) when cf.cf_name = "new" -> TFun(tl,TInst(c,List.map snd c.cl_params))
|
|
|
| _ -> t
|
|
|
in
|
|
|
- raise_type t p cf.cf_doc
|
|
|
+ raise_type (patch_type ctx t) p cf.cf_doc
|
|
|
| _ -> ()
|
|
|
|
|
|
let maybe_display_field ctx c cf p =
|
|
|
- if is_display_position p then display_field ctx.com.display c cf p
|
|
|
+ if is_display_position p then display_field ctx c cf p
|
|
|
|
|
|
- let display_enum_field dm ef p = match dm.dms_kind with
|
|
|
+ let display_enum_field ctx ef p = match ctx.com.display.dms_kind with
|
|
|
| DMDefinition -> raise_position [ef.ef_name_pos]
|
|
|
| DMUsage _ -> reference_position := ef.ef_name_pos
|
|
|
- | DMHover -> raise_type ef.ef_type p ef.ef_doc
|
|
|
+ | DMHover -> raise_type (patch_type ctx ef.ef_type) p ef.ef_doc
|
|
|
| _ -> ()
|
|
|
|
|
|
let display_meta com meta = match com.display.dms_kind with
|