Merge pull request #1233 from Techatrix/enum-completion

set Enum completion kind to .EnumMember
This commit is contained in:
Lee Cannon 2023-06-09 23:20:42 +01:00 committed by GitHub
commit 4d0e1afb72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 9 deletions

View File

@ -51,7 +51,7 @@ pub fn dotCompletions(
while (field_it.next()) |entry| { while (field_it.next()) |entry| {
try completions.append(arena, .{ try completions.append(arena, .{
.label = entry.key_ptr.*, .label = entry.key_ptr.*,
.kind = .Constant, .kind = .EnumMember,
// include field.val? // include field.val?
}); });
} }

View File

@ -2702,7 +2702,7 @@ fn makeInnerScope(context: ScopeContext, tree: Ast, node_idx: Ast.Node.Index) er
errdefer if (doc) |d| allocator.free(d); errdefer if (doc) |d| allocator.free(d);
var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{ var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{
.label = name, .label = name,
.kind = .Enum, .kind = .EnumMember,
.insertText = name, .insertText = name,
.insertTextFormat = .PlainText, .insertTextFormat = .PlainText,
.documentation = if (doc) |d| .{ .MarkupContent = types.MarkupContent{ .kind = .markdown, .value = d } } else null, .documentation = if (doc) |d| .{ .MarkupContent = types.MarkupContent{ .kind = .markdown, .value = d } } else null,

View File

@ -223,7 +223,7 @@ fn nodeToCompletion(
const field = tree.fullContainerField(node).?; const field = tree.fullContainerField(node).?;
try list.append(allocator, .{ try list.append(allocator, .{
.label = handle.tree.tokenSlice(field.ast.main_token), .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, .documentation = doc,
.detail = Analyser.getContainerFieldSignature(handle.tree, field), .detail = Analyser.getContainerFieldSignature(handle.tree, field),
.insertText = tree.tokenSlice(field.ast.main_token), .insertText = tree.tokenSlice(field.ast.main_token),
@ -729,6 +729,7 @@ fn kindToSortScore(kind: types.CompletionItemKind) ?[]const u8 {
.Class, .Class,
.Interface, .Interface,
.Struct, .Struct,
.Enum,
// Union? // Union?
.TypeParameter, .TypeParameter,
=> "6_", => "6_",
@ -757,7 +758,7 @@ pub fn addStructInitNodeFields(server: *Server, decl: Analyser.DeclWithHandle, c
const field = decl.handle.tree.fullContainerField(member) orelse continue; const field = decl.handle.tree.fullContainerField(member) orelse continue;
try completions.append(server.arena.allocator(), .{ try completions.append(server.arena.allocator(), .{
.label = decl.handle.tree.tokenSlice(field.ast.main_token), .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), .detail = Analyser.getContainerFieldSignature(decl.handle.tree, field),
.insertText = decl.handle.tree.tokenSlice(field.ast.main_token), .insertText = decl.handle.tree.tokenSlice(field.ast.main_token),
.insertTextFormat = .PlainText, .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; const field = decl.handle.tree.fullContainerField(@intCast(u32, root_node)) orelse continue;
try completions.append(server.arena.allocator(), .{ try completions.append(server.arena.allocator(), .{
.label = decl.handle.tree.tokenSlice(field.ast.main_token), .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), .detail = Analyser.getContainerFieldSignature(decl.handle.tree, field),
.insertText = decl.handle.tree.tokenSlice(field.ast.main_token), .insertText = decl.handle.tree.tokenSlice(field.ast.main_token),
.insertTextFormat = .PlainText, .insertTextFormat = .PlainText,

View File

@ -297,8 +297,8 @@ test "completion - enum" {
\\}; \\};
\\const foo = E.<cursor> \\const foo = E.<cursor>
, &.{ , &.{
.{ .label = "alpha", .kind = .Enum }, .{ .label = "alpha", .kind = .EnumMember },
.{ .label = "beta", .kind = .Enum }, .{ .label = "beta", .kind = .EnumMember },
}); });
try testCompletion( try testCompletion(
\\const E = enum { \\const E = enum {
@ -307,8 +307,8 @@ test "completion - enum" {
\\}; \\};
\\const foo: E = .<cursor> \\const foo: E = .<cursor>
, &.{ , &.{
.{ .label = "alpha", .kind = .Enum }, .{ .label = "alpha", .kind = .EnumMember },
.{ .label = "beta", .kind = .Enum }, .{ .label = "beta", .kind = .EnumMember },
}); });
} }