Преглед изворни кода

[display] push stream results

see #9956
Simon Krajewski пре 4 година
родитељ
комит
fd19d672e4

+ 2 - 2
src/context/display/display.ml

@@ -262,8 +262,8 @@ end
 let get_expected_name with_type = match with_type with
 	| WithType.Value (Some src) | WithType.WithType(_,Some src) ->
 		(match src with
-		| WithType.FunctionArgument name -> Some name
-		| WithType.StructureField name -> Some name
+		| WithType.FunctionArgument si -> Some si.si_name
+		| WithType.StructureField si -> Some si .si_name
 		| WithType.ImplicitReturn -> None
 		)
 	| _ -> None

+ 9 - 4
src/context/display/displayException.ml

@@ -180,10 +180,11 @@ let to_json ctx de =
 		in
 		let ctx = Genjson.create_context GMFull in
 		let generate_name kind =
-			let i, name = named_source_kind kind in
+			let i,si = named_source_kind kind in
 			jobject [
-				"name",jstring name;
+				"name",jstring si.si_name;
 				"kind",jint i;
+				"doc",(match si.si_doc with None -> jnull | Some s -> jstring s);
 			]
 		in
 		let expected = match hover.hexpected with
@@ -192,10 +193,14 @@ let to_json ctx de =
 				:: (match src with
 					| None -> []
 					| Some ImplicitReturn -> []
-					| Some src -> ["name",generate_name src])
+					| Some src -> [
+							"name",generate_name src;
+						])
 				)
 			| Some(Value(Some ((FunctionArgument name | StructureField name) as src))) ->
