From 8d53a5382d1b01fa68de8d6072b8f74586d86f5e Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 16 Jan 2023 19:46:33 +0100 Subject: [PATCH] resolve type of `@typeInfo` (#915) --- src/analysis.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/analysis.zig b/src/analysis.zig index 5b3ef86..cf92e92 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -3,6 +3,7 @@ const DocumentStore = @import("DocumentStore.zig"); const Ast = std.zig.Ast; const types = @import("lsp.zig"); const offsets = @import("offsets.zig"); +const URI = @import("uri.zig"); const log = std.log.scoped(.analysis); const ast = @import("ast.zig"); const ComptimeInterpreter = @import("ComptimeInterpreter.zig"); @@ -965,6 +966,30 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl return resolved_type; } + if (std.mem.eql(u8, call_name, "@typeInfo")) { + const zig_lib_path = try URI.fromPath(arena.allocator(), store.config.zig_lib_path orelse return null); + + const builtin_uri = URI.pathRelative(arena.allocator(), zig_lib_path, "/std/builtin.zig") catch |err| switch (err) { + error.OutOfMemory => |e| return e, + else => return null, + }; + + const new_handle = store.getOrLoadHandle(builtin_uri) orelse return null; + const root_scope = new_handle.document_scope.scopes.items[0]; + const decl = root_scope.decls.get("Type") orelse return null; + if (decl != .ast_node) return null; + + const var_decl = ast.varDecl(new_handle.tree, decl.ast_node) orelse return null; + + return TypeWithHandle{ + .type = .{ + .data = .{ .other = var_decl.ast.init_node }, + .is_type_val = false, + }, + .handle = new_handle, + }; + } + if (std.mem.eql(u8, call_name, "@import")) { if (params.len == 0) return null; const import_param = params[0];