浏览代码

[display] fix more _Impl_ and kind issues for enum abstract fields (#7322)

* [display] fix _Impl_ and kind for statically imported enum abstract fields

* Fix even more _Impl_

* Fix even more kinds
Jens Fischer 7 年之前
父节点
当前提交
266aa3126a
共有 3 个文件被更改,包括 21 次插入12 次删除
  1. 8 3
      src/context/display/displayToplevel.ml
  2. 4 0
      src/core/display/completionItem.ml
  3. 9 9
      src/typing/typerDisplay.ml

+ 8 - 3
src/context/display/displayToplevel.ml

@@ -236,7 +236,7 @@ let collect ctx tk with_type =
 			| TAbstractDecl ({a_impl = Some c} as a) when Meta.has Meta.Enum a.a_meta && not (path_exists cctx a.a_path) ->
 				add_path cctx a.a_path;
 				List.iter (fun cf ->
-					let ccf = CompletionClassField.make cf CFSMember (Self (TClassDecl c)) true in
+					let ccf = CompletionClassField.make cf CFSMember (Self (decl_of_class c)) true in
 					if (Meta.has Meta.Enum cf.cf_meta) && not (Meta.has Meta.NoCompletion cf.cf_meta) then
 						add (make_ci_enum_abstract_field a ccf (tpair cf.cf_type)) (Some cf.cf_name);
 				) c.cl_ordered_statics
@@ -272,8 +272,13 @@ let collect ctx tk with_type =
 				let class_import c =
 					let cf = PMap.find s c.cl_statics in
 					let cf = if name = cf.cf_name then cf else {cf with cf_name = name} in
-					let origin = StaticImport (TClassDecl c) in
-					add (make_ci_class_field (CompletionClassField.make cf CFSStatic origin is_qualified) (tpair ~values:(get_value_meta cf.cf_meta) cf.cf_type)) (Some name)
+					let decl,make = match c.cl_kind with 
+						| KAbstractImpl a -> TAbstractDecl a,
+							if Meta.has Meta.Enum cf.cf_meta then make_ci_enum_abstract_field a else make_ci_class_field
+						| _ -> TClassDecl c,make_ci_class_field
+					in
+					let origin = StaticImport decl in
+					add (make (CompletionClassField.make cf CFSStatic origin is_qualified) (tpair ~values:(get_value_meta cf.cf_meta) cf.cf_type)) (Some name)
 				in
 				match resolve_typedef mt with
 					| TClassDecl c -> class_import c;

+ 4 - 0
src/core/display/completionItem.ml

@@ -235,6 +235,10 @@ module ClassFieldOrigin = struct
 		)
 end
 
+let decl_of_class c = match c.cl_kind with
+	| KAbstractImpl a -> TAbstractDecl a
+	| _ -> TClassDecl c
+	
 module CompletionClassField = struct
 	type t = {
 		field : tclass_field;

+ 9 - 9
src/typing/typerDisplay.ml

@@ -33,9 +33,9 @@ let completion_item_of_expr ctx e =
 		let ct = DisplayEmitter.completion_type_of_type ctx ~values t in
 		(t,ct)
 	in
-	let of_field e origin cf scope =
+	let of_field e origin cf scope make_ci =
 		let is_qualified = retype e cf.cf_name e.etype in
-		make_ci_class_field (CompletionClassField.make cf scope origin is_qualified) (tpair ~values:(get_value_meta cf.cf_meta) e.etype)
+		make_ci (CompletionClassField.make cf scope origin is_qualified) (tpair ~values:(get_value_meta cf.cf_meta) e.etype)
 	in
 	let of_enum_field e origin ef =
 		let is_qualified = retype e ef.ef_name e.etype in
@@ -45,10 +45,6 @@ let completion_item_of_expr ctx e =
 		let t = tpair e.etype in
 		make_ci_expr e t
 	in
-	let decl_of_class c = match c.cl_kind with
-		| KAbstractImpl a -> TAbstractDecl a
-		| _ -> TClassDecl c
-	in
 	let rec loop e = match e.eexpr with
 		| TLocal v | TVar(v,_) -> make_ci_local v (tpair ~values:(get_value_meta v.v_meta) v.v_type)
 		| TField(e1,FStatic(c,cf)) ->
@@ -58,7 +54,11 @@ let completion_item_of_expr ctx e =
 				| _,TMeta((Meta.StaticExtension,_,_),_) -> StaticExtension decl
 				| _ -> Self decl
 			in
-			of_field e origin cf CFSStatic
+			let make_ci = match c.cl_kind with
+				| KAbstractImpl a when Meta.has Meta.Enum cf.cf_meta -> make_ci_enum_abstract_field a
+				| _ -> make_ci_class_field
+			in
+			of_field e origin cf CFSStatic make_ci
 		| TField(e1,(FInstance(c,_,cf) | FClosure(Some(c,_),cf))) ->
 			let origin = match follow e1.etype with
 			| TInst(c',_) when c != c' ->
@@ -66,7 +66,7 @@ let completion_item_of_expr ctx e =
 			| _ ->
 				Self (TClassDecl c)
 			in
-			of_field e origin cf CFSMember
+			of_field e origin cf CFSMember make_ci_class_field
 		| TField(_,FEnum(en,ef)) -> of_enum_field e (Self (TEnumDecl en)) ef
 		| TField(e1,FAnon cf) ->
 			begin match follow e1.etype with
@@ -75,7 +75,7 @@ let completion_item_of_expr ctx e =
 						| TType(td,_) -> Self (TTypeDecl td)
 						| _ -> AnonymousStructure an
 					in
-					of_field e origin cf CFSMember
+					of_field e origin cf CFSMember make_ci_class_field
 				| _ -> itexpr e
 			end
 		| TTypeExpr (TClassDecl {cl_kind = KAbstractImpl a}) ->