Browse Source

[display] omit dot paths if they are not required

Simon Krajewski 7 years ago
parent
commit
f3fcd81b51

+ 1 - 1
src/compiler/main.ml

@@ -964,7 +964,7 @@ with
 	| DisplayException(DisplayType (t,p,doc)) ->
 	| DisplayException(DisplayType (t,p,doc)) ->
 		let doc = match doc with Some _ -> doc | None -> DisplayOutput.find_doc t in
 		let doc = match doc with Some _ -> doc | None -> DisplayOutput.find_doc t in
 		raise (DisplayOutput.Completion (DisplayOutput.print_type t p doc))
 		raise (DisplayOutput.Completion (DisplayOutput.print_type t p doc))
-	| DisplayException(DisplaySignatures(signatures,display_arg,_)) ->
+	| DisplayException(DisplaySignatures(signatures,_,display_arg)) ->
 		if ctx.com.display.dms_kind = DMSignature then
 		if ctx.com.display.dms_kind = DMSignature then
 			raise (DisplayOutput.Completion (DisplayOutput.print_signature signatures display_arg))
 			raise (DisplayOutput.Completion (DisplayOutput.print_signature signatures display_arg))
 		else
 		else

+ 35 - 14
src/context/display.ml

@@ -170,19 +170,40 @@ module ExprPreprocessing = struct
 end
 end
 
 
 module DisplayEmitter = struct
 module DisplayEmitter = struct
