This commit is contained in:
agra
2026-02-24 13:37:27 +02:00
parent 170e236764
commit b98711a1d3
13 changed files with 157 additions and 632 deletions

View File

@@ -121,28 +121,44 @@ pub fn resolveImports(
.decls = try ns_decls.toOwnedSlice(allocator),
} },
};
ns_node.source_file = file_path;
try mod.scope.put(ns_name, {});
try decl_list.append(allocator, ns_node);
} else {
// Flat: add fn_decls directly + keep c_import_decl
for (result.fn_decls) |fd| {
fd.source_file = file_path;
_ = try mod.addDecl(allocator, &decl_list, fd);
}
decl.source_file = file_path;
_ = try mod.addDecl(allocator, &decl_list, decl);
}
continue;
}
if (decl.data != .import_decl) {
decl.source_file = file_path;
_ = try mod.addDecl(allocator, &decl_list, decl);
continue;
}
const imp = decl.data.import_decl;
// Resolve path relative to base_dir
const resolved_path = if (std.mem.eql(u8, base_dir, "."))
imp.path
else
try std.fmt.allocPrint(allocator, "{s}/{s}", .{ base_dir, imp.path });
// Resolve path: try relative to file dir first, then fall back to cwd-relative
const resolved_path = resolvePath: {
if (!std.mem.eql(u8, base_dir, ".")) {
const rel_path = try std.fmt.allocPrint(allocator, "{s}/{s}", .{ base_dir, imp.path });
// Check if it exists as file or directory relative to base_dir
if (std.Io.Dir.readFileAlloc(.cwd(), io, rel_path, allocator, .limited(10 * 1024 * 1024))) |_| {
break :resolvePath rel_path;
} else |_| {}
// Try as directory
if (std.Io.Dir.openDir(.cwd(), io, rel_path, .{})) |dir| {
dir.close(io);
break :resolvePath rel_path;
} else |_| {}
}
// Fall back to raw path (cwd-relative)
break :resolvePath imp.path;
};
// Circular import check — only along the current chain
if (chain.contains(resolved_path)) continue;