From ff354631832a68f73d5d0813a76f7a0b5f24ef24 Mon Sep 17 00:00:00 2001 From: xdBronch <51252236+xdBronch@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:36:32 -0500 Subject: [PATCH] embrace RLS even harder --- build.zig | 4 +- src/BuildAssociatedConfig.zig | 2 +- src/DocumentScope.zig | 8 +-- src/DocumentStore.zig | 4 +- src/Server.zig | 14 ++-- src/analyser/InternPool.zig | 62 ++++++++-------- src/analyser/degibberish.zig | 2 +- src/analyser/string_pool.zig | 2 +- src/analysis.zig | 98 +++++++++++++------------- src/ast.zig | 8 +-- src/build_runner/master.zig | 16 ++--- src/configuration.zig | 6 +- src/diff.zig | 2 +- src/features/code_actions.zig | 18 ++--- src/features/completions.zig | 14 ++-- src/features/document_symbol.zig | 4 +- src/features/goto.zig | 10 +-- src/features/hover.zig | 2 +- src/offsets.zig | 6 +- src/tools/config_gen.zig | 2 +- tests/ErrorBuilder.zig | 6 +- tests/helper.zig | 2 +- tests/lsp_features/completion.zig | 12 ++-- tests/lsp_features/inlay_hints.zig | 2 +- tests/lsp_features/selection_range.zig | 2 +- tests/utility/ast.zig | 6 +- 26 files changed, 157 insertions(+), 157 deletions(-) diff --git a/build.zig b/build.zig index 0733f1d2d..ec462bdf8 100644 --- a/build.zig +++ b/build.zig @@ -359,9 +359,9 @@ fn getTracyModule( // On mingw, we need to opt into windows 7+ to get some features required by tracy. const tracy_c_flags: []const []const u8 = if (options.target.result.isMinGW()) - &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } + &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } else - &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; + &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; tracy_module.addIncludePath(tracy_dependency.path("")); tracy_module.addCSourceFile(.{ diff --git a/src/BuildAssociatedConfig.zig b/src/BuildAssociatedConfig.zig index 7f8c78c85..b03031d6e 100644 --- a/src/BuildAssociatedConfig.zig +++ b/src/BuildAssociatedConfig.zig @@ -14,7 +14,7 @@ pub const BuildOption = struct { try allocator.dupe(u8, val) else null; - return BuildOption{ + return .{ .name = copy_name, .value = copy_value, }; diff --git a/src/DocumentScope.zig b/src/DocumentScope.zig index a17604ef9..c83f97090 100644 --- a/src/DocumentScope.zig +++ b/src/DocumentScope.zig @@ -493,10 +493,10 @@ const ScopeContext = struct { .loc = loc, .parent_scope = context.current_scope, .child_scopes = .{ - .small = [_]Scope.OptionalIndex{.none} ** Scope.ChildScopes.small_size, + .small = @splat(.none), }, .child_declarations = .{ - .small = [_]Declaration.OptionalIndex{.none} ** Scope.ChildDeclarations.small_size, + .small = @splat(.none), }, }); const new_scope_index: Scope.Index = @enumFromInt(context.doc_scope.scopes.len - 1); @@ -896,7 +896,7 @@ noinline fn walkContainerDecl( const gop = try context.doc_scope.global_enum_set.getOrPutContext( context.allocator, main_token, - IdentifierTokenContext{ .tree = tree }, + .{ .tree = tree }, ); if (!gop.found_existing) { gop.key_ptr.* = main_token; @@ -963,7 +963,7 @@ noinline fn walkErrorSetNode( const gop = try context.doc_scope.global_error_set.getOrPutContext( context.allocator, identifier_token, - IdentifierTokenContext{ .tree = tree }, + .{ .tree = tree }, ); if (!gop.found_existing or token_tags[identifier_token - 1] == .doc_comment) { // a token with a doc comment takes priority. diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index c812142f4..99cac72a4 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -1090,7 +1090,7 @@ fn loadBuildConfiguration(self: *DocumentStore, build_file_uri: Uri) !std.json.P errdefer build_config.deinit(); for (build_config.value.packages) |*pkg| { - pkg.path = try std.fs.path.resolve(build_config.arena.allocator(), &[_][]const u8{ build_file_path, "..", pkg.path }); + pkg.path = try std.fs.path.resolve(build_config.arena.allocator(), &.{ build_file_path, "..", pkg.path }); } return build_config; @@ -1150,7 +1150,7 @@ fn createBuildFile(self: *DocumentStore, uri: Uri) error{OutOfMemory}!BuildFile const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); - var build_file = BuildFile{ + var build_file: BuildFile = .{ .uri = try self.allocator.dupe(u8, uri), }; diff --git a/src/Server.zig b/src/Server.zig index 8996da0b3..25f08aed6 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -599,7 +599,7 @@ fn initializeHandler(server: *Server, arena: std.mem.Allocator, request: types.I .renameProvider = .{ .bool = true }, .completionProvider = .{ .resolveProvider = false, - .triggerCharacters = &[_][]const u8{ ".", ":", "@", "]", "\"", "/" }, + .triggerCharacters = &.{ ".", ":", "@", "]", "\"", "/" }, .completionItem = .{ .labelDetailsSupport = true }, }, .documentHighlightProvider = .{ .bool = true }, @@ -690,7 +690,7 @@ fn registerCapability(server: *Server, method: []const u8) Error!void { .{ .string = id }, "client/registerCapability", types.RegistrationParams{ .registrations = &.{ - types.Registration{ + .{ .id = id, .method = method, }, @@ -1320,7 +1320,7 @@ fn resolveConfiguration( }; defer allocator.free(cache_dir_path); - config.global_cache_path = try std.fs.path.join(config_arena, &[_][]const u8{ cache_dir_path, "zls" }); + config.global_cache_path = try std.fs.path.join(config_arena, &.{ cache_dir_path, "zls" }); std.fs.cwd().makePath(config.global_cache_path.?) catch |err| { log.warn("failed to create directory '{s}': {}", .{ config.global_cache_path.?, err }); @@ -1473,7 +1473,7 @@ fn saveDocumentHandler(server: *Server, arena: std.mem.Allocator, notification: const handle = server.document_store.getHandle(uri) orelse return; var text_edits = try server.autofix(arena, handle); - var workspace_edit = types.WorkspaceEdit{ .changes = .{} }; + var workspace_edit: types.WorkspaceEdit = .{ .changes = .{} }; try workspace_edit.changes.?.map.putNoClobber(arena, uri, try text_edits.toOwnedSlice(arena)); const json_message = try server.sendToClientRequest( @@ -1885,12 +1885,12 @@ fn isBlockingMessage(msg: Message) bool { pub fn create(allocator: std.mem.Allocator) !*Server { const server = try allocator.create(Server); errdefer server.destroy(); - server.* = Server{ + server.* = .{ .allocator = allocator, .config = .{}, .document_store = .{ .allocator = allocator, - .config = .fromMainConfig(Config{}), + .config = .fromMainConfig(.{}), .thread_pool = if (zig_builtin.single_threaded) {} else undefined, // set below .diagnostics_collection = &server.diagnostics_collection, }, @@ -2114,7 +2114,7 @@ fn processMessageReportError(server: *Server, message: Message) ?[]const u8 { } switch (message) { - .request => |request| return server.sendToClientResponseError(request.id, lsp.JsonRPCMessage.Response.Error{ + .request => |request| return server.sendToClientResponseError(request.id, .{ .code = @enumFromInt(switch (err) { error.OutOfMemory => @intFromEnum(types.ErrorCodes.InternalError), error.ParseError => @intFromEnum(types.ErrorCodes.ParseError), diff --git a/src/analyser/InternPool.zig b/src/analyser/InternPool.zig index 0ad5047df..d97e28dbd 100644 --- a/src/analyser/InternPool.zig +++ b/src/analyser/InternPool.zig @@ -655,7 +655,7 @@ pub const Index = enum(u32) { start: u32, len: u32, - pub const empty = Slice{ + pub const empty: Slice = .{ .start = std.math.maxInt(u32), .len = 0, }; @@ -713,7 +713,7 @@ pub const StringSlice = struct { start: u32, len: u32, - pub const empty = StringSlice{ + pub const empty: StringSlice = .{ .start = std.math.maxInt(u32), .len = 0, }; @@ -751,7 +751,7 @@ pub const LimbSlice = struct { start: u32, len: u32, - pub const empty = LimbSlice{ + pub const empty: LimbSlice = .{ .start = std.math.maxInt(u32), .len = 0, }; @@ -2507,7 +2507,7 @@ fn coerceInMemoryAllowed( const src_tag = ip.zigTypeTag(src_ty); if (dest_tag != src_tag) { - return InMemoryCoercionResult{ .no_match = .{ + return .{ .no_match = .{ .actual = dest_ty, .wanted = src_ty, } }; @@ -2525,7 +2525,7 @@ fn coerceInMemoryAllowed( (dest_info.signedness == .signed and (src_info.signedness == .unsigned or dest_info.bits <= src_info.bits)) or (dest_info.signedness == .unsigned and src_info.signedness == .signed)) { - return InMemoryCoercionResult{ .int_not_coercible = .{ + return .{ .int_not_coercible = .{ .actual_signedness = src_info.signedness, .wanted_signedness = dest_info.signedness, .actual_bits = src_info.bits, @@ -2538,7 +2538,7 @@ fn coerceInMemoryAllowed( const dest_bits = ip.floatBits(dest_ty, target); const src_bits = ip.floatBits(src_ty, target); if (dest_bits == src_bits) return .ok; - return InMemoryCoercionResult{ .no_match = .{ + return .{ .no_match = .{ .actual = dest_ty, .wanted = src_ty, } }; @@ -2555,7 +2555,7 @@ fn coerceInMemoryAllowed( } if (maybe_dest_ptr_ty != maybe_src_ptr_ty) { - return InMemoryCoercionResult{ .optional_shape = .{ + return .{ .optional_shape = .{ .actual = src_ty, .wanted = dest_ty, } }; @@ -2566,7 +2566,7 @@ fn coerceInMemoryAllowed( const child = try ip.coerceInMemoryAllowed(gpa, arena, dest_child_type, src_child_type, dest_is_const, target); if (child != .ok) { - return InMemoryCoercionResult{ .optional_child = .{ + return .{ .optional_child = .{ .child = try child.dupe(arena), .actual = src_child_type, .wanted = dest_child_type, @@ -2583,7 +2583,7 @@ fn coerceInMemoryAllowed( const src_payload = src_key.error_union_type.payload_type; const child = try ip.coerceInMemoryAllowed(gpa, arena, dest_payload, src_payload, dest_is_const, target); if (child != .ok) { - return InMemoryCoercionResult{ .error_union_payload = .{ + return .{ .error_union_payload = .{ .child = try child.dupe(arena), .actual = src_payload, .wanted = dest_payload, @@ -2601,7 +2601,7 @@ fn coerceInMemoryAllowed( const dest_info = dest_key.array_type; const src_info = src_key.array_type; if (dest_info.len != src_info.len) { - return InMemoryCoercionResult{ .array_len = .{ + return .{ .array_len = .{ .actual = src_info.len, .wanted = dest_info.len, } }; @@ -2609,7 +2609,7 @@ fn coerceInMemoryAllowed( const child = try ip.coerceInMemoryAllowed(gpa, arena, dest_info.child, src_info.child, dest_is_const, target); if (child != .ok) { - return InMemoryCoercionResult{ .array_elem = .{ + return .{ .array_elem = .{ .child = try child.dupe(arena), .actual = src_info.child, .wanted = dest_info.child, @@ -2621,7 +2621,7 @@ fn coerceInMemoryAllowed( dest_info.sentinel == src_info.sentinel // is this enough for a value equality check? ); if (!ok_sent) { - return InMemoryCoercionResult{ .array_sentinel = .{ + return .{ .array_sentinel = .{ .actual = src_info.sentinel, .wanted = dest_info.sentinel, .ty = dest_info.child, @@ -2634,7 +2634,7 @@ fn coerceInMemoryAllowed( const src_len = src_key.vector_type.len; if (dest_len != src_len) { - return InMemoryCoercionResult{ .vector_len = .{ + return .{ .vector_len = .{ .actual = src_len, .wanted = dest_len, } }; @@ -2644,7 +2644,7 @@ fn coerceInMemoryAllowed( const src_elem_ty = src_key.vector_type.child; const child = try ip.coerceInMemoryAllowed(gpa, arena, dest_elem_ty, src_elem_ty, dest_is_const, target); if (child != .ok) { - return InMemoryCoercionResult{ .vector_elem = .{ + return .{ .vector_elem = .{ .child = try child.dupe(arena), .actual = src_elem_ty, .wanted = dest_elem_ty, @@ -2654,7 +2654,7 @@ fn coerceInMemoryAllowed( return .ok; }, else => { - return InMemoryCoercionResult{ .no_match = .{ + return .{ .no_match = .{ .actual = dest_ty, .wanted = src_ty, } }; @@ -2690,7 +2690,7 @@ fn coerceInMemoryAllowedErrorSets( if (missing_error_buf.items.len == 0) return .ok; - return InMemoryCoercionResult{ + return .{ .missing_error = try arena.dupe(String, missing_error_buf.items), }; } @@ -2707,15 +2707,15 @@ fn coerceInMemoryAllowedFns( const src_info = ip.indexToKey(src_ty).function_type; if (dest_info.flags.is_var_args != src_info.flags.is_var_args) { - return InMemoryCoercionResult{ .fn_var_args = dest_info.flags.is_var_args }; + return .{ .fn_var_args = dest_info.flags.is_var_args }; } if (dest_info.flags.is_generic != src_info.flags.is_generic) { - return InMemoryCoercionResult{ .fn_generic = dest_info.flags.is_generic }; + return .{ .fn_generic = dest_info.flags.is_generic }; } if (dest_info.flags.calling_convention != src_info.flags.calling_convention) { - return InMemoryCoercionResult{ .fn_cc = .{ + return .{ .fn_cc = .{ .actual = src_info.flags.calling_convention, .wanted = dest_info.flags.calling_convention, } }; @@ -2724,7 +2724,7 @@ fn coerceInMemoryAllowedFns( if (src_info.return_type != Index.noreturn_type) { const rt = try ip.coerceInMemoryAllowed(gpa, arena, dest_info.return_type, src_info.return_type, true, target); if (rt != .ok) { - return InMemoryCoercionResult{ .fn_return_type = .{ + return .{ .fn_return_type = .{ .child = try rt.dupe(arena), .actual = src_info.return_type, .wanted = dest_info.return_type, @@ -2733,14 +2733,14 @@ fn coerceInMemoryAllowedFns( } if (dest_info.args.len != src_info.args.len) { - return InMemoryCoercionResult{ .fn_param_count = .{ + return .{ .fn_param_count = .{ .actual = src_info.args.len, .wanted = dest_info.args.len, } }; } if (!dest_info.args_is_noalias.eql(src_info.args_is_noalias)) { - return InMemoryCoercionResult{ .fn_param_noalias = .{ + return .{ .fn_param_noalias = .{ .actual = src_info.args_is_noalias.mask, .wanted = dest_info.args_is_noalias.mask, } }; @@ -2748,7 +2748,7 @@ fn coerceInMemoryAllowedFns( if (!dest_info.args_is_comptime.eql(src_info.args_is_comptime)) { const index = dest_info.args_is_comptime.xorWith(src_info.args_is_comptime).findFirstSet().?; - return InMemoryCoercionResult{ .fn_param_comptime = .{ + return .{ .fn_param_comptime = .{ .index = index, .wanted = dest_info.args_is_comptime.isSet(index), } }; @@ -2764,7 +2764,7 @@ fn coerceInMemoryAllowedFns( // Note: Cast direction is reversed here. const param = try ip.coerceInMemoryAllowed(gpa, arena, src_arg_ty, dest_arg_ty, true, target); if (param != .ok) { - return InMemoryCoercionResult{ .fn_param = .{ + return .{ .fn_param = .{ .child = try param.dupe(arena), .actual = src_arg_ty, .wanted = dest_arg_ty, @@ -2799,7 +2799,7 @@ fn coerceInMemoryAllowedPtrs( const ok_ptr_size = src_info.flags.size == dest_info.flags.size or src_info.flags.size == .C or dest_info.flags.size == .C; if (!ok_ptr_size) { - return InMemoryCoercionResult{ .ptr_size = .{ + return .{ .ptr_size = .{ .actual = src_info.flags.size, .wanted = dest_info.flags.size, } }; @@ -2810,7 +2810,7 @@ fn coerceInMemoryAllowedPtrs( (!src_info.flags.is_volatile or dest_info.flags.is_volatile); if (!ok_cv_qualifiers) { - return InMemoryCoercionResult{ .ptr_qualifiers = .{ + return .{ .ptr_qualifiers = .{ .actual_const = src_info.flags.is_const, .wanted_const = dest_info.flags.is_const, .actual_volatile = src_info.flags.is_volatile, @@ -2819,7 +2819,7 @@ fn coerceInMemoryAllowedPtrs( } if (dest_info.flags.address_space != src_info.flags.address_space) { - return InMemoryCoercionResult{ .ptr_addrspace = .{ + return .{ .ptr_addrspace = .{ .actual = src_info.flags.address_space, .wanted = dest_info.flags.address_space, } }; @@ -2827,7 +2827,7 @@ fn coerceInMemoryAllowedPtrs( const child = try ip.coerceInMemoryAllowed(gpa, arena, dest_info.elem_type, src_info.elem_type, dest_info.flags.is_const, target); if (child != .ok) { - return InMemoryCoercionResult{ .ptr_child = .{ + return .{ .ptr_child = .{ .child = try child.dupe(arena), .actual = src_info.elem_type, .wanted = dest_info.elem_type, @@ -2839,7 +2839,7 @@ fn coerceInMemoryAllowedPtrs( const ok_allows_zero = (dest_allow_zero and (src_allow_zero or dest_is_const)) or (!dest_allow_zero and !src_allow_zero); if (!ok_allows_zero) { - return InMemoryCoercionResult{ .ptr_allowzero = .{ + return .{ .ptr_allowzero = .{ .actual = src_ty, .wanted = dest_ty, } }; @@ -2848,7 +2848,7 @@ fn coerceInMemoryAllowedPtrs( if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size or src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { - return InMemoryCoercionResult{ .ptr_bit_range = .{ + return .{ .ptr_bit_range = .{ .actual_host = src_info.packed_offset.host_size, .wanted_host = dest_info.packed_offset.host_size, .actual_offset = src_info.packed_offset.bit_offset, @@ -2858,7 +2858,7 @@ fn coerceInMemoryAllowedPtrs( const ok_sent = dest_info.sentinel == .none or src_info.flags.size == .C or dest_info.sentinel == src_info.sentinel; // is this enough for a value equality check? if (!ok_sent) { - return InMemoryCoercionResult{ .ptr_sentinel = .{ + return .{ .ptr_sentinel = .{ .actual = src_info.sentinel, .wanted = dest_info.sentinel, .ty = dest_info.elem_type, diff --git a/src/analyser/degibberish.zig b/src/analyser/degibberish.zig index 549a8bb66..5c8cc03ca 100644 --- a/src/analyser/degibberish.zig +++ b/src/analyser/degibberish.zig @@ -12,7 +12,7 @@ const FormatDegibberishData = struct { }; pub fn fmtDegibberish(ip: *InternPool, ty: InternPool.Index) std.fmt.Formatter(formatDegibberish) { - const data = FormatDegibberishData{ .ip = ip, .ty = ty }; + const data: FormatDegibberishData = .{ .ip = ip, .ty = ty }; return .{ .data = data }; } diff --git a/src/analyser/string_pool.zig b/src/analyser/string_pool.zig index 6ef6e38ea..386e8b700 100644 --- a/src/analyser/string_pool.zig +++ b/src/analyser/string_pool.zig @@ -101,7 +101,7 @@ pub fn StringPool(comptime config: Config) type { allocator, str, adapter, - std.hash_map.StringIndexContext{ .bytes = &pool.bytes }, + .{ .bytes = &pool.bytes }, ); if (!gop.found_existing) { diff --git a/src/analysis.zig b/src/analysis.zig index 55d372bde..48ac88468 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -698,7 +698,7 @@ pub fn resolveVarDeclAlias(analyser: *Analyser, node_handle: NodeWithHandle) err } fn resolveVarDeclAliasInternal(analyser: *Analyser, node_handle: NodeWithHandle, node_trail: *NodeSet) error{OutOfMemory}!?DeclWithHandle { - const node_with_uri = NodeWithUri{ .node = node_handle.node, .uri = node_handle.handle.uri }; + const node_with_uri: NodeWithUri = .{ .node = node_handle.node, .uri = node_handle.handle.uri }; const gop = try node_trail.getOrPut(analyser.gpa, node_with_uri); if (gop.found_existing) return null; @@ -844,7 +844,7 @@ pub fn resolveReturnType(analyser: *Analyser, func_type_param: Type) error{OutOf if (ast.hasInferredError(tree, fn_proto)) { const child_type_ptr = try analyser.arena.allocator().create(Type); child_type_ptr.* = child_type; - return Type{ + return .{ .data = .{ .error_union = .{ .error_set = null, .payload = child_type_ptr, @@ -892,7 +892,7 @@ pub fn resolveOptionalChildType(analyser: *Analyser, optional_type: Type) error{ pub fn resolveAddressOf(analyser: *Analyser, ty: Type) error{OutOfMemory}!?Type { const base_type_ptr = try analyser.arena.allocator().create(Type); base_type_ptr.* = ty.typeOf(analyser); - return Type{ + return .{ .data = .{ .pointer = .{ .size = .One, @@ -947,7 +947,7 @@ fn resolveTaggedUnionFieldType(analyser: *Analyser, ty: Type, symbol: []const u8 if (container_decl.ast.enum_token != null) { const union_type_ptr = try analyser.arena.allocator().create(Type); union_type_ptr.* = ty; - return Type{ .data = .{ .union_tag = union_type_ptr }, .is_type_val = false }; + return .{ .data = .{ .union_tag = union_type_ptr }, .is_type_val = false }; } if (container_decl.ast.arg != 0) { @@ -1015,7 +1015,7 @@ fn resolveBracketAccessType(analyser: *Analyser, lhs: Type, rhs: BracketAccessKi .array => |info| switch (rhs) { .Single => return try info.elem_ty.instanceTypeVal(analyser), .Open => { - return Type{ + return .{ .data = .{ .pointer = .{ .size = .Slice, @@ -1028,7 +1028,7 @@ fn resolveBracketAccessType(analyser: *Analyser, lhs: Type, rhs: BracketAccessKi }; }, .Range => { - return Type{ + return .{ .data = .{ .pointer = .{ .size = .Slice, @@ -1047,7 +1047,7 @@ fn resolveBracketAccessType(analyser: *Analyser, lhs: Type, rhs: BracketAccessKi switch (rhs) { .Single => return try array_info.elem_ty.instanceTypeVal(analyser), .Open => { - return Type{ + return .{ .data = .{ .pointer = .{ .size = .Slice, @@ -1060,7 +1060,7 @@ fn resolveBracketAccessType(analyser: *Analyser, lhs: Type, rhs: BracketAccessKi }; }, .Range => { - return Type{ + return .{ .data = .{ .pointer = .{ .size = .Slice, @@ -1080,7 +1080,7 @@ fn resolveBracketAccessType(analyser: *Analyser, lhs: Type, rhs: BracketAccessKi .Single => try info.elem_ty.instanceTypeVal(analyser), .Open => lhs, .Range => { - return Type{ + return .{ .data = .{ .pointer = .{ .size = .Slice, @@ -1100,7 +1100,7 @@ fn resolveBracketAccessType(analyser: *Analyser, lhs: Type, rhs: BracketAccessKi .C => switch (rhs) { .Single => try info.elem_ty.instanceTypeVal(analyser), .Open => lhs, - .Range => Type{ + .Range => .{ .data = .{ .pointer = .{ .size = .Slice, @@ -1180,7 +1180,7 @@ fn resolvePropertyType(analyser: *Analyser, ty: Type, name: []const u8) error{Ou } if (std.mem.eql(u8, "ptr", name)) { - return Type{ + return .{ .data = .{ .pointer = .{ .size = .Many, @@ -1491,7 +1491,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e if (!is_escaped_identifier) { if (std.mem.eql(u8, name, "_")) return null; if (try analyser.resolvePrimitive(name)) |primitive| { - return Type{ + return .{ .data = .{ .ip_index = .{ .index = primitive } }, .is_type_val = analyser.ip.typeOf(primitive) == .type_type, }; @@ -1643,7 +1643,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e const child_ty_ptr = try analyser.arena.allocator().create(Type); child_ty_ptr.* = child_ty; - return Type{ .data = .{ .optional = child_ty_ptr }, .is_type_val = true }; + return .{ .data = .{ .optional = child_ty_ptr }, .is_type_val = true }; }, .ptr_type_aligned, .ptr_type_sentinel, @@ -1659,7 +1659,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e const elem_ty_ptr = try analyser.arena.allocator().create(Type); elem_ty_ptr.* = elem_ty; - return Type{ + return .{ .data = .{ .pointer = .{ .size = ptr_info.size, @@ -1685,7 +1685,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e const elem_ty_ptr = try analyser.arena.allocator().create(Type); elem_ty_ptr.* = elem_ty; - return Type{ + return .{ .data = .{ .array = .{ .elem_count = elem_count, .sentinel = sentinel, @@ -1711,7 +1711,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e return try array_ty.instanceTypeVal(analyser); } - return Type{ + return .{ .data = .{ .other = node_handle }, .is_type_val = false, }; @@ -1729,7 +1729,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e const payload_ptr = try analyser.arena.allocator().create(Type); payload_ptr.* = payload; - return Type{ + return .{ .data = .{ .error_union = .{ .error_set = error_set_ptr, .payload = payload_ptr, @@ -1906,7 +1906,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e return analyser.instanceStdBuiltinType("SourceLocation"); } if (std.mem.eql(u8, call_name, "@compileError")) { - return Type{ .data = .{ .compile_error = node_handle }, .is_type_val = false }; + return .{ .data = .{ .compile_error = node_handle }, .is_type_val = false }; } if (std.mem.eql(u8, call_name, "@Vector")) { @@ -1930,7 +1930,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e }, }); - return Type{ + return .{ .data = .{ .ip_index = .{ .index = vector_ty_ip_index } }, .is_type_val = true, }; @@ -1948,7 +1948,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e return Type.typeVal(node_handle); } - return Type{ .data = .{ .other = .{ .node = node, .handle = handle } }, .is_type_val = false }; + return .{ .data = .{ .other = .{ .node = node, .handle = handle } }, .is_type_val = false }; }, .@"if", .if_simple => { const if_node = ast.fullIf(tree, node).?; @@ -2030,7 +2030,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e if (try analyser.resolveTypeOfNodeInternal(.{ .node = loop.else_expr, .handle = handle })) |else_type| return else_type; - var context = FindBreaks{ + var context: FindBreaks = .{ .label = if (loop.label_token) |token| tree.tokenSlice(token) else null, .allow_unlabeled = true, .allocator = analyser.gpa, @@ -2053,14 +2053,14 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e else => unreachable, }; if (has_zero_statements) { - return Type{ .data = .{ .ip_index = .{ .index = .void_value } }, .is_type_val = false }; + return .{ .data = .{ .ip_index = .{ .index = .void_value } }, .is_type_val = false }; } const label_token = ast.blockLabel(tree, node) orelse return null; const block_label = offsets.identifierTokenToNameSlice(tree, label_token); // TODO: peer type resolution based on all `break` statements - var context = FindBreaks{ + var context: FindBreaks = .{ .label = block_label, .allow_unlabeled = false, .allocator = analyser.gpa, @@ -2073,7 +2073,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e } }, - .for_range => return Type{ .data = .{ .other = .{ .node = node, .handle = handle } }, .is_type_val = false }, + .for_range => return .{ .data = .{ .other = .{ .node = node, .handle = handle } }, .is_type_val = false }, .equal_equal, .bang_equal, @@ -2172,7 +2172,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e .ty = error_set_type, .error_tag_name = name_index, } }); - return Type{ .data = .{ .ip_index = .{ .index = error_value } }, .is_type_val = false }; + return .{ .data = .{ .ip_index = .{ .index = error_value } }, .is_type_val = false }; }, .char_literal => return try Type.typeValFromIP(analyser, .comptime_int_type), @@ -2223,7 +2223,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e .failure => unreachable, // checked above }; - return Type{ + return .{ .data = .{ .ip_index = .{ .index = value orelse try analyser.ip.getUnknown(analyser.gpa, ty) } }, .is_type_val = false, }; @@ -2441,7 +2441,7 @@ pub const Type = struct { .either => |entries| { for (entries) |entry| { hasher.update(entry.descriptor); - const entry_ty = Type{ .data = entry.type_data, .is_type_val = self.is_type_val }; + const entry_ty: Type = .{ .data = entry.type_data, .is_type_val = self.is_type_val }; entry_ty.hashWithHasher(hasher); } }, @@ -2496,8 +2496,8 @@ pub const Type = struct { if (a_entries.len != b_entries.len) return false; for (a_entries, b_entries) |a_entry, b_entry| { if (!std.mem.eql(u8, a_entry.descriptor, b_entry.descriptor)) return false; - const a_entry_ty = Type{ .data = a_entry.type_data, .is_type_val = a.is_type_val }; - const b_entry_ty = Type{ .data = b_entry.type_data, .is_type_val = b.is_type_val }; + const a_entry_ty: Type = .{ .data = a_entry.type_data, .is_type_val = a.is_type_val }; + const b_entry_ty: Type = .{ .data = b_entry.type_data, .is_type_val = b.is_type_val }; if (!a_entry_ty.eql(b_entry_ty)) return false; } }, @@ -2521,7 +2521,7 @@ pub const Type = struct { pub fn typeValFromIP(analyser: *Analyser, ty: InternPool.Index) error{OutOfMemory}!Type { std.debug.assert(analyser.ip.isType(ty)); - return Type{ + return .{ .data = .{ .ip_index = .{ .index = try analyser.ip.getUnknown(analyser.gpa, ty) } }, .is_type_val = ty == .type_type, }; @@ -2545,15 +2545,15 @@ pub const Type = struct { const DeduplicatorContext = struct { pub fn hash(self: @This(), item: Type.Data.EitherEntry) u32 { _ = self; - const ty = Type{ .data = item.type_data, .is_type_val = true }; + const ty: Type = .{ .data = item.type_data, .is_type_val = true }; return ty.hash32(); } pub fn eql(self: @This(), a: Type.Data.EitherEntry, b: Type.Data.EitherEntry, b_index: usize) bool { _ = b_index; _ = self; - const a_ty = Type{ .data = a.type_data, .is_type_val = true }; - const b_ty = Type{ .data = b.type_data, .is_type_val = true }; + const a_ty: Type = .{ .data = a.type_data, .is_type_val = true }; + const b_ty: Type = .{ .data = b.type_data, .is_type_val = true }; return a_ty.eql(b_ty); } }; @@ -2596,7 +2596,7 @@ pub const Type = struct { switch (ty.data) { .either => |entries| { for (entries) |entry| { - const entry_ty = Type{ .data = entry.type_data, .is_type_val = ty.is_type_val }; + const entry_ty: Type = .{ .data = entry.type_data, .is_type_val = ty.is_type_val }; try entry_ty.getAllTypesWithHandlesArrayList(arena, all_types); } }, @@ -2609,7 +2609,7 @@ pub const Type = struct { return switch (self.data) { .ip_index => |payload| { if (payload.index == .unknown_type) return null; - return Type{ + return .{ .data = .{ .ip_index = .{ .index = try analyser.ip.getUnknown(analyser.gpa, payload.index), @@ -2619,26 +2619,26 @@ pub const Type = struct { .is_type_val = payload.index == .type_type, }; }, - else => Type{ .data = self.data, .is_type_val = false }, + else => .{ .data = self.data, .is_type_val = false }, }; } pub fn typeOf(self: Type, analyser: *Analyser) Type { if (self.is_type_val) { - return Type{ + return .{ .data = .{ .ip_index = .{ .index = .type_type } }, .is_type_val = true, }; } if (self.data == .ip_index) { - return Type{ + return .{ .data = .{ .ip_index = .{ .index = analyser.ip.typeOf(self.data.ip_index.index) } }, .is_type_val = true, }; } - return Type{ + return .{ .data = self.data, .is_type_val = true, }; @@ -2817,7 +2817,7 @@ pub const Type = struct { .either => |entries| { // TODO: Return all options instead of first valid one for (entries) |entry| { - const entry_ty = Type{ .data = entry.type_data, .is_type_val = self.is_type_val }; + const entry_ty: Type = .{ .data = entry.type_data, .is_type_val = self.is_type_val }; if (try entry_ty.lookupSymbol(analyser, symbol)) |decl| { return decl; } @@ -3538,7 +3538,7 @@ pub fn getPositionContext( .invalid => { // Single '@' do not return a builtin token so we check this on our own. if (tree.source[tok.loc.start] == '@') { - return PositionContext{ .builtin = tok.loc }; + return .{ .builtin = tok.loc }; } const s = tree.source[tok.loc.start..tok.loc.end]; const q = std.mem.indexOf(u8, s, "\"") orelse return .other; @@ -3903,7 +3903,7 @@ pub const DeclWithHandle = struct { if (gop_resolved.found_existing) break :blk gop_resolved.value_ptr.*; gop_resolved.value_ptr.* = null; - const func_decl = Declaration{ .ast_node = pay.func }; + const func_decl: Declaration = .{ .ast_node = pay.func }; var func_buf: [1]Ast.Node.Index = undefined; const func = tree.fullFnProto(&func_buf, pay.func).?; @@ -4062,7 +4062,7 @@ pub const DeclWithHandle = struct { const resolved_ty_ptr = try analyser.arena.allocator().create(Type); resolved_ty_ptr.* = resolved_ty.typeOf(analyser); - return Type{ + return .{ .data = .{ .pointer = .{ .elem_ty = resolved_ty_ptr, .sentinel = .none, @@ -4105,7 +4105,7 @@ pub fn collectDeclarationsOfContainer( for (scope_decls) |decl_index| { const decl = document_scope.declarations.get(@intFromEnum(decl_index)); - const decl_with_handle = DeclWithHandle{ .decl = decl, .handle = handle }; + const decl_with_handle: DeclWithHandle = .{ .decl = decl, .handle = handle }; if (handle != original_handle and !decl_with_handle.isPublic()) continue; switch (decl) { @@ -4298,7 +4298,7 @@ pub fn iterateLabels(handle: *DocumentStore.Handle, source_index: usize, comptim for (document_scope.getScopeDeclarationsConst(scope_index)) |decl_index| { const decl = document_scope.declarations.get(@intFromEnum(decl_index)); if (decl != .label) continue; - try callback(context, DeclWithHandle{ .decl = decl, .handle = handle }); + try callback(context, .{ .decl = decl, .handle = handle }); } } } @@ -4404,7 +4404,7 @@ pub fn lookupLabel( std.debug.assert(decl == .label); - return DeclWithHandle{ .decl = decl, .handle = handle }; + return .{ .decl = decl, .handle = handle }; } return null; } @@ -4433,7 +4433,7 @@ pub fn lookupSymbolGlobal( const field_name = offsets.tokenToLoc(tree, field.ast.main_token); if (field_name.start <= source_index and source_index <= field_name.end) - return DeclWithHandle{ .decl = decl, .handle = handle }; + return .{ .decl = decl, .handle = handle }; } if (document_scope.getScopeDeclaration(.{ @@ -4442,7 +4442,7 @@ pub fn lookupSymbolGlobal( .kind = .other, }).unwrap()) |decl_index| { const decl = document_scope.declarations.get(@intFromEnum(decl_index)); - return DeclWithHandle{ .decl = decl, .handle = handle }; + return .{ .decl = decl, .handle = handle }; } if (try analyser.resolveUse(document_scope.getScopeUsingnamespaceNodesConst(current_scope), symbol, handle)) |result| return result; @@ -4467,7 +4467,7 @@ pub fn lookupSymbolContainer( .kind = kind, }).unwrap()) |decl_index| { const decl = document_scope.declarations.get(@intFromEnum(decl_index)); - return DeclWithHandle{ .decl = decl, .handle = handle }; + return .{ .decl = decl, .handle = handle }; } if (try analyser.resolveUse(document_scope.getScopeUsingnamespaceNodesConst(container_scope.scope), symbol, handle)) |result| return result; diff --git a/src/ast.zig b/src/ast.zig index 78c193591..3b5b5c3a2 100644 --- a/src/ast.zig +++ b/src/ast.zig @@ -1352,7 +1352,7 @@ pub fn nextFnParam(it: *Ast.full.FnProto.Iterator) ?Ast.full.FnProto.Param { // #boundsCheck // https://github.com/zigtools/zls/issues/567 if (last_param_type_token >= it.tree.tokens.len - 1) - return Ast.full.FnProto.Param{ + return .{ .first_doc_comment = first_doc_comment, .comptime_noalias = comptime_noalias, .name_token = name_token, @@ -1365,7 +1365,7 @@ pub fn nextFnParam(it: *Ast.full.FnProto.Iterator) ?Ast.full.FnProto.Param { it.tok_i += 1; } it.tok_flag = true; - return Ast.full.FnProto.Param{ + return .{ .first_doc_comment = first_doc_comment, .comptime_noalias = comptime_noalias, .name_token = name_token, @@ -1388,7 +1388,7 @@ pub fn nextFnParam(it: *Ast.full.FnProto.Iterator) ?Ast.full.FnProto.Param { switch (token_tags[it.tok_i]) { .ellipsis3 => { it.tok_flag = false; // Next iteration should return null. - return Ast.full.FnProto.Param{ + return .{ .first_doc_comment = first_doc_comment, .comptime_noalias = null, .name_token = null, @@ -1410,7 +1410,7 @@ pub fn nextFnParam(it: *Ast.full.FnProto.Iterator) ?Ast.full.FnProto.Param { } if (token_tags[it.tok_i] == .keyword_anytype) { it.tok_i += 1; - return Ast.full.FnProto.Param{ + return .{ .first_doc_comment = first_doc_comment, .comptime_noalias = comptime_noalias, .name_token = name_token, diff --git a/src/build_runner/master.zig b/src/build_runner/master.zig index 21efc98d5..476242253 100644 --- a/src/build_runner/master.zig +++ b/src/build_runner/master.zig @@ -115,7 +115,7 @@ pub fn main() !void { var thread_pool_options: std.Thread.Pool.Options = .{ .allocator = arena }; var install_prefix: ?[]const u8 = null; - var dir_list = std.Build.DirList{}; + var dir_list: std.Build.DirList = .{}; var max_rss: u64 = 0; var skip_oom_steps = false; var seed: u32 = 0; @@ -1364,7 +1364,7 @@ const copied_from_zig = struct { }; var code: u8 = undefined; - const stdout = if (b.runAllowFail(&[_][]const u8{ + const stdout = if (b.runAllowFail(&.{ "pkg-config", pkg_name, "--cflags", @@ -1384,22 +1384,22 @@ const copied_from_zig = struct { while (it.next()) |tok| { if (mem.eql(u8, tok, "-I")) { const dir = it.next() orelse return error.PkgConfigInvalidOutput; - try zig_args.appendSlice(&[_][]const u8{ "-I", dir }); + try zig_args.appendSlice(&.{ "-I", dir }); } else if (mem.startsWith(u8, tok, "-I")) { try zig_args.append(tok); } else if (mem.eql(u8, tok, "-L")) { const dir = it.next() orelse return error.PkgConfigInvalidOutput; - try zig_args.appendSlice(&[_][]const u8{ "-L", dir }); + try zig_args.appendSlice(&.{ "-L", dir }); } else if (mem.startsWith(u8, tok, "-L")) { try zig_args.append(tok); } else if (mem.eql(u8, tok, "-l")) { const lib = it.next() orelse return error.PkgConfigInvalidOutput; - try zig_args.appendSlice(&[_][]const u8{ "-l", lib }); + try zig_args.appendSlice(&.{ "-l", lib }); } else if (mem.startsWith(u8, tok, "-l")) { try zig_args.append(tok); } else if (mem.eql(u8, tok, "-D")) { const macro = it.next() orelse return error.PkgConfigInvalidOutput; - try zig_args.appendSlice(&[_][]const u8{ "-D", macro }); + try zig_args.appendSlice(&.{ "-D", macro }); } else if (mem.startsWith(u8, tok, "-D")) { try zig_args.append(tok); } else if (b.debug_pkg_config) { @@ -1411,14 +1411,14 @@ const copied_from_zig = struct { } fn execPkgConfigList(self: *std.Build, out_code: *u8) (std.Build.PkgConfigError || std.Build.RunError)![]const std.Build.PkgConfigPkg { - const stdout = try self.runAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore); + const stdout = try self.runAllowFail(&.{ "pkg-config", "--list-all" }, out_code, .Ignore); var list = ArrayList(std.Build.PkgConfigPkg).init(self.allocator); errdefer list.deinit(); var line_it = mem.tokenizeAny(u8, stdout, "\r\n"); while (line_it.next()) |line| { if (mem.trim(u8, line, " \t").len == 0) continue; var tok_it = mem.tokenizeAny(u8, line, " \t"); - try list.append(std.Build.PkgConfigPkg{ + try list.append(.{ .name = tok_it.next() orelse return error.PkgConfigInvalidOutput, .desc = tok_it.rest(), }); diff --git a/src/configuration.zig b/src/configuration.zig index 6c08af9ee..2fe3d9414 100644 --- a/src/configuration.zig +++ b/src/configuration.zig @@ -155,7 +155,7 @@ pub const Env = struct { pub fn getZigEnv(allocator: std.mem.Allocator, zig_exe_path: []const u8) ?std.json.Parsed(Env) { const zig_env_result = std.process.Child.run(.{ .allocator = allocator, - .argv = &[_][]const u8{ zig_exe_path, "env" }, + .argv = &.{ zig_exe_path, "env" }, }) catch { logger.err("Failed to execute zig env", .{}); return null; @@ -197,7 +197,7 @@ fn getConfigurationType() type { for (config_info.@"struct".fields, &fields) |field, *new_field| { new_field.* = field; if (@typeInfo(field.type) != .optional) { - new_field.type = @Type(std.builtin.Type{ + new_field.type = @Type(.{ .optional = .{ .child = field.type }, }); } @@ -223,7 +223,7 @@ pub fn findZig(allocator: std.mem.Allocator) error{OutOfMemory}!?[]const u8 { var it = std.mem.tokenizeScalar(u8, env_path, std.fs.path.delimiter); while (it.next()) |path| { - var full_path = try std.fs.path.join(allocator, &[_][]const u8{ path, zig_exe }); + var full_path = try std.fs.path.join(allocator, &.{ path, zig_exe }); defer allocator.free(full_path); if (!std.fs.path.isAbsolute(full_path)) { diff --git a/src/diff.zig b/src/diff.zig index f9f95bd34..98163a8f3 100644 --- a/src/diff.zig +++ b/src/diff.zig @@ -6,7 +6,7 @@ const offsets = @import("offsets.zig"); const tracy = @import("tracy"); const DiffMatchPatch = @import("diffz"); -const dmp = DiffMatchPatch{ +const dmp: DiffMatchPatch = .{ .diff_timeout = 250, }; diff --git a/src/features/code_actions.zig b/src/features/code_actions.zig index 09f9fb8ca..009ed221c 100644 --- a/src/features/code_actions.zig +++ b/src/features/code_actions.zig @@ -109,16 +109,16 @@ pub const Builder = struct { pub fn createTextEditLoc(self: *Builder, loc: offsets.Loc, new_text: []const u8) types.TextEdit { const range = offsets.locToRange(self.handle.tree.source, loc, self.offset_encoding); - return types.TextEdit{ .range = range, .newText = new_text }; + return .{ .range = range, .newText = new_text }; } pub fn createTextEditPos(self: *Builder, index: usize, new_text: []const u8) types.TextEdit { const position = offsets.indexToPosition(self.handle.tree.source, index, self.offset_encoding); - return types.TextEdit{ .range = .{ .start = position, .end = position }, .newText = new_text }; + return .{ .range = .{ .start = position, .end = position }, .newText = new_text }; } pub fn createWorkspaceEdit(self: *Builder, edits: []const types.TextEdit) error{OutOfMemory}!types.WorkspaceEdit { - var workspace_edit = types.WorkspaceEdit{ .changes = .{} }; + var workspace_edit: types.WorkspaceEdit = .{ .changes = .{} }; try workspace_edit.changes.?.map.putNoClobber(self.arena, self.handle.uri, try self.arena.dupe(types.TextEdit, edits)); return workspace_edit; @@ -218,7 +218,7 @@ pub fn generateMultilineStringCodeActions( offsets.tokenToLoc(builder.handle.tree, @intCast(end - 1)).end + 1, "\n\r", ) orelse builder.handle.tree.source.len; - const remove_loc = offsets.Loc{ .start = first_token_start, .end = last_token_end }; + const remove_loc: offsets.Loc = .{ .start = first_token_start, .end = last_token_end }; try actions.append(builder.arena, .{ .title = "convert to a string literal", @@ -296,7 +296,7 @@ fn handleNonCamelcaseFunction(builder: *Builder, actions: *std.ArrayListUnmanage const new_text = try createCamelcaseText(builder.arena, identifier_name); - const action1 = types.CodeAction{ + const action1: types.CodeAction = .{ .title = "make function name camelCase", .kind = .quickfix, .isPreferred = true, @@ -1064,15 +1064,15 @@ const DiagnosticKind = union(enum) { const msg = diagnostic_message; if (std.mem.startsWith(u8, msg, "unused ")) { - return DiagnosticKind{ + return .{ .unused = parseEnum(IdCat, msg["unused ".len..]) orelse return null, }; } else if (std.mem.startsWith(u8, msg, "pointless discard of ")) { - return DiagnosticKind{ + return .{ .pointless_discard = parseEnum(IdCat, msg["pointless discard of ".len..]) orelse return null, }; } else if (std.mem.startsWith(u8, msg, "discard of ")) { - return DiagnosticKind{ + return .{ .omit_discard = parseEnum(DiscardCat, msg["discard of ".len..]) orelse return null, }; } else if (std.mem.startsWith(u8, msg, "Functions should be camelCase")) { @@ -1156,7 +1156,7 @@ fn getDiscardLoc(text: []const u8, loc: offsets.Loc) ?offsets.Loc { } }; - return offsets.Loc{ + return .{ .start = start_position, .end = autofix_comment_end, }; diff --git a/src/features/completions.zig b/src/features/completions.zig index 72e547f6f..79cdf2939 100644 --- a/src/features/completions.zig +++ b/src/features/completions.zig @@ -132,7 +132,7 @@ fn typeToCompletion(builder: *Builder, ty: Analyser.Type) error{OutOfMemory}!voi ), .either => |either_entries| { for (either_entries) |entry| { - const entry_ty = Analyser.Type{ .data = entry.type_data, .is_type_val = ty.is_type_val }; + const entry_ty: Analyser.Type = .{ .data = entry.type_data, .is_type_val = ty.is_type_val }; try typeToCompletion(builder, entry_ty); } }, @@ -180,7 +180,7 @@ fn declToCompletion(builder: *Builder, decl_handle: Analyser.DeclWithHandle, opt const documentation: std.meta.FieldType(types.CompletionItem, .documentation) = .{ - .MarkupContent = types.MarkupContent{ + .MarkupContent = .{ .kind = if (builder.server.client_capabilities.completion_doc_supports_md) .markdown else .plaintext, .value = try std.mem.join(builder.arena, "\n\n", doc_comments.constSlice()), }, @@ -267,7 +267,7 @@ fn declToCompletion(builder: *Builder, decl_handle: Analyser.DeclWithHandle, opt .label = name, .kind = kind, .documentation = if (compile_error_message) |message| .{ - .MarkupContent = types.MarkupContent{ + .MarkupContent = .{ .kind = if (builder.server.client_capabilities.completion_doc_supports_md) .markdown else .plaintext, .value = message, }, @@ -775,7 +775,7 @@ fn completeFileSystemStringLiteral(builder: *Builder, pos_context: Analyser.Posi else label; - _ = try completions.getOrPut(builder.arena, types.CompletionItem{ + _ = try completions.getOrPut(builder.arena, .{ .label = label, .kind = if (entry.kind == .file) .File else .Folder, .detail = if (pos_context == .cinclude_string_literal) path else null, @@ -999,7 +999,7 @@ fn globalSetCompletions(builder: *Builder, kind: enum { error_set, enum_set }) e ); if (!gop.found_existing) { - gop.key_ptr.* = types.CompletionItem{ + gop.key_ptr.* = .{ .label = name, .detail = switch (kind) { .error_set => try std.fmt.allocPrint(builder.arena, "error.{}", .{std.zig.fmtId(name)}), @@ -1016,7 +1016,7 @@ fn globalSetCompletions(builder: *Builder, kind: enum { error_set, enum_set }) e if (gop.key_ptr.documentation == null) { if (try Analyser.getDocCommentsBeforeToken(builder.arena, dependency_handle.tree, identifier_token)) |documentation| { gop.key_ptr.documentation = .{ - .MarkupContent = types.MarkupContent{ + .MarkupContent = .{ // TODO check if client supports markdown .kind = .markdown, .value = documentation, @@ -1260,7 +1260,7 @@ fn getSwitchOrStructInitContext( // FIXME: This creates a 'blind spot' if the first node in a file is a .container_field_init if (upper_index == 0) return null; - return EnumLiteralContext{ + return .{ .likely = likely, .identifier_token_index = upper_index, .fn_arg_index = fn_arg_index, diff --git a/src/features/document_symbol.zig b/src/features/document_symbol.zig index 4d3adb9dd..50f64a17c 100644 --- a/src/features/document_symbol.zig +++ b/src/features/document_symbol.zig @@ -216,7 +216,7 @@ fn convertSymbolsInternal( .selectionRange = undefined, .children = convertSymbolsInternal(symbol.children.items, symbol_buffer, mappings), }; - mappings.appendSliceAssumeCapacity(&[4]offsets.multiple.IndexToPositionMapping{ + mappings.appendSliceAssumeCapacity(&.{ .{ .output = &out.range.start, .source_index = symbol.loc.start }, .{ .output = &out.selectionRange.start, .source_index = symbol.selection_loc.start }, .{ .output = &out.selectionRange.end, .source_index = symbol.selection_loc.end }, @@ -235,7 +235,7 @@ pub fn getDocumentSymbols( var root_symbols: std.ArrayListUnmanaged(Symbol) = .empty; var total_symbol_count: usize = 0; - var ctx = Context{ + var ctx: Context = .{ .arena = arena, .last_var_decl_name = null, .parent_node = 0, // root-node diff --git a/src/features/goto.zig b/src/features/goto.zig index 307c545db..d529b65a6 100644 --- a/src/features/goto.zig +++ b/src/features/goto.zig @@ -43,7 +43,7 @@ fn gotoDefinitionSymbol( const type_declaration = try decl_handle.typeDeclarationNode() orelse return null; const target_range = offsets.nodeToRange(type_declaration.handle.tree, type_declaration.node, offset_encoding); - return types.DefinitionLink{ + return .{ .originSelectionRange = name_range, .targetUri = type_declaration.handle.uri, .targetRange = target_range, @@ -53,7 +53,7 @@ fn gotoDefinitionSymbol( }; const target_range = offsets.tokenToRange(token_handle.handle.tree, token_handle.token, offset_encoding); - return types.DefinitionLink{ + return .{ .originSelectionRange = name_range, .targetUri = token_handle.handle.uri, .targetRange = target_range, @@ -130,13 +130,13 @@ fn gotoDefinitionBuiltin( const hash = handle.cimports.items(.hash)[index]; const result = document_store.cimports.get(hash) orelse return null; - const target_range = types.Range{ + const target_range: types.Range = .{ .start = .{ .line = 0, .character = 0 }, .end = .{ .line = 0, .character = 0 }, }; switch (result) { .failure => return null, - .success => |uri| return types.DefinitionLink{ + .success => |uri| return .{ .originSelectionRange = offsets.locToRange(handle.tree.source, name_loc, offset_encoding), .targetUri = uri, .targetRange = target_range, @@ -219,7 +219,7 @@ fn gotoDefinitionString( .start = .{ .line = 0, .character = 0 }, .end = .{ .line = 0, .character = 0 }, }; - return types.DefinitionLink{ + return .{ .originSelectionRange = offsets.locToRange(handle.tree.source, loc, offset_encoding), .targetUri = uri orelse return null, .targetRange = target_range, diff --git a/src/features/hover.zig b/src/features/hover.zig index 0a5ba46b4..a9c611e59 100644 --- a/src/features/hover.zig +++ b/src/features/hover.zig @@ -266,7 +266,7 @@ fn hoverDefinitionBuiltin( }, } - return types.Hover{ + return .{ .contents = .{ .MarkupContent = .{ .kind = markup_kind, diff --git a/src/offsets.zig b/src/offsets.zig index 29e421433..1ef72a959 100644 --- a/src/offsets.zig +++ b/src/offsets.zig @@ -723,7 +723,7 @@ pub fn locIntersect(a: Loc, b: Loc) bool { } test locIntersect { - const a = Loc{ .start = 2, .end = 5 }; + const a: Loc = .{ .start = 2, .end = 5 }; try std.testing.expect(locIntersect(a, .{ .start = 0, .end = 2 }) == false); try std.testing.expect(locIntersect(a, .{ .start = 1, .end = 3 }) == true); try std.testing.expect(locIntersect(a, .{ .start = 2, .end = 4 }) == true); @@ -739,7 +739,7 @@ pub fn locInside(inner: Loc, outer: Loc) bool { } test locInside { - const outer = Loc{ .start = 2, .end = 5 }; + const outer: Loc = .{ .start = 2, .end = 5 }; try std.testing.expect(locInside(.{ .start = 0, .end = 2 }, outer) == false); try std.testing.expect(locInside(.{ .start = 1, .end = 3 }, outer) == false); try std.testing.expect(locInside(.{ .start = 2, .end = 4 }, outer) == true); @@ -758,7 +758,7 @@ pub fn locMerge(a: Loc, b: Loc) Loc { } test locMerge { - const a = Loc{ .start = 2, .end = 5 }; + const a: Loc = .{ .start = 2, .end = 5 }; try std.testing.expectEqualDeep(locMerge(a, .{ .start = 0, .end = 2 }), Loc{ .start = 0, .end = 5 }); try std.testing.expectEqualDeep(locMerge(a, .{ .start = 1, .end = 3 }), Loc{ .start = 1, .end = 5 }); try std.testing.expectEqualDeep(locMerge(a, .{ .start = 2, .end = 4 }), Loc{ .start = 2, .end = 5 }); diff --git a/src/tools/config_gen.zig b/src/tools/config_gen.zig index 146e2fe8e..d052ffeb3 100644 --- a/src/tools/config_gen.zig +++ b/src/tools/config_gen.zig @@ -349,7 +349,7 @@ const Tokenizer = struct { }; fn next(self: *Tokenizer) Token { - var result = Token{ + var result: Token = .{ .id = .Eof, .start = self.index, .end = undefined, diff --git a/tests/ErrorBuilder.zig b/tests/ErrorBuilder.zig index fb79cbc51..fe25f3f58 100644 --- a/tests/ErrorBuilder.zig +++ b/tests/ErrorBuilder.zig @@ -219,7 +219,7 @@ fn write(context: FormatContext, writer: anytype) @TypeOf(writer).Error!void { try writer.print("{s}:\n", .{file_name}); } - var it = MsgItemIterator{ + var it: MsgItemIterator = .{ .source = file.source, .messages = file.messages.items, }; @@ -234,10 +234,10 @@ fn write(context: FormatContext, writer: anytype) @TypeOf(writer).Error!void { const line_loc = offsets.lineLocAtIndex(file.source, some_line_source_index); defer last_line_end = line_loc.end; - const unified_loc = if (builder.unified) |n| + const unified_loc: offsets.Loc = if (builder.unified) |n| offsets.multilineLocAtIndex(file.source, some_line_source_index, n) else - offsets.Loc{ + .{ .start = 0, .end = file.source.len, }; diff --git a/tests/helper.zig b/tests/helper.zig index 6faba7a0a..40db120f7 100644 --- a/tests/helper.zig +++ b/tests/helper.zig @@ -103,7 +103,7 @@ pub fn collectReplacePlaceholders(allocator: std.mem.Allocator, source: []const } try new_source.appendSlice(allocator, source[source_index..source.len]); - return CollectPlaceholdersResult{ + return .{ .locations = locations, .new_source = try new_source.toOwnedSlice(allocator), }; diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig index 38196357a..99793e015 100644 --- a/tests/lsp_features/completion.zig +++ b/tests/lsp_features/completion.zig @@ -4032,7 +4032,7 @@ fn testCompletionTextEdit( const TextEditOrInsertReplace = std.meta.Child(@TypeOf(completion_item.textEdit)); - const text_edit_or_insert_replace = completion_item.textEdit orelse blk: { + const text_edit_or_insert_replace: TextEditOrInsertReplace = completion_item.textEdit orelse blk: { var start_index: usize = cursor_idx; while (start_index > 0 and zls.Analyser.isSymbolChar(handle.tree.source[start_index - 1])) { start_index -= 1; @@ -4040,10 +4040,10 @@ fn testCompletionTextEdit( const start_position = offsets.indexToPosition(text, start_index, ctx.server.offset_encoding); - break :blk TextEditOrInsertReplace{ - .TextEdit = types.TextEdit{ + break :blk .{ + .TextEdit = .{ .newText = completion_item.insertText orelse completion_item.label, - .range = types.Range{ .start = start_position, .end = cursor_position }, + .range = .{ .start = start_position, .end = cursor_position }, }, }; }; @@ -4070,8 +4070,8 @@ fn testCompletionTextEdit( try std.testing.expect(offsets.positionInsideRange(cursor_position, insert_replace_edit.insert)); // text edit range must contain the cursor position try std.testing.expect(offsets.positionInsideRange(cursor_position, insert_replace_edit.replace)); // text edit range must contain the cursor position - const insert_text_edit = types.TextEdit{ .newText = insert_replace_edit.newText, .range = insert_replace_edit.insert }; - const replace_text_edit = types.TextEdit{ .newText = insert_replace_edit.newText, .range = insert_replace_edit.replace }; + const insert_text_edit: types.TextEdit = .{ .newText = insert_replace_edit.newText, .range = insert_replace_edit.insert }; + const replace_text_edit: types.TextEdit = .{ .newText = insert_replace_edit.newText, .range = insert_replace_edit.replace }; const actual_insert_text = try zls.diff.applyTextEdits(allocator, text, &.{insert_text_edit}, ctx.server.offset_encoding); defer allocator.free(actual_insert_text); diff --git a/tests/lsp_features/inlay_hints.zig b/tests/lsp_features/inlay_hints.zig index cbd2d1970..bf9d71aa3 100644 --- a/tests/lsp_features/inlay_hints.zig +++ b/tests/lsp_features/inlay_hints.zig @@ -526,7 +526,7 @@ fn testInlayHints(source: []const u8, options: Options) !void { const test_uri = try ctx.addDocument(.{ .source = phr.new_source }); const range: types.Range = .{ - .start = types.Position{ .line = 0, .character = 0 }, + .start = .{ .line = 0, .character = 0 }, .end = offsets.indexToPosition(phr.new_source, phr.new_source.len, .@"utf-16"), }; diff --git a/tests/lsp_features/selection_range.zig b/tests/lsp_features/selection_range.zig index 45e484c7d..f4de86fda 100644 --- a/tests/lsp_features/selection_range.zig +++ b/tests/lsp_features/selection_range.zig @@ -42,7 +42,7 @@ fn testSelectionRange(source: []const u8, want: []const []const u8) !void { const params: types.SelectionRangeParams = .{ .textDocument = .{ .uri = test_uri }, - .positions = &[_]types.Position{position}, + .positions = &.{position}, }; const response = try ctx.server.sendRequestSync(ctx.arena.allocator(), "textDocument/selectionRange", params); diff --git a/tests/utility/ast.zig b/tests/utility/ast.zig index 61356495b..1f8706559 100644 --- a/tests/utility/ast.zig +++ b/tests/utility/ast.zig @@ -79,8 +79,8 @@ fn testNodesAtLoc(source: []const u8) !void { std.debug.assert(std.mem.eql(u8, offsets.locToSlice(source, old_locs[2]), "")); std.debug.assert(std.mem.eql(u8, offsets.locToSlice(source, old_locs[3]), "")); - const inner_loc = offsets.Loc{ .start = locs[1].start, .end = locs[2].start }; - const outer_loc = offsets.Loc{ .start = locs[0].start, .end = locs[3].end }; + const inner_loc: offsets.Loc = .{ .start = locs[1].start, .end = locs[2].start }; + const outer_loc: offsets.Loc = .{ .start = locs[0].start, .end = locs[3].end }; const new_source = try allocator.dupeZ(u8, ccp.new_source); defer allocator.free(new_source); @@ -91,7 +91,7 @@ fn testNodesAtLoc(source: []const u8) !void { const nodes = try ast.nodesAtLoc(allocator, tree, inner_loc); defer allocator.free(nodes); - const actual_loc = offsets.Loc{ + const actual_loc: offsets.Loc = .{ .start = offsets.nodeToLoc(tree, nodes[0]).start, .end = offsets.nodeToLoc(tree, nodes[nodes.len - 1]).end, };