|
@@ -133,13 +133,20 @@ let collect ctx only_types with_type =
|
|
|
) ctx.m.module_globals;
|
|
|
|
|
|
(* literals *)
|
|
|
- add (ITLiteral "null");
|
|
|
- add (ITLiteral "true");
|
|
|
- add (ITLiteral "false");
|
|
|
- add (ITLiteral "this");
|
|
|
- match ctx.curclass.cl_super with
|
|
|
- | Some _ -> add (ITLiteral "super")
|
|
|
- | None -> ()
|
|
|
+ add (ITLiteral("null",t_dynamic));
|
|
|
+ add (ITLiteral("true",ctx.com.basic.tbool));
|
|
|
+ add (ITLiteral("false",ctx.com.basic.tbool));
|
|
|
+ begin match ctx.curfun with
|
|
|
+ | FunMember | FunConstructor | FunMemberClassLocal ->
|
|
|
+ let t = TInst(ctx.curclass,List.map snd ctx.curclass.cl_params) in
|
|
|
+ add (ITLiteral("this",t));
|
|
|
+ begin match ctx.curclass.cl_super with
|
|
|
+ | Some(c,tl) -> add (ITLiteral("super",TInst(c,tl)))
|
|
|
+ | None -> ()
|
|
|
+ end
|
|
|
+ | _ ->
|
|
|
+ ()
|
|
|
+ end
|
|
|
end;
|
|
|
|
|
|
let module_types = ref [] in
|
|
@@ -213,7 +220,25 @@ let collect ctx only_types with_type =
|
|
|
add (ITType (module_type_of_type t,RMTypeParameter))
|
|
|
) ctx.type_params;
|
|
|
|
|
|
- DynArray.to_list acc
|
|
|
+ let l = DynArray.to_list acc in
|
|
|
+ match with_type with
|
|
|
+ | WithType t ->
|
|
|
+ let rec comp t' =
|
|
|
+ if type_iseq t' t then 0 (* equal types - perfect *)
|
|
|
+ else if t' == t_dynamic then 5 (* dynamic isn't good, but better than incompatible *)
|
|
|
+ else try Type.unify t' t; 1 (* assignable - great *)
|
|
|
+ with Unify_error _ -> match follow t' with
|
|
|
+ | TFun(_,tr) ->
|
|
|
+ if type_iseq tr t then 2 (* function returns our exact type - alright *)
|
|
|
+ else (try Type.unify tr t; 3 (* function returns compatible type - okay *)
|
|
|
+ with Unify_error _ -> 7) (* incompatible function - useless *)
|
|
|
+ | _ ->
|
|
|
+ 6 (* incompatible type - probably useless *)
|
|
|
+ in
|
|
|
+ let l = List.map (fun ck -> ck,comp (DisplayTypes.CompletionKind.get_type ck)) l in
|
|
|
+ let l = List.sort (fun (_,i1) (_,i2) -> compare i1 i2) l in
|
|
|
+ List.map fst l
|
|
|
+ | _ -> l
|
|
|
|
|
|
let handle_unresolved_identifier ctx i p only_types =
|
|
|
let l = collect ctx only_types NoValue in
|