瀏覽代碼

[display] do not consider import.hx as current module when it's not (#12018)

* [display] do not consider import.hx as current module when it's not

* [tests] add test

* [tests] 12017 was open in the meantime..

* Invert check order
Rudy Ges 5 月之前
父節點
當前提交
b0b299781a

+ 3 - 2
src/context/display/importHandling.ml

@@ -113,8 +113,9 @@ let init_import ctx path mode p =
 		let check_alias mt name pname =
 			if not (name.[0] >= 'A' && name.[0] <= 'Z') then
 				raise_typing_error "Type aliases must start with an uppercase letter" pname;
-			if ctx.m.is_display_file && DisplayPosition.display_position#enclosed_in pname then
-				DisplayEmitter.display_alias ctx name (type_of_module_type mt) pname;
+			(* Imports from import.hx should not match display position from current file *)
+			if ctx.m.is_display_file && DisplayPosition.display_position#enclosed_in pname && (Path.UniqueKey.create pname.pfile) = (Path.UniqueKey.lazy_key ctx.m.curmod.m_extra.m_file) then
+				DisplayEmitter.display_alias ctx name (type_of_module_type mt) pname
 		in
 		let add_static_init t name s =
 			match resolve_typedef t with

+ 18 - 0
tests/server/src/cases/issues/Issue12018.hx

@@ -0,0 +1,18 @@
+package cases.issues;
+
+class Issue12018 extends TestCase {
+	function test(_) {
+		var content = getTemplate("issues/Issue12018/Main.hx");
+		var transform = Markers.parse(content);
+
+		vfs.putContent("Main.hx", transform.source);
+		vfs.putContent("import.hx", getTemplate("issues/Issue12018/import.hx"));
+		var args = ["-main", "Main"];
+		runHaxe(args);
+		assertSuccess();
+
+		runHaxeJsonCb(args, DisplayMethods.Hover, {file: new FsPath("Main.hx"), offset: transform.offset(1)}, (res) -> {
+			Assert.equals(res.item.args.path.typeName, "Main");
+		});
+	}
+}

+ 6 - 0
tests/server/test/templates/issues/Issue12018/Main.hx

@@ -0,0 +1,6 @@
+// don't remove
+class Ma{-1-}in {
+	static function main() {
+		HaxeJson.parse("{}");
+	}
+}

+ 1 - 0
tests/server/test/templates/issues/Issue12018/import.hx

@@ -0,0 +1 @@
+import haxe.Json as HaxeJson;