Browse Source

[tests] Test Json RPC diagnostics with several open files (#11708)

* [tests] Test Json RPC diagnostics with several open files

* I knew windows wouldn't like that
Rudy Ges 1 year ago
parent
commit
a85fd3d530

+ 43 - 0
tests/server/src/cases/ServerTests.hx

@@ -1,5 +1,6 @@
 package cases;
 
+import haxe.display.Diagnostic;
 import haxe.display.Display;
 import haxe.display.FsPath;
 import haxe.display.Server;
@@ -274,6 +275,48 @@ class ServerTests extends TestCase {
 		assertReuse("HelloWorld");
 	}
 
+	function testDiagnosticsMultipleOpenFiles() {
+		vfs.putContent("Main.hx", getTemplate("diagnostics/multi-files/Main.hx"));
+		vfs.putContent("File1.hx", getTemplate("diagnostics/multi-files/File1.hx"));
+		vfs.putContent("File2.hx", getTemplate("diagnostics/multi-files/File2.hx"));
+		vfs.putContent("File3.hx", getTemplate("diagnostics/multi-files/File3.hx"));
+
+		var args = ["--main", "Main", "--interp"];
+		runHaxeJsonCb(args, DisplayMethods.Diagnostics, {fileContents: [
+			{file: new FsPath("Main.hx")},
+			{file: new FsPath("File1.hx")},
+			{file: new FsPath("File2.hx")},
+		]}, res -> {
+			Assert.equals(3, res.length); // Asked diagnostics for 3 files
+
+			for (fileDiagnostics in res) {
+				final path = ~/[\/|\\]/g.split(fileDiagnostics.file.toString()).pop();
+
+				switch (path) {
+					case "Main.hx":
+						Assert.equals(3, fileDiagnostics.diagnostics.length);
+						for (diag in fileDiagnostics.diagnostics) {
+							Assert.equals(diag.kind, DKUnusedImport);
+						}
+
+					case "File1.hx" | "File2.hx":
+						Assert.equals(1, fileDiagnostics.diagnostics.length);
+						var diag:Diagnostic<ReplaceableCodeDiagnostics> = fileDiagnostics.diagnostics[0];
+						Assert.equals(diag.kind, ReplaceableCode);
+						Assert.equals(diag.args.description, "Unused variable");
+
+					case _: throw 'Did not expect diagnostics for $path';
+				}
+			}
+		});
+
+		// Check that File3 was reached
+		var context = null;
+		runHaxeJsonCb(args, ServerMethods.Contexts, null, res -> context = res.find(ctx -> ctx.desc == "after_init_macros"));
+		runHaxeJsonCb(args, ServerMethods.Type, {signature: context.signature, modulePath: "File3", typeName: "File3"}, res -> Assert.equals(res.pos.file, "File3.hx"));
+		assertSuccess();
+	}
+
 	function testSyntaxCache() {
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
 		runHaxeJson(["-cp", "."], ServerMethods.ReadClassPaths, null);

+ 5 - 0
tests/server/test/templates/diagnostics/multi-files/File1.hx

@@ -0,0 +1,5 @@
+class File1 {
+	static function test() {
+		var foo = 42;
+	}
+}

+ 5 - 0
tests/server/test/templates/diagnostics/multi-files/File2.hx

@@ -0,0 +1,5 @@
+class File2 {
+	static function test() {
+		var foo = 42;
+	}
+}

+ 5 - 0
tests/server/test/templates/diagnostics/multi-files/File3.hx

@@ -0,0 +1,5 @@
+class File3 {
+	static function test() {
+		var foo = 42;
+	}
+}

+ 5 - 0
tests/server/test/templates/diagnostics/multi-files/Main.hx

@@ -0,0 +1,5 @@
+import File1;
+import File2;
+import File3;
+
+function main() {}