enum, union
This commit is contained in:
@@ -553,7 +553,7 @@ pub const Server = struct {
|
||||
.union_decl => |ud| {
|
||||
try items.append(allocator, .{
|
||||
.label = ud.name,
|
||||
.kind = @intFromEnum(lsp.CompletionItemKind.Enum),
|
||||
.kind = @intFromEnum(lsp.CompletionItemKind.Struct),
|
||||
});
|
||||
},
|
||||
.var_decl => |vd| {
|
||||
@@ -602,7 +602,7 @@ pub const Server = struct {
|
||||
if (sx.sema.findNodeAtOffset(lookup_root, sym.def_span.start)) |node| {
|
||||
if (node.data == .enum_decl) {
|
||||
const ed = node.data.enum_decl;
|
||||
for (ed.variants) |variant| {
|
||||
for (ed.variant_names) |variant| {
|
||||
try items.append(self.allocator, .{
|
||||
.label = variant,
|
||||
.kind = @intFromEnum(lsp.CompletionItemKind.EnumMember),
|
||||
@@ -1212,7 +1212,7 @@ pub const Server = struct {
|
||||
if (sx.sema.findNodeAtOffset(lookup_root, sym.def_span.start)) |node| {
|
||||
if (node.data == .enum_decl) {
|
||||
const ed = node.data.enum_decl;
|
||||
for (ed.variants) |v| {
|
||||
for (ed.variant_names) |v| {
|
||||
if (!std.mem.eql(u8, v, variant_name)) continue;
|
||||
|
||||
var buf = std.ArrayList(u8).empty;
|
||||
@@ -1633,7 +1633,7 @@ pub const Server = struct {
|
||||
.enum_decl => |ed| {
|
||||
try buf.appendSlice(allocator, ed.name);
|
||||
try buf.appendSlice(allocator, " :: enum { ");
|
||||
for (ed.variants, 0..) |v, i| {
|
||||
for (ed.variant_names, 0..) |v, i| {
|
||||
if (i > 0) try buf.appendSlice(allocator, ", ");
|
||||
try buf.append(allocator, '.');
|
||||
try buf.appendSlice(allocator, v);
|
||||
@@ -1658,9 +1658,24 @@ pub const Server = struct {
|
||||
.union_decl => |ud| {
|
||||
try buf.appendSlice(allocator, ud.name);
|
||||
try buf.appendSlice(allocator, " :: union { ");
|
||||
for (ud.variant_names, 0..) |vn, i| {
|
||||
for (ud.field_names, 0..) |fn_name, i| {
|
||||
if (i > 0) try buf.appendSlice(allocator, ", ");
|
||||
try buf.appendSlice(allocator, vn);
|
||||
// Anonymous struct fields: show as "struct { ... }"
|
||||
if (std.mem.startsWith(u8, fn_name, "__anon_")) {
|
||||
if (i < ud.field_types.len and ud.field_types[i].data == .type_expr) {
|
||||
try buf.appendSlice(allocator, ud.field_types[i].data.type_expr.name);
|
||||
} else {
|
||||
try buf.appendSlice(allocator, "struct { ... }");
|
||||
}
|
||||
} else {
|
||||
try buf.appendSlice(allocator, fn_name);
|
||||
if (i < ud.field_types.len) {
|
||||
try buf.appendSlice(allocator, ": ");
|
||||
if (ud.field_types[i].data == .type_expr) {
|
||||
try buf.appendSlice(allocator, ud.field_types[i].data.type_expr.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try buf.appendSlice(allocator, " }");
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user