-	let display_module_type dm mt p = match dm.dms_kind with
+
+	let requires_import ctx path =
+		try
+			let mt' = ctx.g.do_load_type_def ctx null_pos {tpackage = []; tname = snd path; tparams = []; tsub = None} in
+			path <> (t_infos mt').mt_path
+		with _ ->
+			true
+
+	let patch_type ctx t =
+		let rec patch t = match t with
+			| TInst(c,tl) when not (requires_import ctx c.cl_path) -> TInst({c with cl_path = ([],snd c.cl_path)},List.map patch tl)
+			| TEnum(en,tl) when not (requires_import ctx en.e_path) -> TEnum({en with e_path = ([],snd en.e_path)},List.map patch tl)
+			| TType(td,tl) when not (requires_import ctx td.t_path) -> TType({td with t_path = ([],snd td.t_path)},List.map patch tl)
+			| TAbstract(a,tl) when not (requires_import ctx a.a_path) -> TAbstract({a with a_path = ([],snd a.a_path)},List.map patch tl)
+			| _ -> Type.map patch t
+		in
+		patch t
+
+	let display_module_type ctx mt p = match ctx.com.display.dms_kind with
 		| DMDefinition -> raise_position [(t_infos mt).mt_name_pos];
 		| DMDefinition -> raise_position [(t_infos mt).mt_name_pos];
 		| DMUsage _ -> reference_position := (t_infos mt).mt_name_pos
 		| DMUsage _ -> reference_position := (t_infos mt).mt_name_pos
-		| DMHover -> raise_type (type_of_module_type mt) p None
+		| DMHover -> raise_type (patch_type ctx (type_of_module_type mt)) p None
 		| _ -> ()
 		| _ -> ()
 
 
-	let rec display_type dm t p = match dm.dms_kind with
-		| DMHover -> raise_type t p None
+	let rec display_type ctx t p =
+		let dm = ctx.com.display in
+		match dm.dms_kind with
+		| DMHover ->
+			raise_type (patch_type ctx t) p None
 		| _ ->
 		| _ ->
-			try display_module_type dm (module_type_of_type t) p
+			try display_module_type ctx (module_type_of_type t) p
 			with Exit -> match follow t,follow !t_dynamic_def with
 			with Exit -> match follow t,follow !t_dynamic_def with
 				| _,TDynamic _ -> () (* sanity check in case it's still t_dynamic *)
 				| _,TDynamic _ -> () (* sanity check in case it's still t_dynamic *)
-				| TDynamic _,_ -> display_type dm !t_dynamic_def p
+				| TDynamic _,_ -> display_type ctx !t_dynamic_def p
 				| _ -> ()
 				| _ -> ()
 
 
 	let check_display_type ctx t p =
 	let check_display_type ctx t p =
@@ -192,20 +213,20 @@ module DisplayEmitter = struct
 		in
 		in
 		let maybe_display_type () =
 		let maybe_display_type () =
 			if ctx.is_display_file && is_display_position p then
 			if ctx.is_display_file && is_display_position p then
-				display_type ctx.com.display t p
+				display_type ctx t p
 		in
 		in
 		match ctx.com.display.dms_kind with
 		match ctx.com.display.dms_kind with
 		| DMStatistics -> add_type_hint()
 		| DMStatistics -> add_type_hint()
 		| DMUsage _ -> add_type_hint(); maybe_display_type()
 		| DMUsage _ -> add_type_hint(); maybe_display_type()
 		| _ -> maybe_display_type()
 		| _ -> maybe_display_type()
 
 
-	let display_variable dm v p = match dm.dms_kind with
+	let display_variable ctx v p = match ctx.com.display.dms_kind with
 		| DMDefinition -> raise_position [v.v_pos]
 		| DMDefinition -> raise_position [v.v_pos]
 		| DMUsage _ -> reference_position := v.v_pos
 		| DMUsage _ -> reference_position := v.v_pos
-		| DMHover -> raise_type v.v_type p None
+		| DMHover -> raise_type (patch_type ctx v.v_type) p None
 		| _ -> ()
 		| _ -> ()
 
 
-	let display_field dm c cf p = match dm.dms_kind with
+	let display_field ctx c cf p = match ctx.com.display.dms_kind with
 		| DMDefinition -> raise_position [cf.cf_name_pos]
 		| DMDefinition -> raise_position [cf.cf_name_pos]
 		| DMUsage _ -> reference_position := cf.cf_name_pos
 		| DMUsage _ -> reference_position := cf.cf_name_pos
 		| DMHover ->
 		| DMHover ->
@@ -218,16 +239,16 @@ module DisplayEmitter = struct
 				| Some c,TFun(tl,_) when cf.cf_name = "new" -> TFun(tl,TInst(c,List.map snd c.cl_params))
 				| Some c,TFun(tl,_) when cf.cf_name = "new" -> TFun(tl,TInst(c,List.map snd c.cl_params))
 				| _ -> t
 				| _ -> t
 			in
 			in
-			raise_type t p cf.cf_doc
+			raise_type (patch_type ctx t) p cf.cf_doc
 		| _ -> ()
 		| _ -> ()
 
 
 	let maybe_display_field ctx c cf p =
 	let maybe_display_field ctx c cf p =
-		if is_display_position p then display_field ctx.com.display c cf p
+		if is_display_position p then display_field ctx c cf p
 
 
-	let display_enum_field dm ef p = match dm.dms_kind with
+	let display_enum_field ctx ef p = match ctx.com.display.dms_kind with
 		| DMDefinition -> raise_position [ef.ef_name_pos]
 		| DMDefinition -> raise_position [ef.ef_name_pos]
 		| DMUsage _ -> reference_position := ef.ef_name_pos
 		| DMUsage _ -> reference_position := ef.ef_name_pos
-		| DMHover -> raise_type ef.ef_type p ef.ef_doc
+		| DMHover -> raise_type (patch_type ctx ef.ef_type) p ef.ef_doc
 		| _ -> ()
 		| _ -> ()
 
 
 	let display_meta com meta = match com.display.dms_kind with
 	let display_meta com meta = match com.display.dms_kind with

+ 1 - 0
src/context/typecore.ml

@@ -87,6 +87,7 @@ type typer_globals = {
 	do_create : Common.context -> typer;
 	do_create : Common.context -> typer;
 	do_macro : typer -> macro_mode -> path -> string -> expr list -> pos -> expr option;
 	do_macro : typer -> macro_mode -> path -> string -> expr list -> pos -> expr option;
 	do_load_module : typer -> path -> pos -> module_def;
 	do_load_module : typer -> path -> pos -> module_def;
+	do_load_type_def : typer -> pos -> type_path -> module_type;
 	do_optimize : typer -> texpr -> texpr;
 	do_optimize : typer -> texpr -> texpr;
 	do_build_instance : typer -> module_type -> pos -> ((string * t) list * path * (t list -> t));
 	do_build_instance : typer -> module_type -> pos -> ((string * t) list * path * (t list -> t));
 	do_format_string : typer -> string -> pos -> Ast.expr;
 	do_format_string : typer -> string -> pos -> Ast.expr;

+ 2 - 2
src/typing/typeload.ml

@@ -567,7 +567,7 @@ let rec type_type_param ?(enum_constructor=false) ctx path get_params p tp =
 	if enum_constructor then c.cl_meta <- (Meta.EnumConstructorParam,[],null_pos) :: c.cl_meta;
 	if enum_constructor then c.cl_meta <- (Meta.EnumConstructorParam,[],null_pos) :: c.cl_meta;
 	let t = TInst (c,List.map snd c.cl_params) in
 	let t = TInst (c,List.map snd c.cl_params) in
 	if ctx.is_display_file && Display.is_display_position (pos tp.tp_name) then
 	if ctx.is_display_file && Display.is_display_position (pos tp.tp_name) then
-		Display.DisplayEmitter.display_type ctx.com.display t (pos tp.tp_name);
+		Display.DisplayEmitter.display_type ctx t (pos tp.tp_name);
 	match tp.tp_constraints with
 	match tp.tp_constraints with
 	| [] ->
 	| [] ->
 		n, t
 		n, t
@@ -724,7 +724,7 @@ let handle_path_display ctx path p =
 				| TClassDecl c when snd c.cl_path = st ->
 				| TClassDecl c when snd c.cl_path = st ->
 					ignore(c.cl_build());
 					ignore(c.cl_build());
 					let cf = PMap.find sf c.cl_statics in
 					let cf = PMap.find sf c.cl_statics in
-					Display.DisplayEmitter.display_field ctx.com.display (Some c) cf p
+					Display.DisplayEmitter.display_field ctx (Some c) cf p
 				| _ ->
 				| _ ->
 					()
 					()
 			) m.m_types;
 			) m.m_types;

+ 2 - 2
src/typing/typeloadFields.ml

@@ -980,7 +980,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 							begin match c.cl_super with
 							begin match c.cl_super with
 							| Some(c,tl) ->
 							| Some(c,tl) ->
 								let _,_,cf = raw_class_field (fun cf -> cf.cf_type) c tl cf.cf_name in
 								let _,_,cf = raw_class_field (fun cf -> cf.cf_type) c tl cf.cf_name in
-								Display.DisplayEmitter.display_field ctx.com.display (Some c) cf p
+								Display.DisplayEmitter.display_field ctx (Some c) cf p
 							| _ ->
 							| _ ->
 								()
 								()
 							end
 							end
@@ -1106,7 +1106,7 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 	let display_accessor m p =
 	let display_accessor m p =
 		try
 		try
 			let cf = match find_accessor m with [_,cf] -> cf | _ -> raise Not_found in
 			let cf = match find_accessor m with [_,cf] -> cf | _ -> raise Not_found in
-			Display.DisplayEmitter.display_field ctx.com.display (Some c) cf p
+			Display.DisplayEmitter.display_field ctx (Some c) cf p
 		with Not_found ->
 		with Not_found ->
 			()
 			()
 	in
 	in

+ 1 - 1
src/typing/typeloadFunction.ml

@@ -87,7 +87,7 @@ let type_function ctx args ret fmode f do_display p =
 		let v,c = add_local ctx n t pn, c in
 		let v,c = add_local ctx n t pn, c in
 		v.v_meta <- m;
 		v.v_meta <- m;
 		if do_display && Display.is_display_position pn then
 		if do_display && Display.is_display_position pn then
-			Display.DisplayEmitter.display_variable ctx.com.display v pn;
+			Display.DisplayEmitter.display_variable ctx v pn;
 		if n = "this" then v.v_meta <- (Meta.This,[],null_pos) :: v.v_meta;
 		if n = "this" then v.v_meta <- (Meta.This,[],null_pos) :: v.v_meta;
 		v,c
 		v,c
 	) args f.f_args in
 	) args f.f_args in

