Răsfoiți Sursa

[display] deal with typedefs in new completion

closes #7224
Simon Krajewski 7 ani în urmă
părinte
comite
047c34f654

+ 12 - 6
src/core/display/completionItem.ml

@@ -132,19 +132,25 @@ module CompletionModuleType = struct
 			raise Exit
 
 	let of_module_type mt =
+		let has_ctor a = match a.a_impl with
+			| None -> false
+			| Some c -> PMap.mem "_new" c.cl_statics
+		in
 		let is_extern,kind,has_ctor = match mt with
 			| TClassDecl c ->
 				c.cl_extern,(if c.cl_interface then Interface else Class),has_constructor c
 			| TEnumDecl en ->
 				en.e_extern,Enum,false
 			| TTypeDecl td ->
-				false,(match follow td.t_type with TAnon _ -> Struct | _ -> TypeAlias),false
-			| TAbstractDecl a ->
-				let has_ctor = match a.a_impl with
-					| None -> false
-					| Some c -> PMap.mem "_new" c.cl_statics
+				let kind,has_ctor = match follow td.t_type with
+					| TAnon _ -> Struct,false
+					| TInst(c,_) -> TypeAlias,has_constructor c
+					| TAbstract(a,_) -> TypeAlias,has_ctor a
+					| _ -> TypeAlias,false
 				in
-				false,(if Meta.has Meta.Enum a.a_meta then EnumAbstract else Abstract),has_ctor
+				false,kind,has_ctor
+			| TAbstractDecl a ->
+				false,(if Meta.has Meta.Enum a.a_meta then EnumAbstract else Abstract),has_ctor a
 		in
 		let infos = t_infos mt in
 		let convert_type_param (s,t) = match follow t with

+ 2 - 2
src/typing/typerDisplay.ml

@@ -405,14 +405,14 @@ let handle_display ctx e_ast dk with_type =
 				(pack,mt.module_name) = ctx.m.curmod.m_path
 			in
 			match item.ci_kind with
-			| ITType({kind = (Class | Abstract)} as mt,_) when not mt.is_private || is_private_to_current_module mt ->
+			| ITType({kind = (Class | Abstract | TypeAlias)} as mt,_) when not mt.is_private || is_private_to_current_module mt ->
 				begin match mt.has_constructor with
 				| Yes -> true
 				| No -> false
 				| Maybe ->
 					begin try
 						let mt = ctx.g.do_load_type_def ctx null_pos {tpackage=mt.pack;tname=mt.module_name;tsub=Some mt.name;tparams=[]} in
-						begin match mt with
+						begin match resolve_typedef mt with
 						| TClassDecl c when has_constructor c -> true
 						| TAbstractDecl {a_impl = Some c} -> PMap.mem "_new" c.cl_statics
 						| _ -> false

+ 24 - 0
tests/display/src/cases/Issue7224.hx

@@ -0,0 +1,24 @@
+package cases;
+
+class Issue7224 extends DisplayTestCase {
+	/**
+	typedef Nope = Int;
+
+	class Bar {
+		function new() {}
+	}
+	typedef Foo = Bar;
+
+	class Main {
+		static function main() {
+			new {-1-}
+		}
+	}
+	**/
+	function test() {
+		var items = toplevel(pos(1));
+		eq(false, hasToplevel(items, "type", "Nope"));
+		eq(true, hasToplevel(items, "type", "Bar"));
+		eq(true, hasToplevel(items, "type", "Foo"));
+	}
+}