Browse Source

[parser] fix completion position right in front of comments

closes #9133
Simon Krajewski 5 years ago
parent
commit
564990938b
2 changed files with 18 additions and 1 deletions
  1. 6 1
      src/syntax/parserEntry.ml
  2. 12 0
      tests/display/src/cases/Issue9133.hx

+ 6 - 1
src/syntax/parserEntry.ml

@@ -248,7 +248,12 @@ let parse ctx code file =
 			if l > 0 && s.[0] = '*' then last_doc := Some (String.sub s 1 (l - (if l > 1 && s.[l-1] = '*' then 2 else 1)), (snd tk).pmin);
 			tk
 		| CommentLine s ->
-			if !in_display_file && display_position#enclosed_in (pos tk) then syntax_completion SCComment None (pos tk);
+			if !in_display_file then begin
+				let p = pos tk in
+				(* Completion at the / should not pick up the comment (issue #9133) *)
+				let p = if is_completion() then {p with pmin = p.pmin + 1} else p in
+				if display_position#enclosed_in p then syntax_completion SCComment None (pos tk);
+			end;
 			next_token()
 		| Sharp "end" ->
 			(match !mstack with

+ 12 - 0
tests/display/src/cases/Issue9133.hx

@@ -42,4 +42,16 @@ class Issue9133 extends DisplayTestCase {
 		Assert.isTrue(i1 < i2);
 		Assert.isTrue(i1 != -1);
 	}
+
+	/**
+		class Main {
+		static function main() {
+			var i = 0;
+			{-1-}// comment
+	**/
+	function test3() {
+		var fields = toplevel(pos(1));
+		var i1 = fields.findIndex(item -> item.kind == "local" && item.name == "i");
+		Assert.isTrue(i1 != -1);
+	}
 }