Browse Source

[display] try to deal with abstracts in completion

closes #7089
Simon Krajewski 7 years ago
parent
commit
070c018b9b

+ 8 - 0
src/context/display/displayEmitter.ml

@@ -23,6 +23,14 @@ let patch_type ctx t =
 		| 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)
+		| TAnon an ->
+			begin match !(an.a_status) with
+			| Statics {cl_kind = KAbstractImpl a} ->
+				an.a_status := AbstractStatics a
+			| _ ->
+				()
+			end;
+			Type.map patch t
 		| _ -> Type.map patch t
 	in
 	patch t

+ 1 - 0
src/context/display/displayFields.ml

@@ -153,6 +153,7 @@ let collect ctx e_ast e dk with_type p =
 			PMap.foldi (fun name cf acc ->
 				if is_new_item acc name then begin
 					let origin,check = match !(an.a_status) with
+						| Statics ({cl_kind = KAbstractImpl a} as c) -> Self (TAbstractDecl a),should_access c cf false
 						| Statics c -> Self (TClassDecl c),should_access c cf true
 						| EnumStatics en -> Self (TEnumDecl en),true
 						| AbstractStatics a ->

+ 7 - 1
src/typing/typerDisplay.ml

@@ -51,7 +51,13 @@ let completion_item_of_expr ctx e =
 					of_field e origin cf CFSMember
 				| _ -> itexpr e
 			end
-		| TTypeExpr mt -> make_ci_type (CompletionModuleType.of_module_type mt) ImportStatus.Imported (Some e.etype) (* TODO *)
+		| TTypeExpr (TClassDecl {cl_kind = KAbstractImpl a}) ->
+			let t = TType(abstract_module_type a (List.map snd a.a_params),[]) in
+			let t = DisplayEmitter.patch_type ctx t in
+			make_ci_type (CompletionModuleType.of_module_type (TAbstractDecl a)) ImportStatus.Imported (Some t)
+		| TTypeExpr mt ->
+			let t = DisplayEmitter.patch_type ctx e.etype in
+			make_ci_type (CompletionModuleType.of_module_type mt) ImportStatus.Imported (Some t) (* TODO *)
 		| TConst (TThis | TSuper) -> itexpr e (* TODO *)
 		| TConst(ct) -> make_ci_literal (s_const ct) e.etype
 		| TObjectDecl _ ->

+ 16 - 1
tests/display/src/cases/Issue7084.hx

@@ -13,7 +13,22 @@ class Issue7084 extends DisplayTestCase {
 		}
 	}
 	**/
-	function test() {
+	function test1() {
 		eq(0, fields(pos(1)).length);
 	}
+
+	/**
+	enum abstract Foo(Int) {
+		var Value = 0;
+	}
+
+	class Main {
+		public static function main() {
+			Foo.{-1-};
+		}
+	}
+	**/
+	function test2() {
+		eq("Value", fields(pos(1))[0].name);
+	}
 }

+ 18 - 0
tests/display/src/cases/Issue7089.hx

@@ -0,0 +1,18 @@
+package cases;
+
+class Issue7089 extends DisplayTestCase {
+	/**
+	enum abstract Foo(Int) {
+		var Value = 1;
+	}
+
+	class Main {
+		static function main() {
+			Fo{-1-}o;
+		}
+	}
+	**/
+	function test() {
+		eq("Abstract<cases.Foo>", type(pos(1)));
+	}
+}