Browse Source

[parser] fix state handling when inline-parsing

Simon Krajewski 7 years ago
parent
commit
156ed43653
2 changed files with 12 additions and 5 deletions
  1. 2 2
      src/syntax/grammar.mly
  2. 10 3
      src/syntax/parserEntry.ml

+ 2 - 2
src/syntax/grammar.mly

@@ -179,7 +179,7 @@ and parse_type_decl s =
 		| [< n , p1 = parse_class_flags; name = type_name; tl = parse_constraint_params >] ->
 		| [< n , p1 = parse_class_flags; name = type_name; tl = parse_constraint_params >] ->
 			let rec loop had_display p0 acc =
 			let rec loop had_display p0 acc =
 				let check_display p0 p1 =
 				let check_display p0 p1 =
-					if not had_display && encloses_display_position p1 then syntax_completion (if List.mem HInterface n then SCInterfaceRelation else SCClassRelation) p0
+					if not had_display && !in_display_file && encloses_display_position p1 then syntax_completion (if List.mem HInterface n then SCInterfaceRelation else SCClassRelation) p0
 				in
 				in
 				match s with parser
 				match s with parser
 				| [< '(Kwd Extends,p1); t,b = parse_type_path_or_resume p1 >] ->
 				| [< '(Kwd Extends,p1); t,b = parse_type_path_or_resume p1 >] ->
@@ -823,7 +823,7 @@ and parse_constraint_param = parser
 and parse_type_path_or_resume p1 s =
 and parse_type_path_or_resume p1 s =
 	let pnext = next_pos s in
 	let pnext = next_pos s in
 	let check_resume exc =
 	let check_resume exc =
-		if encloses_display_position (punion p1 pnext) then
+		if !in_display_file && encloses_display_position (punion p1 pnext) then
 			(magic_type_path,punion_next p1 s),true
 			(magic_type_path,punion_next p1 s),true
 		else
 		else
 			raise exc
 			raise exc

+ 10 - 3
src/syntax/parserEntry.ml

@@ -105,7 +105,7 @@ let parse ctx code file =
 			end;
 			end;
 			tk
 			tk
 		| CommentLine s ->
 		| CommentLine s ->
-			if encloses_display_position (pos tk) then syntax_completion SCComment (pos tk);
+			if !in_display_file && encloses_display_position (pos tk) then syntax_completion SCComment (pos tk);
 			next_token()
 			next_token()
 		| Sharp "end" ->
 		| Sharp "end" ->
 			(match !mstack with
 			(match !mstack with
@@ -193,17 +193,24 @@ let parse_string com s p error inlined =
 	let old_file = (try Some (Hashtbl.find Lexer.all_files p.pfile) with Not_found -> None) in
 	let old_file = (try Some (Hashtbl.find Lexer.all_files p.pfile) with Not_found -> None) in
 	let old_display = !display_position in
 	let old_display = !display_position in
 	let old_de = !display_error in
 	let old_de = !display_error in
+	let old_in_display_file = !in_display_file in
 	let restore() =
 	let restore() =
 		(match old_file with
 		(match old_file with
 		| None -> ()
 		| None -> ()
 		| Some f -> Hashtbl.replace Lexer.all_files p.pfile f);
 		| Some f -> Hashtbl.replace Lexer.all_files p.pfile f);
-		if not inlined then display_position := old_display;
+		if not inlined then begin
+			display_position := old_display;
+			in_display_file := old_in_display_file;
+		end;
 		Lexer.restore old;
 		Lexer.restore old;
 		display_error := old_de
 		display_error := old_de
 	in
 	in
 	Lexer.init p.pfile true;
 	Lexer.init p.pfile true;
 	display_error := (fun e p -> raise (Error (e,p)));
 	display_error := (fun e p -> raise (Error (e,p)));
-	if not inlined then display_position := null_pos;
+	if not inlined then begin
+		display_position := null_pos;
+		in_display_file := false;
+	end;
 	let pack, decls = try
 	let pack, decls = try
 		parse com (Sedlexing.Utf8.from_string s) p.pfile
 		parse com (Sedlexing.Utf8.from_string s) p.pfile
 	with Error (e,pe) ->
 	with Error (e,pe) ->