+ 6 - 6
src/typing/typeloadModule.ml

@@ -392,7 +392,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 					t_type = f (List.map snd (t_infos t).mt_params);
 					t_type = f (List.map snd (t_infos t).mt_params);
 				} in
 				} in
 				if ctx.is_display_file && Display.is_display_position p then
 				if ctx.is_display_file && Display.is_display_position p then
-					Display.DisplayEmitter.display_module_type ctx.com.display mt p;
+					Display.DisplayEmitter.display_module_type ctx mt p;
 				mt
 				mt
 			in
 			in
 			let add_static_init t name s =
 			let add_static_init t name s =
@@ -504,7 +504,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 	| EClass d ->
 	| EClass d ->
 		let c = (match get_type (fst d.d_name) with TClassDecl c -> c | _ -> assert false) in
 		let c = (match get_type (fst d.d_name) with TClassDecl c -> c | _ -> assert false) in
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
-			Display.DisplayEmitter.display_module_type ctx.com.display (match c.cl_kind with KAbstractImpl a -> TAbstractDecl a | _ -> TClassDecl c) (pos d.d_name);
+			Display.DisplayEmitter.display_module_type ctx (match c.cl_kind with KAbstractImpl a -> TAbstractDecl a | _ -> TClassDecl c) (pos d.d_name);
 		TypeloadCheck.check_global_metadata ctx c.cl_meta (fun m -> c.cl_meta <- m :: c.cl_meta) c.cl_module.m_path c.cl_path None;
 		TypeloadCheck.check_global_metadata ctx c.cl_meta (fun m -> c.cl_meta <- m :: c.cl_meta) c.cl_module.m_path c.cl_path None;
 		let herits = d.d_flags in
 		let herits = d.d_flags in
 		c.cl_extern <- List.mem HExtern herits;
 		c.cl_extern <- List.mem HExtern herits;
