Skip to content

Commit

Permalink
[display] push stream results
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Nov 17, 2020
1 parent a3a64f8 commit fd19d67
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/context/display/display.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/context/display/displayException.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 19 additions & 8 deletions src/core/withType.ml
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
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 =
| NoValue
| 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
52 changes: 49 additions & 3 deletions src/typing/callUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 () =
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/typing/typerDisplay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions std/haxe/display/Display.hx
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ typedef HoverDisplayItemOccurence<T> = DisplayItemOccurrence<T> & {
var ?name:{
var name:String;
var kind:HoverExpectedNameKind;
var ?doc:String;
};
};
}
Expand Down

0 comments on commit fd19d67

Please sign in to comment.