浏览代码

handle @:forwardStatics for completion (fixes #7761)

Aleksandr Kuzmenko 6 年之前
父节点
当前提交
7353ce621f
共有 2 个文件被更改,包括 41 次插入1 次删除
  1. 20 1
      src/context/display/displayFields.ml
  2. 21 0
      tests/display/src/cases/Issue7761.hx

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

@@ -181,7 +181,26 @@ let collect ctx e_ast e dk with_type p =
 				items
 			end
 		| TAnon an ->
-			(* Anons only have their own fields. *)
+			(* @:forwardStatics *)
+			let items = match !(an.a_status) with
+				| Statics { cl_kind = KAbstractImpl { a_meta = meta; a_this = TInst (c,_) }} when Meta.has Meta.ForwardStatics meta ->
+					let items = List.fold_left (fun acc cf ->
+						if should_access c cf true && is_new_item acc cf.cf_name then begin
+							let origin = Self(TClassDecl c) in
+							let item = make_class_field origin cf in
+							PMap.add cf.cf_name item acc
+						end else
+							acc
+					) items c.cl_ordered_statics in
+					PMap.foldi (fun name item acc ->
+						if is_new_item acc name then
+							PMap.add name item acc
+						else
+							acc
+					) PMap.empty items
+				| _ -> items
+			in
+			(* Anon own fields *)
 			PMap.foldi (fun name cf acc ->
 				if is_new_item acc name then begin
 					let allow_static_abstract_access c cf =

+ 21 - 0
tests/display/src/cases/Issue7761.hx

@@ -0,0 +1,21 @@
+package cases;
+
+class Issue7761 extends DisplayTestCase {
+	/**
+		class Main {
+			public static function main() {
+				Boolean.{-1-}
+			}
+		}
+
+		@:forwardStatics
+		abstract Boolean(BooleanClass) {}
+
+		extern class BooleanClass {
+			static function foo():Int;
+		}
+	**/
+	function test() {
+		eq(true, hasField(fields(pos(1)), "foo", "Void -> Int"));
+	}
+}