浏览代码

separate usage and position completion (closes #5123)

Simon Krajewski 9 年之前
父节点
当前提交
9ca0876823

+ 0 - 4
src/generators/codegen.ml

@@ -486,10 +486,6 @@ let detect_usage com =
 					Type.iter expr e
 				| TLocal v when Meta.has Meta.Usage v.v_meta ->
 					usage := e.epos :: !usage
-				| TVar (v,_) when com.display = DMPosition && Meta.has Meta.Usage v.v_meta ->
-					raise (Typecore.DisplayPosition [e.epos])
-				| TFunction tf when com.display = DMPosition && List.exists (fun (v,_) -> Meta.has Meta.Usage v.v_meta) tf.tf_args ->
-					raise (Typecore.DisplayPosition [e.epos])
 				| TTypeExpr mt when (Meta.has Meta.Usage (t_infos mt).mt_meta) ->
 					usage := e.epos :: !usage
 				| TNew (c,_,_) ->

+ 1 - 1
src/optimization/filters.ml

@@ -1026,7 +1026,7 @@ let iter_expressions fl mt =
 
 let run com tctx main =
 	begin match com.display with
-		| DMUsage | DMPosition -> Codegen.detect_usage com;
+		| DMUsage -> Codegen.detect_usage com;
 		| _ -> ()
 	end;
 	if not (Common.defined com Define.NoDeprecationWarnings) then

+ 20 - 12
src/typing/typer.ml

@@ -3765,35 +3765,26 @@ and handle_display ctx e_ast iscall with_type p =
 		| _ -> e
 	in
 	ctx.in_display <- old;
-	let handle_field cf =
-		if ctx.com.display = DMPosition then
-			raise (DisplayPosition [cf.cf_pos]);
-		cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
-	in
 	match ctx.com.display with
 	| DMResolve _ ->
 		assert false
 	| DMType ->
 		raise (DisplayTypes [match e.eexpr with TVar(v,_) -> v.v_type | _ -> e.etype])
-	| DMUsage | DMPosition ->
+	| DMUsage ->
 		begin match e.eexpr with
 		| TField(_,FEnum(_,ef)) ->
-			if ctx.com.display = DMPosition then
-				raise (DisplayPosition [ef.ef_pos]);
 			ef.ef_meta <- (Meta.Usage,[],p) :: ef.ef_meta;
 		| TField(_,(FAnon cf | FInstance (_,_,cf) | FStatic (_,cf) | FClosure (_,cf))) ->
-			handle_field cf;
+			cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
 		| TLocal v | TVar(v,_) ->
 			v.v_meta <- (Meta.Usage,[],p) :: v.v_meta;
 		| TTypeExpr mt ->
 			let ti = t_infos mt in
-			if ctx.com.display = DMPosition then
-				raise (DisplayPosition [ti.mt_pos]);
 			ti.mt_meta <- (Meta.Usage,[],p) :: ti.mt_meta;
 		| TNew(c,tl,_) ->
 			begin try
 				let _,cf = get_constructor ctx c tl p in
-				handle_field cf;
+				cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
 			with Not_found ->
 				()
 			end
@@ -3801,6 +3792,23 @@ and handle_display ctx e_ast iscall with_type p =
 			()
 		end;
 		e
+	| DMPosition ->
+		let pl = match e.eexpr with
+		| TField(_,FEnum(_,ef)) -> [ef.ef_pos]
+		| TField(_,(FAnon cf | FInstance (_,_,cf) | FStatic (_,cf) | FClosure (_,cf))) -> [cf.cf_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]
+			with Not_found ->
+				[]
+			end
+		| _ ->
+			[]
+		in
+		raise (DisplayPosition pl);
 	| DMToplevel ->
 		collect_toplevel_identifiers ctx;
 	| DMDefault | DMNone ->

+ 11 - 0
tests/misc/projects/Issue5123/Main.hx

@@ -0,0 +1,11 @@
+class Main {
+    static function main() {
+        var myShinyVar = 50;
+
+        function doBeautifulThings(who:String) {
+            return who.length;
+        }
+
+        doBeautifulThings(myShinyVar);
+    }
+}

+ 1 - 0
tests/misc/projects/Issue5123/compile.hxml

@@ -0,0 +1 @@
+--display Main.hx@180@position

+ 3 - 0
tests/misc/projects/Issue5123/compile.hxml.stderr

@@ -0,0 +1,3 @@
+<list>
+<pos>$$normPath(::cwd::/Main.hx):5: lines 5-7</pos>
+</list>