-				jobject ["name",generate_name src]
+				jobject [
+					"name",generate_name src;
+				]
 			| _ -> jnull
 		in
 		jobject [

+ 1 - 1
src/context/typecore.ml

@@ -134,7 +134,7 @@ and typer = {
 	mutable vthis : tvar option;
 	mutable in_call_args : bool;
 	mutable in_overload_call_args : bool;
-	mutable delayed_display : exn option;
+	mutable delayed_display : DisplayTypes.display_exception_kind option;
 	mutable monomorphs : monomorphs;
 	(* events *)
 	mutable on_error : typer -> string -> pos -> unit;

+ 19 - 8
src/core/withType.ml

@@ -1,8 +1,13 @@
 open Type
 
+type with_type_source_information = {
+	si_name : string;
+	si_doc : string option;
+}
+
 type with_type_source =
-	| FunctionArgument of string
-	| StructureField of string
+	| FunctionArgument of with_type_source_information
+	| StructureField of with_type_source_information
 	| ImplicitReturn
 
 type t =
@@ -10,22 +15,28 @@ type t =
 	| Value of with_type_source option
 	| WithType of Type.t * with_type_source option
 
+let make_with_type_source_information name doc = {
+	si_name = name;
+	si_doc = doc;
+}
+
 let with_type t = WithType(t,None)
 let of_implicit_return t = WithType(t,Some ImplicitReturn)
-let with_argument t name = WithType(t,Some(FunctionArgument name))
-let with_structure_field t name = WithType(t,Some(StructureField name))
+let with_argument t name = WithType(t,Some(FunctionArgument (make_with_type_source_information name None)))
+let with_argument_and_doc t name doc = WithType(t,Some(FunctionArgument (make_with_type_source_information name (Some doc))))
+let with_structure_field t name = WithType(t,Some(StructureField (make_with_type_source_information name None)))
 let value = Value None
-let named_argument name = Value (Some(FunctionArgument name))
-let named_structure_field name = Value (Some(StructureField name))
+let named_argument name = Value (Some(FunctionArgument (make_with_type_source_information name None)))
+let named_structure_field name = Value (Some(StructureField (make_with_type_source_information name None)))
 let no_value = NoValue
 
 let to_string = function
 	| NoValue -> "NoValue"
 	| Value (None | Some ImplicitReturn) -> "Value"
-	| Value (Some(FunctionArgument s | StructureField s)) -> "Value " ^ s
+	| Value (Some(FunctionArgument si | StructureField si)) -> "Value " ^ si.si_name
 	| WithType(t,s) ->
 		let name = match s with
-			| Some(FunctionArgument s | StructureField s) -> s
+			| Some(FunctionArgument si | StructureField si) -> si.si_name
 			| _ -> "None"
 		in
 		Printf.sprintf "WithType(%s, %s)" (s_type (print_context()) t) name

+ 49 - 3
src/typing/callUnification.ml

@@ -198,8 +198,46 @@ let unify_field_call ctx fa el_typed el p inline =
 		| None ->
 			None
 	in
+	let raise_augmented_display_exception cf de =
+		let default () = raise (DisplayException.DisplayException de) in
+		let doc = match gen_doc_text_opt cf.cf_doc with
+			| None -> default()
+			| Some s -> s
+		in
+		let extract_javadoc_param_info name =
+			(* TODO: Parse this properly *)
+			let s = "@param " ^ name ^ " \\(.*\\)" in
+			let reg = Str.regexp s in
+			try
+				ignore(Str.search_forward reg doc 0);
+				Some (Str.matched_group 1 doc)
+			with Not_found ->
+				None
+		in
+		match de with
+		| DisplayHover (Some hover) ->
+			begin match hover.hexpected with
+			| Some (WithType(t,Some si)) ->
+				let si = match si with
+				| FunctionArgument ({si_doc = None} as si) ->
+					WithType.FunctionArgument {si with si_doc = extract_javadoc_param_info si.si_name};
+				| StructureField ({si_doc = None} as si) ->
+					WithType.StructureField {si with si_doc = extract_javadoc_param_info si.si_name};
+				| _ ->
+					si
+				in
+				let expected = WithType.WithType(t,Some si) in
+				DisplayException.raise_hover hover.hitem (Some expected) hover.hpos
+			| _ ->
+				default()
+			end
+		| _ ->
+			default()
+	in
 	let commit_delayed_display fcc =
-		Option.may raise (snd fcc.fc_data);
+		Option.may (fun de ->
+			raise_augmented_display_exception fcc.fc_field de;
+		) (snd fcc.fc_data);
 		{fcc with fc_data = fst fcc.fc_data}
 	in
 	let attempt_call cf in_overload =
@@ -223,7 +261,13 @@ let unify_field_call ctx fa el_typed el p inline =
 					List.rev acc_el,List.rev acc_args,args
 			in
 			let el_typed,args_typed,args = loop [] [] tmap args el_typed in
-			let el,_ = unify_call_args ctx el args ret p inline is_forced_inline in_overload in
+			let el,_ =
+				try
+					unify_call_args ctx el args ret p inline is_forced_inline in_overload
+				with DisplayException.DisplayException de ->
+					raise_augmented_display_exception cf de;
+			in
+			(* here *)
 			let el = el_typed @ el in
 			let tf = TFun(args_typed @ args,ret) in
 			let mk_call () =
@@ -302,7 +346,9 @@ let unify_field_call ctx fa el_typed el p inline =
 		let fail () =
 			let failures = List.map (fun (cf,err,p,delayed_display) ->
 				(* If any resolution attempt had a delayed display result, we might as well raise it now. *)
-				Option.may raise delayed_display;
+				Option.may (fun de ->
+					raise_augmented_display_exception cf de;
+				) delayed_display;
 				cf,error_msg err,p
 			) failures in
 			let failures = remove_duplicates (fun (_,msg1,_) (_,msg2,_) -> msg1 <> msg2) failures in

+ 2 - 2
src/typing/typerDisplay.ml

@@ -655,8 +655,8 @@ let handle_display ctx e_ast dk mode with_type =
 	if ctx.in_overload_call_args then begin
 		try
 			f()
-		with DisplayException _ as exc ->
-			ctx.delayed_display <- Some exc;
+		with DisplayException de ->
+			ctx.delayed_display <- Some de;
 			e
 	end else
 		f()

+ 1 - 0
std/haxe/display/Display.hx

@@ -505,6 +505,7 @@ typedef HoverDisplayItemOccurence<T> = DisplayItemOccurrence<T> & {
 		var ?name:{
 			var name:String;
 			var kind:HoverExpectedNameKind;
+			var ?doc:String;
 		};
 	};
 }