@@ -566,7 +566,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 	| EEnum d ->
 	| EEnum d ->
 		let e = (match get_type (fst d.d_name) with TEnumDecl e -> e | _ -> assert false) in
 		let e = (match get_type (fst d.d_name) with TEnumDecl e -> e | _ -> assert false) in
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
-			Display.DisplayEmitter.display_module_type ctx.com.display (TEnumDecl e) (pos d.d_name);
+			Display.DisplayEmitter.display_module_type ctx (TEnumDecl e) (pos d.d_name);
 		let ctx = { ctx with type_params = e.e_params } in
 		let ctx = { ctx with type_params = e.e_params } in
 		let h = (try Some (Hashtbl.find ctx.g.type_patches e.e_path) with Not_found -> None) in
 		let h = (try Some (Hashtbl.find ctx.g.type_patches e.e_path) with Not_found -> None) in
 		TypeloadCheck.check_global_metadata ctx e.e_meta (fun m -> e.e_meta <- m :: e.e_meta) e.e_module.m_path e.e_path None;
 		TypeloadCheck.check_global_metadata ctx e.e_meta (fun m -> e.e_meta <- m :: e.e_meta) e.e_module.m_path e.e_path None;
@@ -670,7 +670,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 				cf_params = f.ef_params;
 				cf_params = f.ef_params;
 			} in
 			} in
  			if ctx.is_display_file && Display.is_display_position f.ef_name_pos then
  			if ctx.is_display_file && Display.is_display_position f.ef_name_pos then
- 				Display.DisplayEmitter.display_enum_field ctx.com.display f p;
+ 				Display.DisplayEmitter.display_enum_field ctx f p;
 			e.e_constrs <- PMap.add f.ef_name f e.e_constrs;
 			e.e_constrs <- PMap.add f.ef_name f e.e_constrs;
 			fields := PMap.add cf.cf_name cf !fields;
 			fields := PMap.add cf.cf_name cf !fields;
 			incr index;
 			incr index;
@@ -697,7 +697,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 	| ETypedef d ->
 	| ETypedef d ->
 		let t = (match get_type (fst d.d_name) with TTypeDecl t -> t | _ -> assert false) in
 		let t = (match get_type (fst d.d_name) with TTypeDecl t -> t | _ -> assert false) in
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
-			Display.DisplayEmitter.display_module_type ctx.com.display (TTypeDecl t) (pos d.d_name);
+			Display.DisplayEmitter.display_module_type ctx (TTypeDecl t) (pos d.d_name);
 		TypeloadCheck.check_global_metadata ctx t.t_meta (fun m -> t.t_meta <- m :: t.t_meta) t.t_module.m_path t.t_path None;
 		TypeloadCheck.check_global_metadata ctx t.t_meta (fun m -> t.t_meta <- m :: t.t_meta) t.t_module.m_path t.t_path None;
 		let ctx = { ctx with type_params = t.t_params } in
 		let ctx = { ctx with type_params = t.t_params } in
 		let tt = load_complex_type ctx true p d.d_data in
 		let tt = load_complex_type ctx true p d.d_data in
