From c44608723179b9938fee50c4b958d9a845a9dd8a Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 9 Jun 2023 23:35:27 +0200 Subject: [PATCH] set Enum completion kind to .EnumMember --- src/analyser/completions.zig | 2 +- src/analysis.zig | 2 +- src/features/completions.zig | 7 ++++--- tests/lsp_features/completion.zig | 8 ++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/analyser/completions.zig b/src/analyser/completions.zig index 09d6bcd..b97b9ce 100644 --- a/src/analyser/completions.zig +++ b/src/analyser/completions.zig @@ -51,7 +51,7 @@ pub fn dotCompletions( while (field_it.next()) |entry| { try completions.append(arena, .{ .label = entry.key_ptr.*, - .kind = .Constant, + .kind = .EnumMember, // include field.val? }); } diff --git a/src/analysis.zig b/src/analysis.zig index 10fcca2..567f6a6 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -2701,7 +2701,7 @@ fn makeInnerScope(context: ScopeContext, tree: Ast, node_idx: Ast.Node.Index) er errdefer if (doc) |d| allocator.free(d); var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{ .label = name, - .kind = .Enum, + .kind = .EnumMember, .insertText = name, .insertTextFormat = .PlainText, .documentation = if (doc) |d| .{ .MarkupContent = types.MarkupContent{ .kind = .markdown, .value = d } } else null, diff --git a/src/features/completions.zig b/src/features/completions.zig index fff1751..013dbe9 100644 --- a/src/features/completions.zig +++ b/src/features/completions.zig @@ -223,7 +223,7 @@ fn nodeToCompletion( const field = tree.fullContainerField(node).?; try list.append(allocator, .{ .label = handle.tree.tokenSlice(field.ast.main_token), - .kind = if (field.ast.tuple_like) .Enum else .Field, + .kind = if (field.ast.tuple_like) .EnumMember else .Field, .documentation = doc, .detail = Analyser.getContainerFieldSignature(handle.tree, field), .insertText = tree.tokenSlice(field.ast.main_token), @@ -729,6 +729,7 @@ fn kindToSortScore(kind: types.CompletionItemKind) ?[]const u8 { .Class, .Interface, .Struct, + .Enum, // Union? .TypeParameter, => "6_", @@ -757,7 +758,7 @@ pub fn addStructInitNodeFields(server: *Server, decl: Analyser.DeclWithHandle, c const field = decl.handle.tree.fullContainerField(member) orelse continue; try completions.append(server.arena.allocator(), .{ .label = decl.handle.tree.tokenSlice(field.ast.main_token), - .kind = if (field.ast.tuple_like) .Enum else .Field, + .kind = if (field.ast.tuple_like) .EnumMember else .Field, .detail = Analyser.getContainerFieldSignature(decl.handle.tree, field), .insertText = decl.handle.tree.tokenSlice(field.ast.main_token), .insertTextFormat = .PlainText, @@ -770,7 +771,7 @@ pub fn addStructInitNodeFields(server: *Server, decl: Analyser.DeclWithHandle, c const field = decl.handle.tree.fullContainerField(@intCast(u32, root_node)) orelse continue; try completions.append(server.arena.allocator(), .{ .label = decl.handle.tree.tokenSlice(field.ast.main_token), - .kind = if (field.ast.tuple_like) .Enum else .Field, + .kind = if (field.ast.tuple_like) .EnumMember else .Field, .detail = Analyser.getContainerFieldSignature(decl.handle.tree, field), .insertText = decl.handle.tree.tokenSlice(field.ast.main_token), .insertTextFormat = .PlainText, diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig index e31916b..8069a4f 100644 --- a/tests/lsp_features/completion.zig +++ b/tests/lsp_features/completion.zig @@ -297,8 +297,8 @@ test "completion - enum" { \\}; \\const foo = E. , &.{ - .{ .label = "alpha", .kind = .Enum }, - .{ .label = "beta", .kind = .Enum }, + .{ .label = "alpha", .kind = .EnumMember }, + .{ .label = "beta", .kind = .EnumMember }, }); try testCompletion( \\const E = enum { @@ -307,8 +307,8 @@ test "completion - enum" { \\}; \\const foo: E = . , &.{ - .{ .label = "alpha", .kind = .Enum }, - .{ .label = "beta", .kind = .Enum }, + .{ .label = "alpha", .kind = .EnumMember }, + .{ .label = "beta", .kind = .EnumMember }, }); }