2
0
Эх сурвалжийг харах

support display on variable/property fields too

And ignore the constant expression business in display mode. (closes #5125)
Simon Krajewski 9 жил өмнө
parent
commit
3101a590eb

+ 20 - 12
src/typing/typeload.ml

@@ -1941,6 +1941,7 @@ module ClassInitializer = struct
 		is_extern : bool;
 		is_extern : bool;
 		is_macro : bool;
 		is_macro : bool;
 		is_abstract_member : bool;
 		is_abstract_member : bool;
+		is_display_field : bool;
 		field_kind : field_kind;
 		field_kind : field_kind;
 		mutable do_bind : bool;
 		mutable do_bind : bool;
 		mutable do_add : bool;
 		mutable do_add : bool;
@@ -2031,6 +2032,7 @@ module ClassInitializer = struct
 			is_override = is_override;
 			is_override = is_override;
 			is_macro = is_macro;
 			is_macro = is_macro;
 			is_extern = is_extern;
 			is_extern = is_extern;
+			is_display_field = cctx.is_display_file && (cff.cff_pos.pmin <= cctx.completion_position.pmin && cff.cff_pos.pmax >= cctx.completion_position.pmax);
 			is_abstract_member = cctx.abstract <> None && Meta.has Meta.Impl cff.cff_meta;
 			is_abstract_member = cctx.abstract <> None && Meta.has Meta.Impl cff.cff_meta;
 			field_kind = field_kind;
 			field_kind = field_kind;
 			do_bind = (((not c.cl_extern || is_inline) && not c.cl_interface) || field_kind = FKInit);
 			do_bind = (((not c.cl_extern || is_inline) && not c.cl_interface) || field_kind = FKInit);
@@ -2143,6 +2145,17 @@ module ClassInitializer = struct
 			cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
 			cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
 		end
 		end
 
 
+	let check_display (ctx,fctx) cf p =
+		if fctx.is_display_field && not ctx.display_handled then begin
+			(* We're in our display field but didn't exit yet, so the position must be on the field itself.
+			   It could also be one of its arguments, but at the moment we cannot detect that. *)
+			match ctx.com.display with
+				| DMPosition -> raise (DisplayPosition [cf.cf_pos]);
+				| DMUsage -> cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
+				| DMType -> raise (DisplayTypes [cf.cf_type])
+				| _ -> ()
+		end
+
 	let bind_var (ctx,cctx,fctx) cf e =
 	let bind_var (ctx,cctx,fctx) cf e =
 		let c = cctx.tclass in
 		let c = cctx.tclass in
 		let p = cf.cf_pos in
 		let p = cf.cf_pos in
@@ -2199,7 +2212,10 @@ module ClassInitializer = struct
 						| TConst _ | TLocal _ | TFunction _ -> e
 						| TConst _ | TLocal _ | TFunction _ -> e
 						| _ -> !analyzer_run_on_expr_ref ctx.com e
 						| _ -> !analyzer_run_on_expr_ref ctx.com e
 					in
 					in
-					let require_constant_expression e msg = match Optimizer.make_constant_expression ctx (maybe_run_analyzer e) with
+					let require_constant_expression e msg =
+						if ctx.com.display <> DMNone then
+							e
+						else match Optimizer.make_constant_expression ctx (maybe_run_analyzer e) with
 						| Some e -> e
 						| Some e -> e
 						| None -> display_error ctx msg p; e
 						| None -> display_error ctx msg p; e
 					in
 					in
@@ -2248,6 +2264,7 @@ module ClassInitializer = struct
 						e
 						e
 					) in
 					) in
 					let e = check_cast e in
 					let e = check_cast e in
+					check_display (ctx,fctx) cf p;
 					cf.cf_expr <- Some e;
 					cf.cf_expr <- Some e;
 					cf.cf_type <- t;
 					cf.cf_type <- t;
 				end;
 				end;
@@ -2532,7 +2549,6 @@ module ClassInitializer = struct
 					| None ->
 					| None ->
 						if fctx.field_kind = FKConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
 						if fctx.field_kind = FKConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
 				) in
 				) in
-				let is_display_field = cctx.is_display_file && (f.cff_pos.pmin <= cctx.completion_position.pmin && f.cff_pos.pmax >= cctx.completion_position.pmax) in
 				match ctx.com.platform with
 				match ctx.com.platform with
 					| Java when is_java_native_function cf.cf_meta ->
 					| Java when is_java_native_function cf.cf_meta ->
 						if fd.f_expr <> None then
 						if fd.f_expr <> None then
@@ -2540,16 +2556,8 @@ module ClassInitializer = struct
 						cf.cf_expr <- None;
 						cf.cf_expr <- None;
 						cf.cf_type <- t
 						cf.cf_type <- t
 					| _ ->
 					| _ ->
-						let e , fargs = type_function ctx args ret fmode fd is_display_field p in
-						if is_display_field && not ctx.display_handled then begin
-							(* We're in our display field but didn't exit yet, so the position must be on the field itself.
-							   It could also be one of its arguments, but at the moment we cannot detect that. *)
-							match ctx.com.display with
-								| DMPosition -> raise (DisplayPosition [cf.cf_pos]);
-								| DMUsage -> cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
-								| DMType -> raise (DisplayTypes [cf.cf_type])
-								| _ -> ()
-						end;
+						let e , fargs = type_function ctx args ret fmode fd fctx.is_display_field p in
+						check_display (ctx,fctx) cf p;
 						let tf = {
 						let tf = {
 							tf_args = fargs;
 							tf_args = fargs;
 							tf_type = ret;
 							tf_type = ret;

+ 10 - 0
tests/misc/projects/Issue5125/Main.hx

@@ -0,0 +1,10 @@
+enum TextDocumentSyncKind {
+    Incremental;
+}
+
+class Main {
+	public static inline var syncKind = TextDocumentSyncKind.Incremental;
+	static function main() {
+        trace(syncKind);
+    }
+}

+ 1 - 0
tests/misc/projects/Issue5125/compile.hxml

@@ -0,0 +1 @@
+--display Main.hx@90@type

+ 3 - 0
tests/misc/projects/Issue5125/compile.hxml.stderr

@@ -0,0 +1,3 @@
+<type>
+TextDocumentSyncKind
+</type>