@@ -748,7 +748,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 	| EAbstract d ->
 	| EAbstract d ->
 		let a = (match get_type (fst d.d_name) with TAbstractDecl a -> a | _ -> assert false) in
 		let a = (match get_type (fst d.d_name) with TAbstractDecl a -> a | _ -> assert false) in
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
 		if ctx.is_display_file && Display.is_display_position (pos d.d_name) then
-			Display.DisplayEmitter.display_module_type ctx.com.display (TAbstractDecl a) (pos d.d_name);
+			Display.DisplayEmitter.display_module_type ctx (TAbstractDecl a) (pos d.d_name);
 		TypeloadCheck.check_global_metadata ctx a.a_meta (fun m -> a.a_meta <- m :: a.a_meta) a.a_module.m_path a.a_path None;
 		TypeloadCheck.check_global_metadata ctx a.a_meta (fun m -> a.a_meta <- m :: a.a_meta) a.a_module.m_path a.a_path None;
 		let ctx = { ctx with type_params = a.a_params } in
 		let ctx = { ctx with type_params = a.a_params } in
 		let is_type = ref false in
 		let is_type = ref false in

+ 5 - 4
src/typing/typer.ml

@@ -1471,7 +1471,7 @@ and type_vars ctx vl p =
 			let v = add_local ctx v t pv in
 			let v = add_local ctx v t pv in
 			v.v_meta <- (Meta.UserVariable,[],pv) :: v.v_meta;
 			v.v_meta <- (Meta.UserVariable,[],pv) :: v.v_meta;
 			if ctx.in_display && Display.is_display_position pv then
 			if ctx.in_display && Display.is_display_position pv then
-				Display.DisplayEmitter.display_variable ctx.com.display v pv;
+				Display.DisplayEmitter.display_variable ctx v pv;
 			v,e
 			v,e
 		with
 		with
 			Error (e,p) ->
 			Error (e,p) ->
@@ -1651,7 +1651,7 @@ and type_object_decl ctx fl with_type p =
 					| Some t -> t
 					| Some t -> t
 					| None ->
 					| None ->
 						let cf = PMap.find n field_map in
 						let cf = PMap.find n field_map in
-						if ctx.in_display && Display.is_display_position pn then Display.DisplayEmitter.display_field ctx.com.display None cf pn;
+						if ctx.in_display && Display.is_display_position pn then Display.DisplayEmitter.display_field ctx None cf pn;
 						cf.cf_type
 						cf.cf_type
 				in
 				in
 				let e = type_expr ctx e (WithType t) in
 				let e = type_expr ctx e (WithType t) in
@@ -1689,7 +1689,7 @@ and type_object_decl ctx fl with_type p =
 			let e = type_expr ctx e Value in
 			let e = type_expr ctx e Value in
 			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
 			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
 			let cf = mk_field f e.etype (punion pf e.epos) pf in
 			let cf = mk_field f e.etype (punion pf e.epos) pf in
