|
@@ -6,36 +6,78 @@ open DisplayException
|
|
|
open DisplayTypes
|
|
|
open DisplayMode
|
|
|
open CompletionItem
|
|
|
+open CompletionType
|
|
|
+open ImportStatus
|
|
|
open ClassFieldOrigin
|
|
|
open DisplayTypes.CompletionResultKind
|
|
|
open Common
|
|
|
open Display
|
|
|
open DisplayPosition
|
|
|
|
|
|
-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)
|
|
|
+let completion_type_of_type ctx t =
|
|
|
+ let get_import_status path =
|
|
|
+ try
|
|
|
+ let mt' = ctx.g.do_load_type_def ctx null_pos {tpackage = []; tname = snd path; tparams = []; tsub = None} in
|
|
|
+ if path <> (t_infos mt').mt_path then Shadowed else Imported
|
|
|
+ with _ ->
|
|
|
+ Unimported
|
|
|
+ in
|
|
|
+ let ctpath path = {
|
|
|
+ ct_dot_path = path;
|
|
|
+ ct_import_status = get_import_status path;
|
|
|
+ } in
|
|
|
+ let rec ppath path tl = {
|
|
|
+ ct_path = ctpath path;
|
|
|
+ ct_params = List.map from_type tl;
|
|
|
+ }
|
|
|
+ and from_type t = match t with
|
|
|
+ | TMono r ->
|
|
|
+ begin match !r with
|
|
|
+ | None -> CTMono
|
|
|
+ | Some t -> from_type t
|
|
|
+ end
|
|
|
+ | TLazy r ->
|
|
|
+ from_type (lazy_type r)
|
|
|
+ | TInst({cl_kind = KTypeParameter _} as c,_) ->
|
|
|
+ CTInst ({
|
|
|
+ ct_path = {
|
|
|
+ ct_dot_path = c.cl_path;
|
|
|
+ ct_import_status = Imported;
|
|
|
+ };
|
|
|
+ ct_params = [];
|
|
|
+ })
|
|
|
+ | TInst(c,tl) ->
|
|
|
+ CTInst (ppath c.cl_path tl)
|
|
|
+ | TEnum(en,tl) ->
|
|
|
+ CTInst (ppath en.e_path tl)
|
|
|
+ | TType(td,tl) ->
|
|
|
+ CTInst (ppath td.t_path tl)
|
|
|
+ | TAbstract(a,tl) ->
|
|
|
+ CTInst (ppath a.a_path tl)
|
|
|
+ | TFun(tl,t) ->
|
|
|
+ let funarg (name,opt,t) = {
|
|
|
+ ct_name = name;
|
|
|
+ ct_optional = opt;
|
|
|
+ ct_type = from_type t;
|
|
|
+ ct_value = None
|
|
|
+ } in
|
|
|
+ CTFunction {
|
|
|
+ ct_args = List.map funarg tl;
|
|
|
+ ct_return = from_type t;
|
|
|
+ }
|
|
|
| TAnon an ->
|
|
|
- begin match !(an.a_status) with
|
|
|
- | Statics {cl_kind = KAbstractImpl a} ->
|
|
|
- an.a_status := AbstractStatics a
|
|
|
- | _ ->
|
|
|
- ()
|
|
|
- end;
|
|
|
- Type.map patch t
|
|
|
- | _ -> Type.map patch t
|
|
|
+ let afield af = {
|
|
|
+ ctf_field = af;
|
|
|
+ ctf_type = from_type af.cf_type;
|
|
|
+ } in
|
|
|
+ CTAnonymous {
|
|
|
+ ct_fields = PMap.fold (fun cf acc -> afield cf :: acc) an.a_fields [];
|
|
|
+ ct_status = !(an.a_status);
|
|
|
+ }
|
|
|
+ | TDynamic t ->
|
|
|
+ CTDynamic (if t == t_dynamic then None else Some (from_type t))
|
|
|
in
|
|
|
- patch t
|
|
|
+ from_type t
|
|
|
|
|
|
let display_module_type ctx mt p = match ctx.com.display.dms_kind with
|
|
|
| DMDefinition -> raise_position [(t_infos mt).mt_name_pos];
|
|
@@ -43,16 +85,18 @@ let display_module_type ctx mt p = match ctx.com.display.dms_kind with
|
|
|
let infos = t_infos mt in
|
|
|
reference_position := (snd infos.mt_path,infos.mt_name_pos,KModuleType)
|
|
|
| DMHover ->
|
|
|
- let t = patch_type ctx (type_of_module_type mt) in
|
|
|
- raise_hover (make_ci_type (CompletionModuleType.of_module_type mt) ImportStatus.Imported (Some t)) p
|
|
|
+ let t = type_of_module_type mt in
|
|
|
+ let ct = completion_type_of_type ctx t in
|
|
|
+ raise_hover (make_ci_type (CompletionModuleType.of_module_type mt) ImportStatus.Imported (Some (t,ct))) p
|
|
|
| _ -> ()
|
|
|
|
|
|
let rec display_type ctx t p =
|
|
|
let dm = ctx.com.display in
|
|
|
match dm.dms_kind with
|
|
|
| DMHover ->
|
|
|
- let t = patch_type ctx t in
|
|
|
- raise_hover (make_ci_expr (mk (TConst TNull) t p)) p
|
|
|
+ let ct = completion_type_of_type ctx t in
|
|
|
+ let ci = make_ci_expr (mk (TConst TNull) t p) (t,ct) in
|
|
|
+ raise_hover ci p
|
|
|
| _ ->
|
|
|
try display_module_type ctx (module_type_of_type t) p
|
|
|
with Exit -> match follow t,follow !t_dynamic_def with
|
|
@@ -76,8 +120,8 @@ let display_variable ctx v p = match ctx.com.display.dms_kind with
|
|
|
| DMDefinition -> raise_position [v.v_pos]
|
|
|
| DMUsage _ -> reference_position := (v.v_name,v.v_pos,KVar)
|
|
|
| DMHover ->
|
|
|
- let t = patch_type ctx v.v_type in
|
|
|
- raise_hover (make_ci_local v t) p
|
|
|
+ let ct = completion_type_of_type ctx v.v_type in
|
|
|
+ raise_hover (make_ci_local v (v.v_type,ct)) p
|
|
|
| _ -> ()
|
|
|
|
|
|
let display_field ctx origin scope cf p = match ctx.com.display.dms_kind with
|
|
@@ -101,8 +145,8 @@ let display_field ctx origin scope cf p = match ctx.com.display.dms_kind with
|
|
|
| Self (TClassDecl c),CFSConstructor,TFun(tl,_) -> {cf with cf_type = TFun(tl,TInst(c,List.map snd c.cl_params))}
|
|
|
| _ -> cf
|
|
|
in
|
|
|
- let t = patch_type ctx cf.cf_type in
|
|
|
- raise_hover (make_ci_class_field (CompletionClassField.make cf scope origin true) t) p
|
|
|
+ let ct = completion_type_of_type ctx cf.cf_type in
|
|
|
+ raise_hover (make_ci_class_field (CompletionClassField.make cf scope origin true) (cf.cf_type,ct)) p
|
|
|
| _ -> ()
|
|
|
|
|
|
let maybe_display_field ctx origin scope cf p =
|
|
@@ -112,8 +156,8 @@ let display_enum_field ctx en ef p = match ctx.com.display.dms_kind with
|
|
|
| DMDefinition -> raise_position [ef.ef_name_pos]
|
|
|
| DMUsage _ -> reference_position := (ef.ef_name,ef.ef_name_pos,KEnumField)
|
|
|
| DMHover ->
|
|
|
- let t = patch_type ctx ef.ef_type in
|
|
|
- raise_hover (make_ci_enum_field (CompletionEnumField.make ef (Self (TEnumDecl en)) true) t) p
|
|
|
+ let ct = completion_type_of_type ctx ef.ef_type in
|
|
|
+ raise_hover (make_ci_enum_field (CompletionEnumField.make ef (Self (TEnumDecl en)) true) (ef.ef_type,ct)) p
|
|
|
| _ -> ()
|
|
|
|
|
|
let display_meta com meta p = match com.display.dms_kind with
|
|
@@ -164,7 +208,8 @@ let check_field_modifiers ctx c cf override display_modifier =
|
|
|
let missing_fields = List.fold_left (fun fields cf -> PMap.remove cf.cf_name fields) all_fields c.cl_ordered_fields in
|
|
|
let l = PMap.fold (fun (c,cf) fields ->
|
|
|
let origin = Parent (TClassDecl c) in
|
|
|
- make_ci_class_field (CompletionClassField.make cf CFSMember origin true) cf.cf_type :: fields
|
|
|
+ let ct = completion_type_of_type ctx cf.cf_type in
|
|
|
+ make_ci_class_field (CompletionClassField.make cf CFSMember origin true) (cf.cf_type,ct) :: fields
|
|
|
) missing_fields [] in
|
|
|
raise_fields l CROverride None
|
|
|
| _ -> ()
|