Browse Source

delayed syntax completion

Simon Krajewski 5 months ago
parent
commit
80c0eddf0c

+ 1 - 1
src/compiler/displayProcessing.ml

@@ -264,7 +264,7 @@ let maybe_load_display_file_before_typing tctx display_file_dot_path = match dis
 let handle_display_after_typing ctx tctx display_file_dot_path =
 	let com = ctx.com in
 	if ctx.com.display.dms_kind = DMNone && ctx.has_error then raise Abort;
-	begin match ctx.com.display.dms_kind,!Parser.delayed_syntax_completion with
+	begin match ctx.com.display.dms_kind,Atomic.get ctx.com.delayed_syntax_completion with
 		| DMDefault,Some(kind,subj) -> DisplayOutput.handle_syntax_completion com kind subj
 		| _ -> ()
 	end;

+ 3 - 0
src/context/common.ml

@@ -250,8 +250,10 @@ type context = {
 	main : Gctx.context_main;
 	mutable package_rules : (string,package_rule) PMap.t;
 	mutable report_mode : report_mode;
+	(* parser stuff to clean up later *)
 	mutable was_auto_triggered : bool;
 	mutable had_parser_resume : bool;
+	delayed_syntax_completion : Parser.syntax_completion_on option Atomic.t;
 	(* communication *)
 	mutable print : string -> unit;
 	mutable error : Gctx.error_function;
@@ -774,6 +776,7 @@ let create timer_ctx compilation_step cs version args display_mode =
 		hxb_writer_config = None;
 		was_auto_triggered = false;
 		had_parser_resume = false;
+		delayed_syntax_completion = Atomic.make None;
 	} in
 	com
 

+ 10 - 8
src/syntax/parser.ml

@@ -66,9 +66,11 @@ type 'a sequence_parsing_result =
 	| End of pos
 	| Error of string
 
+type syntax_completion_on = syntax_completion * DisplayTypes.completion_subject
+
 exception Error of error_msg * pos
 exception TypePath of string list * (string * bool) option * bool (* in import *) * pos
-exception SyntaxCompletion of syntax_completion * DisplayTypes.completion_subject
+exception SyntaxCompletion of syntax_completion_on
 
 type parser_config = {
 	defines : Define.define;
@@ -85,6 +87,7 @@ type parser_ctx = {
 	in_macro : bool;
 	code : Sedlexing.lexbuf;
 	mutable had_resume : bool;
+	delayed_syntax_completion : syntax_completion_on option ref;
 	config : parser_config;
 }
 
@@ -116,6 +119,7 @@ type parser_display_information = {
 	pd_conditions : expr list;
 	pd_was_display_file : bool;
 	pd_had_resume : bool;
+	pd_delayed_syntax_completion : syntax_completion_on option;
 }
 
 type 'a parse_result =
@@ -131,6 +135,7 @@ let create_context lexer_ctx config in_macro code = {
 	in_macro;
 	code;
 	had_resume = false;
+	delayed_syntax_completion = ref None;
 	config;
 }
 
@@ -188,11 +193,8 @@ let next_pos ctx s = pos (next_token ctx s)
 
 (* Global state *)
 
-let delayed_syntax_completion : (syntax_completion * DisplayTypes.completion_subject) option ref = ref None
-
 let reset_state () =
-	display_position#reset;
-	delayed_syntax_completion := None
+	display_position#reset
 
 let syntax_error_with_pos ctx error_msg p v =
 	let p = if p.pmax = max_int then {p with pmax = p.pmin + 1} else p in
@@ -273,8 +275,8 @@ let magic_type_ct p = make_ptp_ct magic_type_path p
 
 let magic_type_th p = magic_type_ct p,p
 
-let delay_syntax_completion kind so p =
-	delayed_syntax_completion := Some(kind,DisplayTypes.make_subject so p)
+let delay_syntax_completion ctx kind so p =
+	ctx.delayed_syntax_completion := Some(kind,DisplayTypes.make_subject so p)
 
 let type_path sl in_import p = match sl with
 	| n :: l when n.[0] >= 'A' && n.[0] <= 'Z' -> raise (TypePath (List.rev l,Some (n,false),in_import,p));
@@ -443,7 +445,7 @@ let check_type_decl_completion ctx mode pmax s =
 			| Some(e,p) -> None,p
 			| _ -> None,p
 			in
-			delay_syntax_completion (SCTypeDecl mode) so p
+			delay_syntax_completion ctx (SCTypeDecl mode) so p
 		end
 	end
 

+ 1 - 0
src/syntax/parserEntry.ml

@@ -360,6 +360,7 @@ let parse config entry lctx code file =
 			pd_conditions = conds#get_conditions;
 			pd_was_display_file = was_display_file;
 			pd_had_resume = ctx.had_resume;
+			pd_delayed_syntax_completion = !(ctx.delayed_syntax_completion);
 		} in
 		if was_display_file then
 			ParseSuccess(l,pdi)

+ 4 - 2
src/typing/typeloadParse.ml

@@ -45,8 +45,10 @@ let parse_file_from_lexbuf com file p lexbuf =
 		| DMModuleSymbols filter,(ParseSuccess(data,_)) when filter = None && DisplayPosition.display_position#is_in_file (com.file_keys#get file) ->
 			let ds = DocumentSymbols.collect_module_symbols None (filter = None) data in
 			DisplayException.raise_module_symbols (DocumentSymbols.Printer.print_module_symbols com [file,ds] filter);
-		| _,ParseSuccess(_,{pd_had_resume = true}) ->
-			com.had_parser_resume <- true
+		| _,ParseSuccess(_,({pd_was_display_file = true} as pdi)) ->
+			if pdi.pd_had_resume then
+				com.had_parser_resume <- true;
+			Atomic.set com.delayed_syntax_completion pdi.pd_delayed_syntax_completion
 		| _ ->
 			()
 	end;