Pārlūkot izejas kodu

[display] fix hover origin of class fields

closes #7105
Simon Krajewski 7 gadi atpakaļ
vecāks
revīzija
cdd87e1956
3 mainītis faili ar 19 papildinājumiem un 8 dzēšanām
  1. 4 2
      src/core/meta.ml
  2. 1 0
      src/typing/calls.ml
  3. 14 6
      src/typing/typerDisplay.ml

+ 4 - 2
src/core/meta.ml

@@ -149,6 +149,7 @@ type strict_meta =
 	| Sound
 	| SourceFile
 	| StackOnly
+	| StaticExtension
 	| StoredTypedExpr
 	| Strict
 	| Struct
@@ -343,12 +344,13 @@ let get_info = function
 	| Scalar -> ":scalar",("Used by hxcpp to mark a custom coreType abstract",[UsedOn TAbstract; Platform Cpp])
 	| SelfCall -> ":selfCall",("Translates method calls into calling object directly",[UsedOn TClassField; Platforms [Js;Lua]])
 	| Setter -> ":setter",("Generates a native setter function on the given field",[HasParam "Class field name";UsedOn TClassField;Platform Flash])
-	| StackOnly -> ":stackOnly",("Instances of this type can only appear on the stack",[Platform Cpp])
-	| StoredTypedExpr -> ":storedTypedExpr",("Used internally to reference a typed expression returned from a macro",[UsedInternally])
 	| SkipCtor -> ":skipCtor",("Used internally to generate a constructor as if it were a native type (no __hx_ctor)",[Platforms [Java;Cs]; UsedInternally])
 	| SkipReflection -> ":skipReflection",("Used internally to annotate a field that shouldn't have its reflection data generated",[Platforms [Java;Cs]; UsedOn TClassField; UsedInternally])
 	| Sound -> ":sound",( "Includes a given .wav or .mp3 file into the target Swf and associates it with the class (must extend flash.media.Sound)",[HasParam "File path";UsedOn TClass;Platform Flash])
 	| SourceFile -> ":sourceFile",("Source code filename for external class",[Platform Cpp])
+	| StackOnly -> ":stackOnly",("Instances of this type can only appear on the stack",[Platform Cpp])
+	| StaticExtension -> "haxe.internal.static_extension",("Used internally to mark static extension fields",[UsedInternally])
+	| StoredTypedExpr -> ":storedTypedExpr",("Used internally to reference a typed expression returned from a macro",[UsedInternally])
 	| Strict -> ":strict",("Used to declare a native C# attribute or a native Java metadata. Is type checked",[Platforms [Java;Cs]])
 	| Struct -> ":struct",("Marks a class definition as a struct",[Platform Cs; UsedOn TClass])
 	| StructAccess -> ":structAccess",("Marks an extern class as using struct access('.') not pointer('->')",[Platform Cpp; UsedOn TClass])

+ 1 - 0
src/typing/calls.ml

@@ -411,6 +411,7 @@ let rec acc_get ctx g p =
 	| AKUsing (et,c,cf,e) when ctx.in_display ->
 		(* Generate a TField node so we can easily match it for position/usage completion (issue #1968) *)
 		let ec = type_module_type ctx (TClassDecl c) None p in
+		let ec = {ec with eexpr = (TMeta((Meta.StaticExtension,[],null_pos),ec))} in
 		let t = match follow et.etype with
 			| TFun (_ :: args,ret) -> TFun(args,ret)
 			| _ -> et.etype

+ 14 - 6
src/typing/typerDisplay.ml

@@ -36,14 +36,22 @@ let completion_item_of_expr ctx e =
 		let t = DisplayEmitter.patch_type ctx e.etype in
 		make_ci_expr {e with etype = t}
 	in
-	let class_origin c = match c.cl_kind with
-		| KAbstractImpl a -> TAbstractDecl a
-		| _ -> TClassDecl c
+	let class_origin static c = match c.cl_kind with
+		| KAbstractImpl a -> Self (TAbstractDecl a)
+		| _ ->
+			if static then Self (TClassDecl c)
+			else if c != ctx.curclass then Parent (TClassDecl c)
+			else Self (TClassDecl c)
 	in
 	let rec loop e = match e.eexpr with
 		| TLocal v | TVar(v,_) -> make_ci_local v (DisplayEmitter.patch_type ctx v.v_type)
-		| TField(_,FStatic(c,cf)) -> of_field e (Self (class_origin c)) cf CFSStatic
-		| TField(_,(FInstance(c,_,cf) | FClosure(Some(c,_),cf))) -> of_field e (Self (class_origin c)) cf CFSMember
+		| TField(e1,FStatic(c,cf)) ->
+			let origin = match e1.eexpr with
+				| TMeta((Meta.StaticExtension,_,_),_) -> StaticExtension (TClassDecl c)
+				| _ -> class_origin true c
+			in
+			of_field e origin cf CFSStatic
+		| TField(_,(FInstance(c,_,cf) | FClosure(Some(c,_),cf))) -> of_field e (class_origin false c) cf CFSMember
 		| TField(_,FEnum(en,ef)) -> of_enum_field e (Self (TEnumDecl en)) ef
 		| TField(e1,FAnon cf) ->
 			begin match follow e1.etype with
@@ -93,7 +101,7 @@ let completion_item_of_expr ctx e =
 					| TFun(args,_) -> TFun(args,TInst(c,tl))
 					| _ -> t
 				in
-				make_ci_class_field (CompletionClassField.make {cf with cf_type = t} CFSConstructor (Self (class_origin c)) true) (DisplayEmitter.patch_type ctx t)
+				make_ci_class_field (CompletionClassField.make {cf with cf_type = t} CFSConstructor (class_origin false c) true) (DisplayEmitter.patch_type ctx t)
 			(* end *)
 		| TCall({eexpr = TConst TSuper; etype = t} as e1,_) ->
 			itexpr e1 (* TODO *)