Browse Source

[server] move ServerCompilationContext to its own module

also flush pipes when sending JSON results which hopefully stabilizes some tests
Simon Krajewski 3 years ago
parent
commit
ad1a393bb9

+ 0 - 72
src/compiler/server.ml

@@ -83,78 +83,6 @@ let parse_file cs com file p =
 		) () in
 		) () in
 		data
 		data
 
 
-module ServerCompilationContext = struct
-	type t = {
-		(* If true, prints some debug information *)
-		verbose : bool;
-		(* The list of changed directories per-signature *)
-		changed_directories : (Digest.t,cached_directory list) Hashtbl.t;
-		(* A reference to the compilation server instance *)
-		cs : CompilationCache.t;
-		(* A list of class paths per-signature *)
-		class_paths : (Digest.t,string list) Hashtbl.t;
-		(* Increased for each compilation *)
-		mutable compilation_step : int;
-		(* A list of delays which are run after compilation *)
-		mutable delays : (unit -> unit) list;
-		(* True if it's an actual compilation, false if it's a display operation *)
-		mutable was_compilation : bool;
-		(* True if the macro context has been set up *)
-		mutable macro_context_setup : bool;
-	}
-
-	let create verbose = {
-		verbose = verbose;
-		cs = new CompilationCache.cache;
-		class_paths = Hashtbl.create 0;
-		changed_directories = Hashtbl.create 0;
-		compilation_step = 0;
-		delays = [];
-		was_compilation = false;
-		macro_context_setup = false;
-	}
-
-	let add_delay sctx f =
-		sctx.delays <- f :: sctx.delays
-
-	let run_delays sctx =
-		let fl = sctx.delays in
-		sctx.delays <- [];
-		List.iter (fun f -> f()) fl
-
-	(* Resets the state for a new compilation *)
-	let reset sctx =
-		Hashtbl.clear sctx.changed_directories;
-		sctx.was_compilation <- false;
-		Parser.reset_state();
-		return_partial_type := false;
-		measure_times := false;
-		Hashtbl.clear DeprecationCheck.warned_positions;
-		close_times();
-		stats.s_files_parsed := 0;
-		stats.s_classes_built := 0;
-		stats.s_methods_typed := 0;
-		stats.s_macros_called := 0;
-		Hashtbl.clear Timer.htimers;
-		Helper.start_time := get_time()
-
-	let maybe_cache_context sctx com =
-		if com.display.dms_full_typing then begin
-			CommonCache.cache_context sctx.cs com;
-			ServerMessage.cached_modules com "" (List.length com.modules);
-		end
-
-	let ensure_macro_setup sctx =
-		if not sctx.macro_context_setup then begin
-			sctx.macro_context_setup <- true;
-			MacroContext.setup();
-		end
-
-	let cleanup () = match !MacroContext.macro_interp_cache with
-		| Some interp -> EvalContext.GlobalState.cleanup interp
-		| None -> ()
-end
-
 open ServerCompilationContext
 open ServerCompilationContext
 
 
 module Communication = struct
 module Communication = struct

+ 74 - 0
src/compiler/serverCompilationContext.ml

@@ -0,0 +1,74 @@
+open Globals
+open Common
+open Timer
+open CompilationCache
+
+type t = {
+	(* If true, prints some debug information *)
+	verbose : bool;
+	(* The list of changed directories per-signature *)
+	changed_directories : (Digest.t,cached_directory list) Hashtbl.t;
+	(* A reference to the compilation server instance *)
+	cs : CompilationCache.t;
+	(* A list of class paths per-signature *)
+	class_paths : (Digest.t,string list) Hashtbl.t;
+	(* Increased for each compilation *)
+	mutable compilation_step : int;
+	(* A list of delays which are run after compilation *)
+	mutable delays : (unit -> unit) list;
+	(* True if it's an actual compilation, false if it's a display operation *)
+	mutable was_compilation : bool;
+	(* True if the macro context has been set up *)
+	mutable macro_context_setup : bool;
+}
+
+let create verbose = {
+	verbose = verbose;
+	cs = new CompilationCache.cache;
+	class_paths = Hashtbl.create 0;
+	changed_directories = Hashtbl.create 0;
+	compilation_step = 0;
+	delays = [];
+	was_compilation = false;
+	macro_context_setup = false;
+}
+
+let add_delay sctx f =
+	sctx.delays <- f :: sctx.delays
+
+let run_delays sctx =
+	let fl = sctx.delays in
+	sctx.delays <- [];
+	List.iter (fun f -> f()) fl
+
+(* Resets the state for a new compilation *)
+let reset sctx =
+	Hashtbl.clear sctx.changed_directories;
+	sctx.was_compilation <- false;
+	Parser.reset_state();
+	return_partial_type := false;
+	measure_times := false;
+	Hashtbl.clear DeprecationCheck.warned_positions;
+	close_times();
+	stats.s_files_parsed := 0;
+	stats.s_classes_built := 0;
+	stats.s_methods_typed := 0;
+	stats.s_macros_called := 0;
+	Hashtbl.clear Timer.htimers;
+	Helper.start_time := get_time()
+
+let maybe_cache_context sctx com =
+	if com.display.dms_full_typing then begin
+		CommonCache.cache_context sctx.cs com;
+		ServerMessage.cached_modules com "" (List.length com.modules);
+	end
+
+let ensure_macro_setup sctx =
+	if not sctx.macro_context_setup then begin
+		sctx.macro_context_setup <- true;
+		MacroContext.setup();
+	end
+
+let cleanup () = match !MacroContext.macro_interp_cache with
+	| Some interp -> EvalContext.GlobalState.cleanup interp
+	| None -> ()

+ 2 - 0
src/context/display/displayJson.ml

@@ -308,6 +308,8 @@ let parse_input com input report_times =
 	let jsonrpc = new jsonrpc_handler input in
 	let jsonrpc = new jsonrpc_handler input in
 
 
 	let send_result json =
 	let send_result json =
+		flush stdout;
+		flush stderr;
 		let fl = [
 		let fl = [
 			"result",json;
 			"result",json;
 			"timestamp",jfloat (Unix.gettimeofday ());
 			"timestamp",jfloat (Unix.gettimeofday ());