Browse Source

[display] don't mark EVars as display expression

closes #7320
Simon Krajewski 7 years ago
parent
commit
e92a887e2c
2 changed files with 69 additions and 5 deletions
  1. 6 5
      src/context/display/display.ml
  2. 63 0
      tests/display/src/cases/Issue7320.hx

+ 6 - 5
src/context/display/display.ml

@@ -20,13 +20,14 @@ module ExprPreprocessing = struct
 	let find_before_pos dm e =
 	let find_before_pos dm e =
 
 
 		let display_pos = ref (!DisplayPosition.display_position) in
 		let display_pos = ref (!DisplayPosition.display_position) in
+		let was_annotated = ref false in
 		let is_annotated,is_completion = match dm with
 		let is_annotated,is_completion = match dm with
-			| DMDefault -> (fun p -> encloses_position !display_pos p),true
-			| DMHover -> (fun p -> encloses_position_gt !display_pos p),false
-			| _ -> (fun p -> encloses_position !display_pos p),false
+			| DMDefault -> (fun p -> not !was_annotated && encloses_position !display_pos p),true
+			| DMHover -> (fun p -> not !was_annotated && encloses_position_gt !display_pos p),false
+			| _ -> (fun p -> not !was_annotated && encloses_position !display_pos p),false
 		in
 		in
 		let annotate e dk =
 		let annotate e dk =
-			display_pos := { pfile = ""; pmin = -2; pmax = -2 };
+			was_annotated := true;
 			(EDisplay(e,dk),pos e)
 			(EDisplay(e,dk),pos e)
 		in
 		in
 		let annotate_marked e = annotate e DKMarked in
 		let annotate_marked e = annotate e DKMarked in
@@ -86,7 +87,7 @@ module ExprPreprocessing = struct
 				in
 				in
 				let vl,mark = loop2 [] false vl in
 				let vl,mark = loop2 [] false vl in
 				let e = EVars (List.rev vl),pos e in
 				let e = EVars (List.rev vl),pos e in
-				if mark then annotate_marked e else e
+				if !was_annotated then e else raise Exit
 			| EBinop((OpAssign | OpAssignOp _) as op,e1,e2) when is_annotated (pos e) && is_completion ->
 			| EBinop((OpAssign | OpAssignOp _) as op,e1,e2) when is_annotated (pos e) && is_completion ->
 				(* Special case for assign ops: If the expression is marked, but none of its operands are,
 				(* Special case for assign ops: If the expression is marked, but none of its operands are,
 				   we are "probably" interested in the rhs. Like with EVars, this isn't accurate because we
 				   we are "probably" interested in the rhs. Like with EVars, this isn't accurate because we

+ 63 - 0
tests/display/src/cases/Issue7320.hx

@@ -0,0 +1,63 @@
+package cases;
+
+class Issue7320 extends DisplayTestCase {
+	/**
+	class Main {
+		static function main() {
+			var f{-1-}
+		}
+	}
+	**/
+	@:func
+	function test1() {
+		eq(true, noCompletionPoint(toplevel.bind((pos(1)))));
+	}
+
+	/**
+	class Main {
+		static function main() {
+			var f = {-1-}
+		}
+	}
+	**/
+	@:func
+	function test2() {
+		eq(true, hasToplevel(toplevel(pos(1)), "type", "Float"));
+	}
+
+	/**
+	class Main {
+		static function main() {
+			var f, l{-1-}
+		}
+	}
+	**/
+	@:func
+	function test3() {
+		eq(true, noCompletionPoint(toplevel.bind((pos(1)))));
+	}
+
+	/**
+	class Main {
+		static function main() {
+			var f = "foo", l{-1-}
+		}
+	}
+	**/
+	@:func
+	function test4() {
+		eq(true, noCompletionPoint(toplevel.bind((pos(1)))));
+	}
+
+	/**
+	class Main {
+		static function main() {
+			var f, l{-1-} = "foo"
+		}
+	}
+	**/
+	@:func
+	function test5() {
+		eq(true, noCompletionPoint(toplevel.bind((pos(1)))));
+	}
+}