2
0
Эх сурвалжийг харах

[display] consistently use type/field names as position targets

Simon Krajewski 7 жил өмнө
parent
commit
5bc1ffac60

+ 3 - 3
src/context/display.ml

@@ -134,7 +134,7 @@ end
 
 module DisplayEmitter = struct
 	let display_module_type dm mt p = match dm.dms_kind with
-		| DMPosition -> raise (DisplayPosition [(t_infos mt).mt_pos]);
+		| DMPosition -> raise (DisplayPosition [(t_infos mt).mt_name_pos]);
 		| DMUsage _ ->
 			let ti = t_infos mt in
 			ti.mt_meta <- (Meta.Usage,[],ti.mt_pos) :: ti.mt_meta
@@ -170,7 +170,7 @@ module DisplayEmitter = struct
 		| _ -> ()
 
 	let display_field dm cf p = match dm.dms_kind with
-		| DMPosition -> raise (DisplayPosition [cf.cf_pos]);
+		| DMPosition -> raise (DisplayPosition [cf.cf_name_pos]);
 		| DMUsage _ -> cf.cf_meta <- (Meta.Usage,[],cf.cf_pos) :: cf.cf_meta;
 		| DMType ->
 			let t = if Meta.has Meta.Impl cf.cf_meta then
@@ -185,7 +185,7 @@ module DisplayEmitter = struct
 		if is_display_position p then display_field ctx.com.display cf p
 
 	let display_enum_field dm ef p = match dm.dms_kind with
-		| DMPosition -> raise (DisplayPosition [p]);
+		| DMPosition -> raise (DisplayPosition [ef.ef_name_pos]);
 		| DMUsage _ -> ef.ef_meta <- (Meta.Usage,[],p) :: ef.ef_meta;
 		| DMType -> raise (DisplayType (ef.ef_type,p,ef.ef_doc))
 		| _ -> ()

+ 5 - 5
src/typing/typerDisplay.ml

@@ -180,28 +180,28 @@ and display_expr ctx e_ast e dk with_type p =
 		e
 	| DMPosition ->
 		let rec loop e = match e.eexpr with
-		| TField(_,FEnum(_,ef)) -> [ef.ef_pos]
-		| TField(_,(FAnon cf | FInstance (_,_,cf) | FStatic (_,cf) | FClosure (_,cf))) -> [cf.cf_pos]
+		| TField(_,FEnum(_,ef)) -> [ef.ef_name_pos]
+		| TField(_,(FAnon cf | FInstance (_,_,cf) | FStatic (_,cf) | FClosure (_,cf))) -> [cf.cf_name_pos]
 		| TLocal v | TVar(v,_) -> [v.v_pos]
 		| TTypeExpr mt -> [(t_infos mt).mt_pos]
 		| TNew(c,tl,_) ->
 			begin try
 				let _,cf = get_constructor ctx c tl p in
-				[cf.cf_pos]
+				[cf.cf_name_pos]
 			with Not_found ->
 				[]
 			end
 		| TCall({eexpr = TConst TSuper},_) ->
 			begin try
 				let cf = get_super_constructor() in
-				[cf.cf_pos]
+				[cf.cf_name_pos]
 			with Not_found ->
 				[]
 			end
 		| TConst TSuper ->
 			begin match ctx.curclass.cl_super with
 				| None -> []
-				| Some (c,_) -> [c.cl_pos]
+				| Some (c,_) -> [c.cl_name_pos]
 			end
 		| TCall(e1,_) ->
 			loop e1

+ 1 - 1
tests/display/src/cases/BuildMacro.hx

@@ -9,7 +9,7 @@ class BuildMacro extends DisplayTestCase {
 		}
 	}
 
-	{-7-}typedef MyString = String{-8-};
+	typedef {-7-}MyString{-8-} = String;
 
 	#if !macro
 	@:build(cases.BuildMacro.MyMacro.build())

+ 2 - 2
tests/display/src/cases/Issue5166.hx

@@ -3,12 +3,12 @@ package cases;
 class Issue5166 extends DisplayTestCase {
 	/**
 		enum abstract E(Int) {
-			{-2-}var A{-1-} = 5;{-3-}
+			var {-2-}A{-1-} = 5;
 		}
 
 	**/
 	function test() {
 		eq("cases.E", type(pos(1)));
-		eq(range(2, 3), position(pos(1)));
+		eq(range(2, 1), position(pos(1)));
 	}
 }

