Browse Source

[display] deal with static extension hovers properly

closes #11285
Simon Krajewski 2 years ago
parent
commit
2d056193da

+ 4 - 1
src/context/typecore.ml

@@ -739,10 +739,13 @@ let get_next_stored_typed_expr_id =
 	let uid = ref 0 in
 	let uid = ref 0 in
 	(fun() -> incr uid; !uid)
 	(fun() -> incr uid; !uid)
 
 
+let make_stored_id_expr id p =
+	(EConst (Int (string_of_int id, None))), p
+
 let store_typed_expr com te p =
 let store_typed_expr com te p =
 	let id = get_next_stored_typed_expr_id() in
 	let id = get_next_stored_typed_expr_id() in
 	com.stored_typed_exprs#add id te;
 	com.stored_typed_exprs#add id te;
-	let eid = (EConst (Int (string_of_int id, None))), p in
+	let eid = make_stored_id_expr id p in
 	id,((EMeta ((Meta.StoredTypedExpr,[],null_pos), eid)),p)
 	id,((EMeta ((Meta.StoredTypedExpr,[],null_pos), eid)),p)
 
 
 let push_this ctx e = match e.eexpr with
 let push_this ctx e = match e.eexpr with

+ 2 - 2
src/typing/calls.ml

@@ -214,8 +214,8 @@ let rec acc_get ctx g =
 	| AKUsingAccessor sea | AKUsingField sea when ctx.in_display ->
 	| AKUsingAccessor sea | AKUsingField sea when ctx.in_display ->
 		(* Generate a TField node so we can easily match it for position/usage completion (issue #1968) *)
 		(* Generate a TField node so we can easily match it for position/usage completion (issue #1968) *)
 		let e_field = FieldAccess.get_field_expr sea.se_access FGet in
 		let e_field = FieldAccess.get_field_expr sea.se_access FGet in
-		(* TODO *)
-		(* let ec = {ec with eexpr = (TMeta((Meta.StaticExtension,[],null_pos),ec))} in *)
+		let id,_ = store_typed_expr ctx.com sea.se_this e_field.epos in
+		let e_field = {e_field with eexpr = (TMeta((Meta.StaticExtension,[make_stored_id_expr id e_field.epos],null_pos),e_field))} in
 		let t = match follow e_field.etype with
 		let t = match follow e_field.etype with
 			| TFun (_ :: args,ret) -> TFun(args,ret)
 			| TFun (_ :: args,ret) -> TFun(args,ret)
 			| t -> t
 			| t -> t

+ 0 - 4
src/typing/macroContext.ml

@@ -1055,7 +1055,3 @@ let interpret ctx =
 
 
 let setup() =
 let setup() =
 	Interp.setup Interp.macro_api
 	Interp.setup Interp.macro_api
-
-let type_stored_expr ctx e1 =
-	let id = match e1 with (EConst (Int (s, _)),_) -> int_of_string s | _ -> die "" __LOC__ in
-	TyperBase.get_stored_typed_expr ctx id

+ 1 - 1
src/typing/matcher/exprToPattern.ml

@@ -436,7 +436,7 @@ let rec make pctx toplevel t e =
 			ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) MGet (WithType.with_type t));
 			ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) MGet (WithType.with_type t));
 			pat
 			pat
 		| EMeta((Meta.StoredTypedExpr,_,_),e1) ->
 		| EMeta((Meta.StoredTypedExpr,_,_),e1) ->
-			let e1 = MacroContext.type_stored_expr ctx e1 in
+			let e1 = TyperBase.type_stored_expr ctx e1 in
 			loop (TExprToExpr.convert_expr e1)
 			loop (TExprToExpr.convert_expr e1)
 		| _ ->
 		| _ ->
 			fail()
 			fail()

+ 1 - 1
src/typing/typer.ml

@@ -1672,7 +1672,7 @@ and type_meta ?(mode=MGet) ctx m e1 with_type p =
 			| _ -> e()
 			| _ -> e()
 			end
 			end
 		| (Meta.StoredTypedExpr,_,_) ->
 		| (Meta.StoredTypedExpr,_,_) ->
-			MacroContext.type_stored_expr ctx e1
+			type_stored_expr ctx e1
 		| (Meta.NoPrivateAccess,_,_) ->
 		| (Meta.NoPrivateAccess,_,_) ->
 			ctx.meta <- List.filter (fun(m,_,_) -> m <> Meta.PrivateAccess) ctx.meta;
 			ctx.meta <- List.filter (fun(m,_,_) -> m <> Meta.PrivateAccess) ctx.meta;
 			e()
 			e()

+ 4 - 0
src/typing/typerBase.ml

@@ -177,6 +177,10 @@ let get_stored_typed_expr ctx id =
 	let e = ctx.com.stored_typed_exprs#find id in
 	let e = ctx.com.stored_typed_exprs#find id in
 	Texpr.duplicate_tvars (fun e -> get_this ctx e.epos) e
 	Texpr.duplicate_tvars (fun e -> get_this ctx e.epos) e
 
 
