Jelajahi Sumber

[parser] don't trigger comment completion at file start

closes #10322
Simon Krajewski 4 tahun lalu
induk
melakukan
1d5f076d88
2 mengubah file dengan 10 tambahan dan 4 penghapusan
  1. 2 1
      src/syntax/parserEntry.ml
  2. 8 3
      tests/display/src/cases/DocumentSymbols.hx

+ 2 - 1
src/syntax/parserEntry.ml

@@ -252,7 +252,8 @@ let parse entry ctx code file =
 				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);
+				(* The > 0 check is to deal with the special case of line comments at the beginning of the file (issue #10322) *)
+				if display_position#enclosed_in p && p.pmin > 0 then syntax_completion SCComment None (pos tk);
 			end;
 			next_token()
 		| Sharp "end" ->

+ 8 - 3
tests/display/src/cases/DocumentSymbols.hx

@@ -120,9 +120,14 @@ class DocumentSymbols extends DisplayTestCase {
 		function main() {}
 	**/
 	function testModuleLevelFields() {
-		checkDocumentSymbols([
-			{name: "main", kind: Method, containerName: null},
-		], ctx.documentSymbols());
+		checkDocumentSymbols([{name: "main", kind: Method, containerName: null},], ctx.documentSymbols());
+	}
+
+	/*// Test
+		function main() {}
+	 */
+	function testLeadingLineComment() {
+		checkDocumentSymbols([{name: "main", kind: Method, containerName: null},], ctx.documentSymbols());
 	}
 
 	function checkDocumentSymbols(expected:Array<ModuleSymbolEntry>, actual:Array<ModuleSymbolEntry>, ?pos:haxe.PosInfos) {