Skip to content

Commit

Permalink
[display] Config to disable populating cache from display requests (H…
Browse files Browse the repository at this point in the history
…axeFoundation#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)
  • Loading branch information
kLabz committed Jul 7, 2023
1 parent c373d36 commit 9a7a1d3
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/compiler/displayProcessing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/serverCompilationContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/serverConfig.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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 changes: 6 additions & 0 deletions src/context/display/displayJson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
4 changes: 4 additions & 0 deletions src/core/displayTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions std/haxe/display/Server.hx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef ConfigurePrintParams = {

typedef ConfigureParams = {
final ?noModuleChecks:Bool;
final ?populateCacheFromDisplay:Bool;
final ?legacyCompletion:Bool;
final ?print:ConfigurePrintParams;
}
Expand Down
31 changes: 31 additions & 0 deletions tests/server/src/cases/issues/Issue11177.hx
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions tests/server/src/cases/issues/Issue11184.hx
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions tests/server/test/templates/issues/Issue11177/Buttons.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Buttons {
public static function init(main:Main):Void {
// Recursive inline is not supported
trace(KeyCode.Backspace);
}
}
3 changes: 3 additions & 0 deletions tests/server/test/templates/issues/Issue11177/KeyCode.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enum abstract KeyCode(Int) {
var Backspace = 8;
}
5 changes: 5 additions & 0 deletions tests/server/test/templates/issues/Issue11177/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Main {
static function main():Void {
trace("change this line");
}
}
5 changes: 5 additions & 0 deletions tests/server/test/templates/issues/Issue11177/Main2.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Main {
static function main():Void {
trace("change this trace");
}
}
7 changes: 7 additions & 0 deletions tests/server/test/templates/issues/Issue11184/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Main {
static function main() {
function foo():Void {}
final arr = [foo()];
}
}

0 comments on commit 9a7a1d3

Please sign in to comment.