Browse Source

add some completion

Simon Krajewski 4 years ago
parent
commit
b48f65805f
3 changed files with 30 additions and 10 deletions
  1. 19 10
      src/context/display/displayFields.ml
  2. 6 0
      src/context/typecore.ml
  3. 5 0
      src/typing/typerDisplay.ml

+ 19 - 10
src/context/display/displayFields.ml

@@ -286,17 +286,26 @@ let collect ctx e_ast e dk with_type p =
 				end else
 					acc
 			) an.a_fields items
-		| TFun (args,ret,_) ->
-			(* A function has no field except the magic .bind one. *)
-			if is_new_item items "bind" then begin
-				let t = opt_args args ret in
-				let cf = mk_field "bind" (tfun [t] t) p null_pos in
-				cf.cf_kind <- Method MethNormal;
-				let ct = CompletionType.from_type (get_import_status ctx) ~values:(get_value_meta cf.cf_meta) t in
-				let item = make_ci_class_field (CompletionClassField.make cf CFSStatic BuiltIn true) (t,ct) in
-				PMap.add "bind" item items
-			end else
+		| TFun (args,ret,coro) ->
+			let maybe_add_builtin items name t =
+				if is_new_item items name then begin
+					let cf = mk_field name t p null_pos in
+					cf.cf_kind <- Method MethNormal;
+					let ct = CompletionType.from_type (get_import_status ctx) ~values:(get_value_meta cf.cf_meta) t in
+					let item = make_ci_class_field (CompletionClassField.make cf CFSStatic BuiltIn true) (t,ct) in
+					PMap.add name item items
+				end else
+					items
+			in
+			let items = if not coro then
 				items
+			else begin
+				let t = coroutine_type ctx args ret in
+				let items = maybe_add_builtin items "start" t in
+				maybe_add_builtin items "create" t
+			end in
+			let t = opt_args args ret in
+			maybe_add_builtin items "bind" t
 		| _ ->
 			items
 	in

+ 6 - 0
src/context/typecore.ml

@@ -614,6 +614,12 @@ let s_field_call_candidate fcc =
 		"fc_field",Printf.sprintf "%s: %s" fcc.fc_field.cf_name (s_type pctx fcc.fc_field.cf_type)
 	]
 
+
+let coroutine_type ctx args ret =
+	let args = args @ [("_hx_continuation",false,(tfun [ret; t_dynamic] ctx.com.basic.tvoid))] in
+	let ret = ctx.com.basic.tvoid in
+	TFun(args,ret,true)
+
 (* -------------- debug functions to activate when debugging typer passes ------------------------------- *)
 (*/*
 

+ 5 - 0
src/typing/typerDisplay.ml

@@ -265,6 +265,11 @@ let rec handle_signature_display ctx e_ast with_type =
 					(match follow e.etype with
 						| TFun signature -> e
 						| _ -> def ())
+				| (EField (e,("start" | "create")),p) ->
+					let e = type_expr ctx e WithType.value in
+					(match follow e.etype with
+						| TFun(args,ret,true) -> {e with etype = coroutine_type ctx args ret}
+						| _ -> def ())
 				| _ ->	def()
 			in
 			let tl = match e1.eexpr with