Browse Source

[parser] deal with `Type<|` completion

closes #8007
Simon Krajewski 6 years ago
parent
commit
c406230a3a
2 changed files with 34 additions and 3 deletions
  1. 11 3
      src/syntax/grammar.mly
  2. 23 0
      tests/display/src/cases/Issue8007.hx

+ 11 - 3
src/syntax/grammar.mly

@@ -589,7 +589,7 @@ and parse_type_path2 p0 pack name p1 s =
 			| [< >] -> None,p1
 			| [< >] -> None,p1
 		) in
 		) in
 		let params,p2 = (match s with parser
 		let params,p2 = (match s with parser
-			| [< '(Binop OpLt,_); l = psep Comma parse_type_path_or_const >] ->
+			| [< '(Binop OpLt,plt); l = psep Comma (parse_type_path_or_const plt) >] ->
 				begin match s with parser
 				begin match s with parser
 				| [<'(Binop OpGt,p2) >] -> l,p2
 				| [<'(Binop OpGt,p2) >] -> l,p2
 				| [< >] ->
 				| [< >] ->
@@ -612,7 +612,7 @@ and type_name = parser
 			name,p
 			name,p
 	| [< '(Dollar name,p) >] -> "$" ^ name,p
 	| [< '(Dollar name,p) >] -> "$" ^ name,p
 
 
-and parse_type_path_or_const = parser
+and parse_type_path_or_const plt = parser
 	(* we can't allow (expr) here *)
 	(* we can't allow (expr) here *)
 	| [< '(BkOpen,p1); e = parse_array_decl p1 >] -> TPExpr (e)
 	| [< '(BkOpen,p1); e = parse_array_decl p1 >] -> TPExpr (e)
 	| [< t = parse_complex_type >] -> TPType t
 	| [< t = parse_complex_type >] -> TPType t
@@ -620,7 +620,15 @@ and parse_type_path_or_const = parser
 	| [< '(Kwd True,p) >] -> TPExpr (EConst (Ident "true"),p)
 	| [< '(Kwd True,p) >] -> TPExpr (EConst (Ident "true"),p)
 	| [< '(Kwd False,p) >] -> TPExpr (EConst (Ident "false"),p)
 	| [< '(Kwd False,p) >] -> TPExpr (EConst (Ident "false"),p)
 	| [< e = expr >] -> TPExpr e
 	| [< e = expr >] -> TPExpr e
-	| [< >] -> if !in_display_file then raise Stream.Failure else serror()
+	| [< s >] ->
+		if !in_display_file then begin
+			if would_skip_display_position plt s then begin
+				let ct = CTPath magic_type_path in
+				TPType (ct,plt)
+			end else
+				raise Stream.Failure
+		end else
+			serror()
 
 
 and parse_complex_type_next (t : type_hint) s =
 and parse_complex_type_next (t : type_hint) s =
 	let make_fun t2 p2 = match t2 with
 	let make_fun t2 p2 = match t2 with

+ 23 - 0
tests/display/src/cases/Issue8007.hx

@@ -0,0 +1,23 @@
+package cases;
+
+class Issue8007 extends DisplayTestCase {
+	/**
+		var i:Null<{-1-}>
+	**/
+	@:funcCode
+	function test1() {
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
+	/**
+		var i:Null<{-1-}
+	**/
+	@:funcCode
+	function test2() {
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+}