+let type_stored_expr ctx e1 =
+	let id = match e1 with (EConst (Int (s, _)),_) -> int_of_string s | _ -> die "" __LOC__ in
+	get_stored_typed_expr ctx id
+
 let assign_to_this_is_allowed ctx =
 let assign_to_this_is_allowed ctx =
 	match ctx.curclass.cl_kind with
 	match ctx.curclass.cl_kind with
 		| KAbstractImpl _ ->
 		| KAbstractImpl _ ->

+ 11 - 5
src/typing/typerDisplay.ml

@@ -346,20 +346,26 @@ and display_expr ctx e_ast e dk mode with_type p =
 			let fa = get_constructor_access c params p in
 			let fa = get_constructor_access c params p in
 			fa.fa_field,c
 			fa.fa_field,c
 	in
 	in
-	let maybe_expand_overload e e_on host cf = match mode with
+	let maybe_expand_overload el_typed e e_on host cf = match mode with
 		| MCall el when cf.cf_overloads <> [] ->
 		| MCall el when cf.cf_overloads <> [] ->
 			let fa = FieldAccess.create e_on cf host false p in
 			let fa = FieldAccess.create e_on cf host false p in
-			let fcc = unify_field_call ctx fa [] el p false in
+			let fcc = unify_field_call ctx fa el_typed el p false in
 			FieldAccess.get_field_expr {fa with fa_field = fcc.fc_field} FCall
 			FieldAccess.get_field_expr {fa with fa_field = fcc.fc_field} FCall
 		| _ ->
 		| _ ->
 			e
 			e
 	in
 	in
+	let e,el_typed = match e.eexpr with
+		| TMeta((Meta.StaticExtension,[e_self],_),e1) ->
+			e1,[type_stored_expr ctx e_self]
+		| _ ->
+			e,[]
+	in
 	(* If we display on a TField node that points to an overloaded field, let's try to unify the field call
 	(* If we display on a TField node that points to an overloaded field, let's try to unify the field call
 	   in order to resolve the correct overload (issue #7753). *)
 	   in order to resolve the correct overload (issue #7753). *)
 	let e = match e.eexpr with
 	let e = match e.eexpr with
-		| TField(e1,FStatic(c,cf)) -> maybe_expand_overload e e1 (FHStatic c) cf
-		| TField(e1,(FInstance(c,tl,cf) | FClosure(Some(c,tl),cf))) -> maybe_expand_overload e e1 (FHInstance(c,tl)) cf
-		| TField(e1,(FAnon cf | FClosure(None,cf))) -> maybe_expand_overload e e1 FHAnon cf
+		| TField(e1,FStatic(c,cf)) -> maybe_expand_overload el_typed e e1 (FHStatic c) cf
+		| TField(e1,(FInstance(c,tl,cf) | FClosure(Some(c,tl),cf))) -> maybe_expand_overload el_typed e e1 (FHInstance(c,tl)) cf
+		| TField(e1,(FAnon cf | FClosure(None,cf))) -> maybe_expand_overload el_typed e e1 FHAnon cf
 		| _ -> e
 		| _ -> e
 	in
 	in
 	match ctx.com.display.dms_kind with
 	match ctx.com.display.dms_kind with

+ 1 - 1
tests/display/build.hxml

@@ -5,4 +5,4 @@
 -lib haxeserver
 -lib haxeserver
 --interp
 --interp
 -D use-rtti-doc
 -D use-rtti-doc
-#-D test=9133
+-D test=11285

+ 34 - 0
tests/display/src/cases/Issue11285.hx

@@ -0,0 +1,34 @@
+package cases;
+
+class Issue11285 extends DisplayTestCase {
+	/**
+		using Issue11285.MathTools;
+
+		function main() {
+			var float = 0.0;
+			var int = 0;
+			float.wrapA{-1-}round(0, 1);
+			int.wrap{-2-}Around(0, 1);
+		}
+
+		class MathTools {
+
+			extern overload public static inline function {-3-}wrapAround{-4-}(v:Int, min:Int, max:Int):Int {
+				var range = max - min;
+				return min + (((v - min) % range) + range) % range;
+			}
+
+			extern overload public static inline function {-5-}wrapAround{-6-}(v:Float, min:Float, max:Float):Float {
+				var range = max - min;
+				return min + (((v - min) % range) + range) % range;
+			}
+		}
+	**/
+	function test() {
+		eq(range(5, 6), position(pos(1)));
+		eq("(v : Float, min : Float, max : Float) -> Float", type(pos(1)));
+
+		eq(range(3, 4), position(pos(2)));
+		eq("(v : Int, min : Int, max : Int) -> Int", type(pos(2)));
+	}
+}