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

support {| completion (closes #3907)

Simon Krajewski 10 жил өмнө
parent
commit
319588b6bf
3 өөрчлөгдсөн 21 нэмэгдсэн , 7 устгасан
  1. 3 0
      optimizer.ml
  2. 11 5
      parser.ml
  3. 7 2
      typer.ml

+ 3 - 0
optimizer.ml

@@ -1618,6 +1618,9 @@ let optimize_completion_expr e =
 						e)
 				| EFunction (_,f) ->
 					Ast.map_expr (subst_locals { r = PMap.foldi (fun n i acc -> if List.exists (fun (a,_,_,_) -> a = n) f.f_args then acc else PMap.add n i acc) locals.r PMap.empty }) e
+				| EObjectDecl [] ->
+					(* this probably comes from {| completion so we need some context} *)
+					raise Exit
 				| _ ->
 					Ast.map_expr (subst_locals locals) e
 			in

+ 11 - 5
parser.ml

@@ -1201,11 +1201,17 @@ and expr = parser
 			make_meta name params (secure_expr s) p
 		with Display e ->
 			display (make_meta name params e p))
-	| [< '(BrOpen,p1); b = block1; '(BrClose,p2); s >] ->
-		let e = (b,punion p1 p2) in
-		(match b with
-		| EObjectDecl _ -> expr_next e s
-		| _ -> e)
+	| [< '(BrOpen,p1); s >] ->
+		if is_resuming p1 then display (EDisplay ((EObjectDecl [],p1),false),p1);
+		(match s with parser
+		| [< '(Binop OpOr,p2) when do_resume() >] ->
+			set_resume p1;
+			display (EDisplay ((EObjectDecl [],p1),false),p1);
+		| [< b = block1; '(BrClose,p2); s >] ->
+			let e = (b,punion p1 p2) in
+			(match b with
+			| EObjectDecl _ -> expr_next e s
+			| _ -> e))
 	| [< '(Kwd Macro,p); s >] ->
 		parse_macro_expr p s
 	| [< '(Kwd Var,p1); v = parse_var_decl >] -> (EVars [v],p1)

+ 7 - 2
typer.ml

@@ -3511,7 +3511,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		let texpr = loop t in
 		mk (TCast (type_expr ctx e Value,Some texpr)) t p
 	| EDisplay (e,iscall) ->
-		handle_display ctx e iscall p
+		handle_display ctx e iscall with_type p
 	| EDisplayNew t ->
 		let t = Typeload.load_instance ctx t p true in
 		(match follow t with
@@ -3608,7 +3608,7 @@ and get_stored_typed_expr com id =
 	build_expr  e
 
 
-and handle_display ctx e_ast iscall p =
+and handle_display ctx e_ast iscall with_type p =
 	let old = ctx.in_display in
 	ctx.in_display <- true;
 	let get_submodule_fields path =
@@ -3757,6 +3757,11 @@ and handle_display ctx e_ast iscall p =
 					end else
 						acc
 				) c.cl_statics fields
+			| TAnon a when PMap.is_empty a.a_fields ->
+				begin match with_type with
+				| WithType t | WithTypeResume t -> get_fields t
+				| _ -> a.a_fields
+				end
 			| TAnon a ->
 				(match !(a.a_status) with
 				| Statics c ->