瀏覽代碼

[tests] add test for #10678

closes #10678

This is really awkward, but whatever
Simon Krajewski 3 年之前
父節點
當前提交
3dff681fd6

+ 13 - 1
src/macro/macroApi.ml

@@ -2061,6 +2061,18 @@ let macro_api ccom get_api =
 			let name = decode_string name in
 			let name = decode_string name in
 			v.v_name <- name;
 			v.v_name <- name;
 			vnull;
 			vnull;
-		)
+		);
+		"send_json", vfun1 (fun json ->
+			begin match (ccom()).json_out with
+			| Some api ->
+				let json = decode_string json in
+				let lexbuf = Sedlexing.Utf8.from_string json in
+				let parse = Json.Reader.read_json lexbuf in
+				api.send_result parse;
+				vbool true
+			| None ->
+				vbool false
+			end
+		);
 	]
 	]
 end
 end

+ 2 - 0
src/typing/macroContext.ml

@@ -295,6 +295,7 @@ let make_macro_api ctx p =
 				let mnew = TypeloadModule.type_module ctx ~dont_check_path:(has_native_meta) m (Path.UniqueKey.lazy_path mdep.m_extra.m_file) [tdef,pos] pos in
 				let mnew = TypeloadModule.type_module ctx ~dont_check_path:(has_native_meta) m (Path.UniqueKey.lazy_path mdep.m_extra.m_file) [tdef,pos] pos in
 				mnew.m_extra.m_kind <- if is_macro then MMacro else MFake;
 				mnew.m_extra.m_kind <- if is_macro then MMacro else MFake;
 				add_dependency mnew mdep;
 				add_dependency mnew mdep;
+				ctx.com.module_nonexistent_lut#clear;
 			in
 			in
 			add false ctx;
 			add false ctx;
 			(* if we are adding a class which has a macro field, we also have to add it to the macro context (issue #1497) *)
 			(* if we are adding a class which has a macro field, we also have to add it to the macro context (issue #1497) *)
@@ -324,6 +325,7 @@ let make_macro_api ctx p =
 				let mnew = TypeloadModule.type_module ctx mpath (Path.UniqueKey.lazy_path ctx.m.curmod.m_extra.m_file) types pos in
 				let mnew = TypeloadModule.type_module ctx mpath (Path.UniqueKey.lazy_path ctx.m.curmod.m_extra.m_file) types pos in
 				mnew.m_extra.m_kind <- MFake;
 				mnew.m_extra.m_kind <- MFake;
 				add_dependency mnew ctx.m.curmod;
 				add_dependency mnew ctx.m.curmod;
+				ctx.com.module_nonexistent_lut#clear;
 			end
 			end
 		);
 		);
 		MacroApi.module_dependency = (fun mpath file ->
 		MacroApi.module_dependency = (fun mpath file ->

+ 17 - 0
tests/server/src/cases/display/issues/Issue10678.hx

@@ -0,0 +1,17 @@
+package cases.display.issues;
+
+import haxe.Json;
+
+class Issue10678 extends DisplayTestCase {
+	function test(_) {
+		vfs.putContent("Macro.hx", getTemplate("issues/Issue10678/Macro.hx"));
+		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
+		var args = ["--main HelloWorld", "--js", "js.js", "--macro", "Macro.init()"];
+		// This is very facepalm
+		runHaxeJson(args, DisplayMethods.FindReferences, {file: new FsPath("HelloWorld.hx"), offset: 0});
+		var results:Array<String> = Json.parse(lastResult.stderr).result.result;
+		for (i => result in results) {
+			Assert.notContains(result, results.slice(i + 1));
+		}
+	}
+}

+ 14 - 0
tests/server/test/templates/issues/Issue10678/Macro.hx

@@ -0,0 +1,14 @@
+import haxe.macro.Context;
+
+var lookups = [];
+
+function init() {
+	Context.onTypeNotFound(path -> {
+		lookups.push(path);
+		return null;
+	});
+	Context.onAfterTyping(_ -> {
+		var json = haxe.Json.stringify(lookups);
+		@:privateAccess Context.load("send_json", 1)(json);
+	});
+}