-			if ctx.in_display && Display.is_display_position pf then Display.DisplayEmitter.display_field ctx.com.display None cf pf;
+			if ctx.in_display && Display.is_display_position pf then Display.DisplayEmitter.display_field ctx None cf pf;
 			(((f,pf,qs),e) :: l, if is_valid then begin
 			(((f,pf,qs),e) :: l, if is_valid then begin
 				if String.length f > 0 && f.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
 				if String.length f > 0 && f.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
 				PMap.add f cf acc
 				PMap.add f cf acc
@@ -1885,7 +1885,7 @@ and type_try ctx e1 catches with_type p =
 		let locals = save_locals ctx in
 		let locals = save_locals ctx in
 		let v = add_local ctx v t pv in
 		let v = add_local ctx v t pv in
 		if ctx.is_display_file && Display.is_display_position pv then
 		if ctx.is_display_file && Display.is_display_position pv then
-			Display.DisplayEmitter.display_variable ctx.com.display v pv;
+			Display.DisplayEmitter.display_variable ctx v pv;
 		let e = type_expr ctx e_ast with_type in
 		let e = type_expr ctx e_ast with_type in
 		(* If the catch position is the display position it means we get completion on the catch keyword or some
 		(* If the catch position is the display position it means we get completion on the catch keyword or some
 		   punctuation. Otherwise we wouldn't reach this point. *)
 		   punctuation. Otherwise we wouldn't reach this point. *)
@@ -2482,6 +2482,7 @@ let rec create com =
 			do_create = create;
 			do_create = create;
 			do_macro = MacroContext.type_macro;
 			do_macro = MacroContext.type_macro;
 			do_load_module = TypeloadModule.load_module;
 			do_load_module = TypeloadModule.load_module;
+			do_load_type_def = Typeload.load_type_def;
 			do_optimize = Optimizer.reduce_expression;
 			do_optimize = Optimizer.reduce_expression;
 			do_build_instance = InstanceBuilder.build_instance;
 			do_build_instance = InstanceBuilder.build_instance;
 			do_format_string = format_string;
 			do_format_string = format_string;

+ 1 - 1
src/typing/typerDisplay.ml

@@ -190,7 +190,7 @@ and display_expr ctx e_ast e dk with_type p =
 			| _ -> e.etype,None
 			| _ -> e.etype,None
 		in
 		in
 		let t,doc = loop e in
 		let t,doc = loop e in
-		raise_type t p doc
+		raise_type (Display.DisplayEmitter.patch_type ctx t) p doc
 	| DMUsage _ ->
 	| DMUsage _ ->
 		let rec loop e = match e.eexpr with
 		let rec loop e = match e.eexpr with
 		| TField(_,FEnum(_,ef)) ->
 		| TField(_,FEnum(_,ef)) ->

+ 38 - 5
std/haxe/rtti/JsonModuleTypesPrinter.hx

@@ -22,8 +22,11 @@
 package haxe.rtti;
 package haxe.rtti;
 
 
 import haxe.rtti.JsonModuleTypes;
 import haxe.rtti.JsonModuleTypes;
+using Lambda;
 
 
 class JsonModuleTypesPrinter {
 class JsonModuleTypesPrinter {
+	var indent = "";
+
     public function new() {
     public function new() {
 
 
     }
     }
@@ -54,19 +57,49 @@ class JsonModuleTypesPrinter {
                 if (t.args == null) {
                 if (t.args == null) {
                     "Dynamic";
                     "Dynamic";
                 } else {
                 } else {
-                    var s = printType(t.args);
+                    var s = printTypeRec(t.args);
                     'Dynamic<$s>';
                     'Dynamic<$s>';
                 }
                 }
             case TAnonymous:
             case TAnonymous:
                 var fields = t.args.fields;
                 var fields = t.args.fields;
-                var s = [for (field in fields) '${field.name}: ${printType(field.type)}'].join(", ");
+                var s = [for (field in fields) '${field.name}: ${printTypeRec(field.type)}'].join(", ");
                 '{ $s }';
                 '{ $s }';
             case TFun:
             case TFun:
+                var hasNamed = false;
                 function printFunctionArgument(arg:JsonFunctionArgument) {
                 function printFunctionArgument(arg:JsonFunctionArgument) {
-                    return (arg.opt ? "?" : "") + arg.name + ":" + printType(arg.t);
+                    if (arg.name != "") {
+                        hasNamed = true;
+                    }
+                    return this.printFunctionArgument(arg);
+                }
+                var args = t.args.args.map(printFunctionArgument);
+                var r = printTypeRec(t.args.ret);
+                switch (args.length) {
+                    case 0: '()->$r';
+                    case 1 if (hasNamed): '(${args[0]})->$r';
+                    case 1 : '${args[0]}->$r';
+                    case _:
+                        var busy = args.fold((args,i) -> i + args.length,0);
+                        if (busy < 50) {
+                            var s = args.join(", ");
+                            '($s)->$r';
+                        } else {
+                            var s = args.join(',\n $indent');
+                            '($s)\n$indent-> $r';
+                        }
                 }
                 }
-                var s = t.args.args.map(printFunctionArgument).join(", ");
-                '($s) -> ${printType(t.args.ret)}';
         }
         }
     }
     }
+
+    function printTypeRec<T>(t:JsonType<T>) {
+        var old = indent;
+        indent += "  ";
+        var t = printType(t);
+        indent = old;
+        return t;
+    }
+
+    public function printFunctionArgument(arg:JsonFunctionArgument) {
+        return (arg.opt ? "?" : "") + (arg.name == "" ? "" : arg.name + ":") + printTypeRec(arg.t);
+    }
 }
 }

+ 1 - 1
tests/display/src/cases/Basic.hx

@@ -110,6 +110,6 @@ class Basic extends DisplayTestCase {
 	}
 	}
 	**/
 	**/
 	function testCtorClosureType() {
 	function testCtorClosureType() {
-		eq("someName : Int -> cases.Some", type(pos(1)));
+		eq("someName : Int -> Some", type(pos(1)));
 	}
 	}
 }
 }

