Browse Source

[display] Config to disable populating cache from display requests (#11224)

* Add compilation server config to disable populating cache from display requests

* [tests] Add test for 11177 (including a disabled one for now)

* [tests] Add test for 11184 (including a disabled one for now)
Rudy Ges 2 years ago
parent
commit
29a42ba6b8

+ 1 - 1
src/compiler/displayProcessing.ml

@@ -48,7 +48,7 @@ let handle_display_argument_old com file_pos actx =
 			| "diagnostics" ->
 			| "diagnostics" ->
 				com.report_mode <- RMDiagnostics [file_unique];
 				com.report_mode <- RMDiagnostics [file_unique];
 				let dm = create DMNone in
 				let dm = create DMNone in
-				{dm with dms_display_file_policy = DFPAlso; dms_per_file = true}
+				{dm with dms_display_file_policy = DFPAlso; dms_per_file = true; dms_populate_cache = !ServerConfig.populate_cache_from_display}
 			| "statistics" ->
 			| "statistics" ->
 				com.report_mode <- RMStatistics;
 				com.report_mode <- RMStatistics;
 				let dm = create DMNone in
 				let dm = create DMNone in

+ 1 - 1
src/compiler/serverCompilationContext.ml

@@ -58,7 +58,7 @@ let reset sctx =
 	Helper.start_time := get_time()
 	Helper.start_time := get_time()
 
 
 let maybe_cache_context sctx com =
 let maybe_cache_context sctx com =
-	if com.display.dms_full_typing then begin
+	if com.display.dms_full_typing && com.display.dms_populate_cache then begin
 		CommonCache.cache_context sctx.cs com;
 		CommonCache.cache_context sctx.cs com;
 		ServerMessage.cached_modules com "" (List.length com.modules);
 		ServerMessage.cached_modules com "" (List.length com.modules);
 	end
 	end

+ 2 - 1
src/compiler/serverConfig.ml

@@ -1,2 +1,3 @@
 let do_not_check_modules = ref false
 let do_not_check_modules = ref false
-let legacy_completion = ref false
+let populate_cache_from_display = ref true
+let legacy_completion = ref false

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

@@ -297,6 +297,12 @@ let handler =
 				l := jstring ("Legacy completion " ^ (if b then "enabled" else "disabled")) :: !l;
 				l := jstring ("Legacy completion " ^ (if b then "enabled" else "disabled")) :: !l;
 				()
 				()
 			) ();
 			) ();
+			hctx.jsonrpc#get_opt_param (fun () ->
+				let b = hctx.jsonrpc#get_bool_param "populateCacheFromDisplay" in
+				ServerConfig.populate_cache_from_display := b;
+				l := jstring ("Compilation cache refill from display " ^ (if b then "enabled" else "disabled")) :: !l;
+				()
+			) ();
 			hctx.send_result (jarray !l)
 			hctx.send_result (jarray !l)
 		);
 		);
 		"server/memory",(fun hctx ->
 		"server/memory",(fun hctx ->

+ 4 - 0
src/core/displayTypes.ml

@@ -198,6 +198,7 @@ module DisplayMode = struct
 		dms_inline : bool;
 		dms_inline : bool;
 		dms_display_file_policy : display_file_policy;
 		dms_display_file_policy : display_file_policy;
 		dms_exit_during_typing : bool;
 		dms_exit_during_typing : bool;
+		dms_populate_cache : bool;
 		dms_per_file : bool;
 		dms_per_file : bool;
 	}
 	}
 
 
@@ -210,6 +211,7 @@ module DisplayMode = struct
 		dms_inline = false;
 		dms_inline = false;
 		dms_display_file_policy = DFPOnly;
 		dms_display_file_policy = DFPOnly;
 		dms_exit_during_typing = true;
 		dms_exit_during_typing = true;
+		dms_populate_cache = false;
 		dms_per_file = false;
 		dms_per_file = false;
 	}
 	}
 
 
@@ -222,6 +224,7 @@ module DisplayMode = struct
 		dms_inline = true;
 		dms_inline = true;
 		dms_display_file_policy = DFPNo;
 		dms_display_file_policy = DFPNo;
 		dms_exit_during_typing = false;
 		dms_exit_during_typing = false;
+		dms_populate_cache = true;
 		dms_per_file = false;
 		dms_per_file = false;
 	}
 	}
 
 
