浏览代码

[parser] allow `function` as package name

see #7697
Aleksandr Kuzmenko 5 年之前
父节点
当前提交
e8901d53b1

+ 1 - 0
extra/CHANGES.txt

@@ -6,6 +6,7 @@
 	all : fixed display/references completion server request for static fields (#9440)
 	all : fixed "Module not found" error reporting during macro execution in display requests (#9449)
 	all : fixed module name completion for target-specific modules like `Mod.js.hx` (#9423)
+	all : fixed completion for packages named "function" (#7697)
 	cpp : fixed StringTools.endsWith() for unicode characters (#8980)
 	js/cpp : fixed catch var naming collision (#9413)
 	interp : fixed throwing `haxe.macro.Error` outside of a macro context (#9390)

+ 7 - 0
src/syntax/grammar.mly

@@ -67,11 +67,13 @@ let dollar_ident_macro pack = parser
 	| [< '(Dollar i,p) >] -> ("$" ^ i),p
 	| [< '(Kwd Macro,p) when pack <> [] >] -> "macro", p
 	| [< '(Kwd Extern,p) when pack <> [] >] -> "extern", p
+	| [< '(Kwd Function,p) when pack <> [] >] -> "function", p
 
 let lower_ident_or_macro = parser
 	| [< '(Const (Ident i),p) when is_lower_ident i >] -> i
 	| [< '(Kwd Macro,_) >] -> "macro"
 	| [< '(Kwd Extern,_) >] -> "extern"
+	| [< '(Kwd Function,_) >] -> "function"
 
 let property_ident = parser
 	| [< i,p = ident >] -> i,p
@@ -279,6 +281,8 @@ and parse_import s p1 =
 				loop pn (("macro",p) :: acc)
 			| [< '(Kwd Extern,p) >] ->
 				loop pn (("extern",p) :: acc)
+			| [< '(Kwd Function,p) >] ->
+				loop pn (("function",p) :: acc)
 			| [< '(Binop OpMult,_); '(Semicolon,p2) >] ->
 				p2, List.rev acc, IAll
 			| [< >] ->
@@ -316,6 +320,8 @@ and parse_using s p1 =
 				loop pn (("macro",p) :: acc)
 			| [< '(Kwd Extern,p) >] ->
 				loop pn (("extern",p) :: acc)
+			| [< '(Kwd Function,p) >] ->
+				loop pn (("function",p) :: acc)
 			| [< >] ->
 				syntax_error (Expected ["identifier"]) s (p,List.rev acc);
 			end
@@ -1415,6 +1421,7 @@ and parse_field e1 p s =
 		begin match s with parser
 		| [< '(Kwd Macro,p2) when p.pmax = p2.pmin; s >] -> expr_next (EField (e1,"macro") , punion (pos e1) p2) s
 		| [< '(Kwd Extern,p2) when p.pmax = p2.pmin; s >] -> expr_next (EField (e1,"extern") , punion (pos e1) p2) s
+		| [< '(Kwd Function,p2) when p.pmax = p2.pmin; s >] -> expr_next (EField (e1,"function") , punion (pos e1) p2) s
 		| [< '(Kwd New,p2) when p.pmax = p2.pmin; s >] -> expr_next (EField (e1,"new") , punion (pos e1) p2) s
 		| [< '(Kwd k,p2) when !parsing_macro_cond && p.pmax = p2.pmin; s >] -> expr_next (EField (e1,s_keyword k) , punion (pos e1) p2) s
 		| [< '(Const (Ident f),p2) when p.pmax = p2.pmin; s >] -> expr_next (EField (e1,f) , punion (pos e1) p2) s

+ 22 - 0
tests/server/src/cases/display/issues/Issue7697.hx

@@ -0,0 +1,22 @@
+package cases.display.issues;
+
+class Issue7697 extends DisplayTestCase {
+	/**
+		import data.function.{-1-}
+
+		class Main {
+			function main() {}
+		}
+	**/
+	function test(_) {
+		vfs.putContent("data/function/Test.hx", getTemplate("issues/Issue7697/data/function/Test.hx"));
+		runHaxeJson([], DisplayMethods.Completion, {
+			file: file,
+			offset: offset(1),
+			wasAutoTriggered: true
+		});
+		var result = parseCompletion().result;
+		Assert.equals(1, result.items.length);
+		Assert.equals('Test', result.items[0].args.path.moduleName);
+	}
+}

+ 3 - 0
tests/server/test/templates/issues/Issue7697/data/function/Test.hx

@@ -0,0 +1,3 @@
+package data.function;
+
+class Test {}