+ 3 - 3
tests/display/src/cases/BuildMacro.hx

@@ -23,9 +23,9 @@ class BuildMacro extends DisplayTestCase {
 	}
 	}
 	**/
 	**/
 	function test1() {
 	function test1() {
-		eq("cases.MyString", type(pos(2)));
-		eq("cases.MyString", type(pos(3)));
-		eq("cases.MyString", type(pos(4)));
+		eq("MyString", type(pos(2)));
+		eq("MyString", type(pos(3)));
+		eq("MyString", type(pos(4)));
 		eq(range(7, 8), position(pos(3)));
 		eq(range(7, 8), position(pos(3)));
 		eq(range(7, 8), position(pos(4)));
 		eq(range(7, 8), position(pos(4)));
 		eq(range(5, 6), position(pos(2)));
 		eq(range(5, 6), position(pos(2)));

+ 2 - 2
tests/display/src/cases/Issue5141.hx

@@ -13,7 +13,7 @@ class Issue5141 extends DisplayTestCase {
 	}
 	}
 	**/
 	**/
 	function testTypedef() {
 	function testTypedef() {
-		eq("cases.MyHandler", type(pos(1)));
+		eq("MyHandler", type(pos(1)));
 		sigEq(0, [[":Int", ":String"]], signature(pos(2)));
 		sigEq(0, [[":Int", ":String"]], signature(pos(2)));
 	}
 	}
 
 
@@ -30,7 +30,7 @@ class Issue5141 extends DisplayTestCase {
 	}
 	}
 	**/
 	**/
 	function testAbstract() {
 	function testAbstract() {
-		eq("cases.MyCallable", type(pos(1)));
+		eq("MyCallable", type(pos(1)));
 		sigEq(0, [[":Int", ":String"]], signature(pos(2)));
 		sigEq(0, [[":Int", ":String"]], signature(pos(2)));
 	}
 	}
 }
 }

+ 1 - 1
tests/display/src/cases/Issue5166.hx

@@ -8,7 +8,7 @@ class Issue5166 extends DisplayTestCase {
 
 
 	**/
 	**/
 	function test() {
 	function test() {
-		eq("cases.E", type(pos(2)));
+		eq("E", type(pos(2)));
 		eq(range(2, 1), position(pos(2)));
 		eq(range(2, 1), position(pos(2)));
 	}
 	}
 }
 }

+ 2 - 2
tests/display/src/cases/Issue6029.hx

@@ -11,7 +11,7 @@ class Issue6029 extends DisplayTestCase {
 		}
 		}
 	**/
 	**/
 	function test() {
 	function test() {
-		eq("cases.A", type(pos(1)));
-		eq("cases.B", type(pos(2)));
+		eq("A", type(pos(1)));
+		eq("B", type(pos(2)));
 	}
 	}
 }
 }

+ 1 - 1
tests/display/src/cases/Issue6275.hx

@@ -13,7 +13,7 @@ class Issue6275 extends DisplayTestCase {
 	}
 	}
 	**/
 	**/
 	function test() {
 	function test() {
-		eq("s : String -> cases.Main", type(pos(2)));
+		eq("s : String -> Main", type(pos(2)));
 		eq(range(4, 5), position(pos(1)));
 		eq(range(4, 5), position(pos(1)));
 		eq(range(1, 3), usage(pos(2))[0]);
 		eq(range(1, 3), usage(pos(2))[0]);
 	}
 	}

+ 1 - 1
tests/display/src/cases/Issue6381.hx