@@ -232,6 +235,7 @@ module DisplayMode = struct
 		| DMDefault | DMDefinition | DMTypeDefinition | DMPackage | DMHover | DMSignature -> settings
 		| DMDefault | DMDefinition | DMTypeDefinition | DMPackage | DMHover | DMSignature -> settings
 		| DMUsage _ | DMImplementation -> { settings with
 		| DMUsage _ | DMImplementation -> { settings with
 				dms_full_typing = true;
 				dms_full_typing = true;
+				dms_populate_cache = !ServerConfig.populate_cache_from_display;
 				dms_force_macro_typing = true;
 				dms_force_macro_typing = true;
 				dms_display_file_policy = DFPAlso;
 				dms_display_file_policy = DFPAlso;
 				dms_exit_during_typing = false
 				dms_exit_during_typing = false

+ 1 - 0
std/haxe/display/Server.hx

@@ -73,6 +73,7 @@ typedef ConfigurePrintParams = {
 
 
 typedef ConfigureParams = {
 typedef ConfigureParams = {
 	final ?noModuleChecks:Bool;
 	final ?noModuleChecks:Bool;
+	final ?populateCacheFromDisplay:Bool;
 	final ?legacyCompletion:Bool;
 	final ?legacyCompletion:Bool;
 	final ?print:ConfigurePrintParams;
 	final ?print:ConfigurePrintParams;
 }
 }

+ 31 - 0
tests/server/src/cases/issues/Issue11177.hx

@@ -0,0 +1,31 @@
+package cases.issues;
+
+class Issue11177 extends TestCase {
+	// Disabled for now until #11177 is actually fixed, likely by #11220
+	// function test(_) {
+	// 	vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main.hx"));
+	// 	vfs.putContent("Buttons.hx", getTemplate("issues/Issue11177/Buttons.hx"));
+	// 	vfs.putContent("KeyCode.hx", getTemplate("issues/Issue11177/KeyCode.hx"));
+	// 	var args = ["-main", "Main", "--interp"];
+	// 	runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"]));
+	// 	vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main2.hx"));
+	// 	runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")});
+	// 	runHaxe(args);
+	// 	runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"]));
+	// 	Assert.isTrue(lastResult.stderr.length == 2);
+	// }
+
+	function testWithoutCacheFromDisplay(_) {
+		vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main.hx"));
+		vfs.putContent("Buttons.hx", getTemplate("issues/Issue11177/Buttons.hx"));
+		vfs.putContent("KeyCode.hx", getTemplate("issues/Issue11177/KeyCode.hx"));
+		var args = ["-main", "Main", "--interp"];
+		runHaxeJson([], ServerMethods.Configure, {populateCacheFromDisplay: false});
+		runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"]));
+		vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main2.hx"));
+		runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")});
+		runHaxe(args);
+		runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"]));
+		Assert.isTrue(lastResult.stderr.length == 2);
+	}
+}

+ 25 - 0
tests/server/src/cases/issues/Issue11184.hx

@@ -0,0 +1,25 @@
+package cases.issues;
+
+class Issue11184 extends TestCase {
+	// Disabled for now until #11184 is actually fixed, likely by #11220
+	// function test(_) {
+	// 	vfs.putContent("Main.hx", getTemplate("issues/Issue11184/Main.hx"));
+	// 	var args = ["-main", "Main", "-js", "bin/test.js"];
+	// 	runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"]));
+	// 	runHaxe(args);
+	// 	Assert.isTrue(hasErrorMessage("Cannot use Void as value"));
+	// 	runHaxe(args);
+	// 	Assert.isTrue(hasErrorMessage("Cannot use Void as value"));
+	// }
+
+	function testWithoutCacheFromDisplay(_) {
+		vfs.putContent("Main.hx", getTemplate("issues/Issue11184/Main.hx"));
+		var args = ["-main", "Main", "-js", "bin/test.js"];
+		runHaxeJson([], ServerMethods.Configure, {populateCacheFromDisplay: false});
+		runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"]));
+		runHaxe(args);
+		Assert.isTrue(hasErrorMessage("Cannot use Void as value"));
+		runHaxe(args);
+		Assert.isTrue(hasErrorMessage("Cannot use Void as value"));
+	}
+}

+ 6 - 0
tests/server/test/templates/issues/Issue11177/Buttons.hx

@@ -0,0 +1,6 @@
+class Buttons {
+	public static function init(main:Main):Void {
+		// Recursive inline is not supported
+		trace(KeyCode.Backspace);
+	}
+}

+ 3 - 0
tests/server/test/templates/issues/Issue11177/KeyCode.hx

@@ -0,0 +1,3 @@
+enum abstract KeyCode(Int) {
+	var Backspace = 8;
+}

+ 5 - 0
tests/server/test/templates/issues/Issue11177/Main.hx

@@ -0,0 +1,5 @@
+class Main {
+	static function main():Void {
+		trace("change this line");
+	}
+}

+ 5 - 0
tests/server/test/templates/issues/Issue11177/Main2.hx

@@ -0,0 +1,5 @@
+class Main {
+	static function main():Void {
+		trace("change this trace");
+	}
+}

+ 7 - 0
tests/server/test/templates/issues/Issue11184/Main.hx

@@ -0,0 +1,7 @@
+class Main {
+	static function main() {
+		function foo():Void {}
+		final arr = [foo()];
+	}
+}
+