Skip to content

Commit

Permalink
Set completion labelDetails if supported and applicable (#2067)
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbangsheshotmedown authored Oct 27, 2024
1 parent cd4dc1b commit b2e89df
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ fn declToCompletion(builder: *Builder, decl_handle: Analyser.DeclWithHandle, opt
}
}

const detail = if (maybe_resolved_ty) |ty| blk: {
if (ty.is_type_val and ty.data == .ip_index and !builder.analyser.ip.isUnknown(ty.data.ip_index.index)) {
break :blk try std.fmt.allocPrint(builder.arena, "{}", .{ty.fmtTypeVal(builder.analyser, .{ .truncate_container_decls = false })});
} else {
break :blk try std.fmt.allocPrint(builder.arena, "{}", .{ty.fmt(builder.analyser, .{ .truncate_container_decls = false })});
}
} else null;

const label_details: ?types.CompletionItemLabelDetails = blk: {
if (!builder.server.client_capabilities.label_details_support) break :blk null;

break :blk .{ .description = detail };
};

builder.completions.appendAssumeCapacity(.{
.label = name,
.kind = kind,
Expand All @@ -264,13 +278,8 @@ fn declToCompletion(builder: *Builder, decl_handle: Analyser.DeclWithHandle, opt
.value = message,
},
} else documentation,
.detail = if (maybe_resolved_ty) |ty| blk: {
if (ty.is_type_val and ty.data == .ip_index and !builder.analyser.ip.isUnknown(ty.data.ip_index.index)) {
break :blk try std.fmt.allocPrint(builder.arena, "{}", .{ty.fmtTypeVal(builder.analyser, .{ .truncate_container_decls = false })});
} else {
break :blk try std.fmt.allocPrint(builder.arena, "{}", .{ty.fmt(builder.analyser, .{ .truncate_container_decls = false })});
}
} else null,
.detail = detail,
.labelDetails = label_details,
.deprecated = if (compile_error_message != null and builder.server.client_capabilities.supports_completion_deprecated_old) true else null,
.tags = if (compile_error_message != null and builder.server.client_capabilities.supports_completion_deprecated_tag) &.{.Deprecated} else null,
});
Expand Down

0 comments on commit b2e89df

Please sign in to comment.