Skip to content

Commit

Permalink
[display] do not consider import.hx as current module when it's not (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
kLabz authored Feb 18, 2025
1 parent 1249ed9 commit b0b2997
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/context/display/importHandling.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/server/src/cases/issues/Issue12018.hx
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions tests/server/test/templates/issues/Issue12018/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// don't remove
class Ma{-1-}in {
static function main() {
HaxeJson.parse("{}");
}
}
1 change: 1 addition & 0 deletions tests/server/test/templates/issues/Issue12018/import.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import haxe.Json as HaxeJson;

0 comments on commit b0b2997

Please sign in to comment.