remove boxed null boilerplate

This commit is contained in:
Techatrix 2023-03-21 17:28:52 +01:00 committed by Lee Cannon
parent 0c333aaa8a
commit 3c165eabcd

View File

@ -296,14 +296,7 @@ const Context = struct {
document_store: *zls.DocumentStore, document_store: *zls.DocumentStore,
interpreter: *ComptimeInterpreter, interpreter: *ComptimeInterpreter,
// this is very annoying and ugly
boxed_null: *const ?ZigVersionWrapper,
pub fn init(source: []const u8) !Context { pub fn init(source: []const u8) !Context {
var boxed_null = try allocator.create(?ZigVersionWrapper);
errdefer allocator.destroy(boxed_null);
boxed_null.* = null;
var config = try allocator.create(zls.Config); var config = try allocator.create(zls.Config);
errdefer allocator.destroy(config); errdefer allocator.destroy(config);
@ -317,7 +310,7 @@ const Context = struct {
document_store.* = .{ document_store.* = .{
.allocator = allocator, .allocator = allocator,
.config = config, .config = config,
.runtime_zig_version = boxed_null, .runtime_zig_version = &@as(?ZigVersionWrapper, null),
}; };
errdefer document_store.deinit(); errdefer document_store.deinit();
@ -345,8 +338,6 @@ const Context = struct {
.config = config, .config = config,
.document_store = document_store, .document_store = document_store,
.interpreter = interpreter, .interpreter = interpreter,
.boxed_null = boxed_null,
}; };
} }
@ -357,7 +348,6 @@ const Context = struct {
allocator.destroy(self.config); allocator.destroy(self.config);
allocator.destroy(self.document_store); allocator.destroy(self.document_store);
allocator.destroy(self.interpreter); allocator.destroy(self.interpreter);
allocator.destroy(self.boxed_null);
} }
pub fn call(self: *Context, func_node: Ast.Node.Index, arguments: []const KV) !KV { pub fn call(self: *Context, func_node: Ast.Node.Index, arguments: []const KV) !KV {