@@ -15,7 +15,7 @@ class Issue6381 extends DisplayTestCase {
 	}
 	}
 	**/
 	**/
 	function test() {
 	function test() {
-		eq("haxe.ds.Option<String>", type(pos(2)));
+		eq("Option<String>", type(pos(2)));
 		eq(range(1, 3), position(pos(2)));
 		eq(range(1, 3), position(pos(2)));
 		eq(range(4, 5), usage(pos(2))[0]);
 		eq(range(4, 5), usage(pos(2))[0]);
 	}
 	}

+ 1 - 1
tests/display/src/cases/Issue6405.hx

@@ -19,7 +19,7 @@ class Issue6405 extends DisplayTestCase {
 		eq(range(2, 3), position(pos(1)));
 		eq(range(2, 3), position(pos(1)));
 		var usage = usage(pos(2));
 		var usage = usage(pos(2));
 		arrayEq([range(1, 5)], usage);
 		arrayEq([range(1, 5)], usage);
-		eq("haxe.macro.Expr", type(pos(1)));
+		eq("Expr", type(pos(1)));
 		var fields = fields(pos(4));
 		var fields = fields(pos(4));
 		eq(true, hasField(fields, "expr", "haxe.macro.ExprDef"));
 		eq(true, hasField(fields, "expr", "haxe.macro.ExprDef"));
 		eq(true, hasField(fields, "toString", "Void -> String"));
 		eq(true, hasField(fields, "toString", "Void -> String"));

+ 1 - 1
tests/display/src/cases/Issue7022.hx

@@ -11,6 +11,6 @@ class Issue7022 extends DisplayTestCase {
 	}
 	}
 	**/
 	**/
 	function test() {
 	function test() {
-		eq("Void -> cases.Main", type(pos(1)));
+		eq("Void -> Main", type(pos(1)));
 	}
 	}
 }
 }

+ 2 - 2
tests/display/src/cases/Super.hx

@@ -13,7 +13,7 @@ class Super extends DisplayTestCase {
 	**/
 	**/
 	function testSuperCall() {
 	function testSuperCall() {
 		eq(range(1, 2), position(pos(3)));
 		eq(range(1, 2), position(pos(3)));
-		eq("cases.Base<String>", type(pos(3)));
+		eq("Base<String>", type(pos(3)));
 		arrayEq([range(4, 5)], usage(pos(3)));
 		arrayEq([range(4, 5)], usage(pos(3)));
 	}
 	}
 
 
@@ -29,7 +29,7 @@ class Super extends DisplayTestCase {
 	**/
 	**/
 	function testSuperField() {
 	function testSuperField() {
 		eq(range(1, 2), position(pos(3)));
 		eq(range(1, 2), position(pos(3)));
-		eq("cases.Base<String>", type(pos(3)));
+		eq("Base<String>", type(pos(3)));
 		eq(range(4, 5), position(pos(6)));
 		eq(range(4, 5), position(pos(6)));
 		eq("Void -> Void", type(pos(6)));
 		eq("Void -> Void", type(pos(6)));
 	}
 	}

+ 1 - 1
tests/display/src/cases/Type.hx

@@ -5,6 +5,6 @@ class Type extends DisplayTestCase {
 	abstract {-1-}A(Int) {}
 	abstract {-1-}A(Int) {}
 	**/
 	**/
 	function testAbstractDecl() {
 	function testAbstractDecl() {
-		eq("cases.A", type(pos(1)));
+		eq("A", type(pos(1)));
 	}
 	}
 }
 }

+ 1 - 1
tests/misc/projects/Issue5118/compile1.hxml.stderr

@@ -1,3 +1,3 @@
 <type p="$$normPath(::cwd::/Main.hx):8: characters 18-22">
 <type p="$$normPath(::cwd::/Main.hx):8: characters 18-22">
-v : Int -&gt; haxe.ds.Option&lt;Int&gt;
+v : Int -&gt; Option&lt;Int&gt;
 </type>
 </type>

+ 1 - 1
tests/misc/projects/Issue5118/compile2.hxml.stderr

@@ -1,3 +1,3 @@
 <type p="$$normPath(::cwd::/Main.hx):7: characters 18-22">
 <type p="$$normPath(::cwd::/Main.hx):7: characters 18-22">
-haxe.ds.Option&lt;Int&gt;
+Option&lt;Int&gt;
 </type>
 </type>