+ 1 - 1
tests/display/src/cases/Issue5712.hx

@@ -3,7 +3,7 @@ package cases;
 class Issue5712 extends DisplayTestCase {
 	/**
 	typedef Struct = {
-		{-1-}field:Float{-2-}
+		{-1-}field{-2-}:Float
 	}
 	class Main {
 		public static function main() {

+ 1 - 1
tests/display/src/cases/Issue5999.hx

@@ -3,7 +3,7 @@ package cases;
 class Issue5999 extends DisplayTestCase {
 	/**
 	class Main {
-		{-1-}static inline var value = 1;{-2-}
+		static inline var {-1-}value{-2-} = 1;
 
 		static public function main() {
 			trace(val{-3-}ue);

+ 1 - 1
tests/display/src/cases/Issue6275.hx

@@ -9,7 +9,7 @@ class Issue6275 extends DisplayTestCase {
 			{-1-}n{-2-}ew Main("foo"){-3-};
 		}
 
-		{-4-}function new(s:String) {}{-5-}
+		function {-4-}new{-5-}(s:String) {}
 	}
 	**/
 	function test() {

+ 1 - 1
tests/display/src/cases/Issue6422.hx

@@ -7,7 +7,7 @@ class Issue6422 extends DisplayTestCase {
 			pro{-1-}perty;
 		}
 
-		{-2-}static var property(get, set):Int;{-3-}
+		static var {-2-}property{-3-}(get, set):Int;
 		static function get_property() return 0;
 		static function set_property(i) return 0;
 	}

+ 1 - 1
tests/display/src/cases/Issue6442.hx

@@ -3,7 +3,7 @@ package cases;
 class Issue6442 extends DisplayTestCase {
 	/**
 	extern class Foo {
-		{-1-}function b{-2-}ar():Void;{-3-}
+		function {-1-}b{-2-}ar{-3-}():Void;
 	}
 	**/
 	function test() {

+ 2 - 2
tests/display/src/cases/PropertyAccessors.hx

@@ -5,8 +5,8 @@ class PropertyAccessors extends DisplayTestCase {
 	class Main {
 		static var test(ge{-1-}t, se{-2-}t):String;
 
-		{-3-}static public function get_test() return "foo"{-4-};
-		{-5-}static public function set_test(s:String) return s{-6-};
+		static public function {-3-}get_test{-4-}() return "foo";
+		static public function {-5-}set_test{-6-}(s:String) return s;
 
 		static function main() { }
 	}

+ 4 - 4
tests/display/src/cases/Super.hx

@@ -3,7 +3,7 @@ package cases;
 class Super extends DisplayTestCase {
 	/**
 	class Base<T> {
-		{-1-}public function new() { }{-2-}
+		public function {-1-}new{-2-}() { }
 	}
 	class Main extends Base<String> {
 		function new() {
@@ -18,9 +18,9 @@ class Super extends DisplayTestCase {
 	}
 
 	/**
-	{-1-}class Base<T> {
-		{-4-}public function test() { }{-5-}
-	}{-2-}
+	class {-1-}Base{-2-}<T> {
+		public function {-4-}test{-5-}() { }
+	}
 	class Main extends Base<String> {
 		override function test() {
 			su{-3-}per.te{-6-}st();

+ 1 - 1
tests/misc/projects/Issue1968/compile.hxml.stderr

@@ -1,3 +1,3 @@
 <list>
-<pos>$$normPath(::cwd::/Main.hx, true):4: characters 5-62</pos>
+<pos>$$normPath(::cwd::/Main.hx, true):4: characters 28-29</pos>
 </list>

+ 1 - 1
tests/misc/projects/Issue2995/position.hxml.stderr

@@ -1,3 +1,3 @@
 <list>
-<pos>$$normPath(::cwd::/Main.hx, true):2: characters 5-22</pos>
+<pos>$$normPath(::cwd::/Main.hx, true):2: characters 14-17</pos>
 </list>

+ 1 - 1
tests/misc/projects/Issue2997/compile1.hxml.stderr

@@ -1,3 +1,3 @@
 <list>
-<pos>$$normPath(::cwd::/Main.hx, true):2: characters 5-15</pos>
+<pos>$$normPath(::cwd::/Main.hx, true):2: characters 9-10</pos>
 </list>