From 6a554bfb34cb5f6bb3029835a0e630a6e8d1e119 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Mon, 15 May 2023 19:43:41 +0200 Subject: [PATCH] [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) --- src/compiler/displayProcessing.ml | 2 +- src/compiler/serverCompilationContext.ml | 2 +- src/compiler/serverConfig.ml | 3 +- src/context/display/displayJson.ml | 6 ++++ src/core/displayTypes.ml | 4 +++ std/haxe/display/Server.hx | 1 + tests/server/src/cases/issues/Issue11177.hx | 31 +++++++++++++++++++ tests/server/src/cases/issues/Issue11184.hx | 25 +++++++++++++++ .../templates/issues/Issue11177/Buttons.hx | 6 ++++ .../templates/issues/Issue11177/KeyCode.hx | 3 ++ .../test/templates/issues/Issue11177/Main.hx | 5 +++ .../test/templates/issues/Issue11177/Main2.hx | 5 +++ .../test/templates/issues/Issue11184/Main.hx | 7 +++++ 13 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 tests/server/src/cases/issues/Issue11177.hx create mode 100644 tests/server/src/cases/issues/Issue11184.hx create mode 100644 tests/server/test/templates/issues/Issue11177/Buttons.hx create mode 100644 tests/server/test/templates/issues/Issue11177/KeyCode.hx create mode 100644 tests/server/test/templates/issues/Issue11177/Main.hx create mode 100644 tests/server/test/templates/issues/Issue11177/Main2.hx create mode 100644 tests/server/test/templates/issues/Issue11184/Main.hx diff --git a/src/compiler/displayProcessing.ml b/src/compiler/displayProcessing.ml index b709c875d93..e5876b1d54c 100644 --- a/src/compiler/displayProcessing.ml +++ b/src/compiler/displayProcessing.ml @@ -48,7 +48,7 @@ let handle_display_argument_old com file_pos actx = | "diagnostics" -> com.report_mode <- RMDiagnostics [file_unique]; 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" -> com.report_mode <- RMStatistics; let dm = create DMNone in diff --git a/src/compiler/serverCompilationContext.ml b/src/compiler/serverCompilationContext.ml index 95a567aa901..bec9724e4c3 100644 --- a/src/compiler/serverCompilationContext.ml +++ b/src/compiler/serverCompilationContext.ml @@ -58,7 +58,7 @@ let reset sctx = Helper.start_time := get_time() 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; ServerMessage.cached_modules com "" (List.length com.modules); end diff --git a/src/compiler/serverConfig.ml b/src/compiler/serverConfig.ml index ec7ba308e59..173637cb401 100644 --- a/src/compiler/serverConfig.ml +++ b/src/compiler/serverConfig.ml @@ -1,2 +1,3 @@ let do_not_check_modules = ref false -let legacy_completion = ref false \ No newline at end of file +let populate_cache_from_display = ref true +let legacy_completion = ref false diff --git a/src/context/display/displayJson.ml b/src/context/display/displayJson.ml index 87b1ee3f503..06a336c8aac 100644 --- a/src/context/display/displayJson.ml +++ b/src/context/display/displayJson.ml @@ -296,6 +296,12 @@ let handler = 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) ); "server/memory",(fun hctx -> diff --git a/src/core/displayTypes.ml b/src/core/displayTypes.ml index 8111464c72a..b6833b897b9 100644 --- a/src/core/displayTypes.ml +++ b/src/core/displayTypes.ml @@ -196,6 +196,7 @@ module DisplayMode = struct dms_inline : bool; dms_display_file_policy : display_file_policy; dms_exit_during_typing : bool; + dms_populate_cache : bool; dms_per_file : bool; } @@ -208,6 +209,7 @@ module DisplayMode = struct dms_inline = false; dms_display_file_policy = DFPOnly; dms_exit_during_typing = true; + dms_populate_cache = false; dms_per_file = false; } @@ -220,6 +222,7 @@ module DisplayMode = struct dms_inline = true; dms_display_file_policy = DFPNo; dms_exit_during_typing = false; + dms_populate_cache = true; dms_per_file = false; } @@ -230,6 +233,7 @@ module DisplayMode = struct | DMDefault | DMDefinition | DMTypeDefinition | DMPackage | DMHover | DMSignature -> settings | DMUsage _ | DMImplementation -> { settings with dms_full_typing = true; + dms_populate_cache = !ServerConfig.populate_cache_from_display; dms_force_macro_typing = true; dms_display_file_policy = DFPAlso; dms_exit_during_typing = false diff --git a/std/haxe/display/Server.hx b/std/haxe/display/Server.hx index 63895758cec..44ce700587e 100644 --- a/std/haxe/display/Server.hx +++ b/std/haxe/display/Server.hx @@ -73,6 +73,7 @@ typedef ConfigurePrintParams = { typedef ConfigureParams = { final ?noModuleChecks:Bool; + final ?populateCacheFromDisplay:Bool; final ?legacyCompletion:Bool; final ?print:ConfigurePrintParams; } diff --git a/tests/server/src/cases/issues/Issue11177.hx b/tests/server/src/cases/issues/Issue11177.hx new file mode 100644 index 00000000000..42aa7423082 --- /dev/null +++ b/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); + } +} diff --git a/tests/server/src/cases/issues/Issue11184.hx b/tests/server/src/cases/issues/Issue11184.hx new file mode 100644 index 00000000000..7f2d326d726 --- /dev/null +++ b/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")); + } +} diff --git a/tests/server/test/templates/issues/Issue11177/Buttons.hx b/tests/server/test/templates/issues/Issue11177/Buttons.hx new file mode 100644 index 00000000000..981215fa8e2 --- /dev/null +++ b/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); + } +} diff --git a/tests/server/test/templates/issues/Issue11177/KeyCode.hx b/tests/server/test/templates/issues/Issue11177/KeyCode.hx new file mode 100644 index 00000000000..d9e56743fc8 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11177/KeyCode.hx @@ -0,0 +1,3 @@ +enum abstract KeyCode(Int) { + var Backspace = 8; +} diff --git a/tests/server/test/templates/issues/Issue11177/Main.hx b/tests/server/test/templates/issues/Issue11177/Main.hx new file mode 100644 index 00000000000..50277c19e01 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11177/Main.hx @@ -0,0 +1,5 @@ +class Main { + static function main():Void { + trace("change this line"); + } +} diff --git a/tests/server/test/templates/issues/Issue11177/Main2.hx b/tests/server/test/templates/issues/Issue11177/Main2.hx new file mode 100644 index 00000000000..c3300795a09 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11177/Main2.hx @@ -0,0 +1,5 @@ +class Main { + static function main():Void { + trace("change this trace"); + } +} diff --git a/tests/server/test/templates/issues/Issue11184/Main.hx b/tests/server/test/templates/issues/Issue11184/Main.hx new file mode 100644 index 00000000000..c769638ee40 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11184/Main.hx @@ -0,0 +1,7 @@ +class Main { + static function main() { + function foo():Void {} + final arr = [foo()]; + } +} +