include enum fields in enum completion set

This commit is contained in:
Techatrix 2023-05-29 23:59:20 +02:00
parent a6f7e80ea3
commit 9f9bf9eba8
2 changed files with 15 additions and 2 deletions

View File

@ -2657,6 +2657,7 @@ fn makeInnerScope(context: ScopeContext, tree: Ast, node_idx: Ast.Node.Index) er
const allocator = context.allocator; const allocator = context.allocator;
const scopes = &context.doc_scope.scopes; const scopes = &context.doc_scope.scopes;
const tags = tree.nodes.items(.tag); const tags = tree.nodes.items(.tag);
const token_tags = tree.tokens.items(.tag);
const scope_index = try context.pushScope( const scope_index = try context.pushScope(
offsets.nodeToLoc(tree, node_idx), offsets.nodeToLoc(tree, node_idx),
@ -2691,14 +2692,16 @@ fn makeInnerScope(context: ScopeContext, tree: Ast, node_idx: Ast.Node.Index) er
try context.putDecl(scope_index, name, .{ .ast_node = decl }); try context.putDecl(scope_index, name, .{ .ast_node = decl });
if (container_decl.ast.enum_token != null) { if ((node_idx != 0 and token_tags[container_decl.ast.main_token] == .keyword_enum) or
container_decl.ast.enum_token != null)
{
if (std.mem.eql(u8, name, "_")) return; if (std.mem.eql(u8, name, "_")) return;
const doc = try getDocComments(allocator, tree, decl, .markdown); const doc = try getDocComments(allocator, tree, decl, .markdown);
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 = .Constant, .kind = .Enum,
.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

@ -300,6 +300,16 @@ test "completion - enum" {
.{ .label = "alpha", .kind = .Enum }, .{ .label = "alpha", .kind = .Enum },
.{ .label = "beta", .kind = .Enum }, .{ .label = "beta", .kind = .Enum },
}); });
try testCompletion(
\\const E = enum {
\\ alpha,
\\ beta,
\\};
\\const foo: E = .<cursor>
, &.{
.{ .label = "alpha", .kind = .Enum },
.{ .label = "beta", .kind = .Enum },
});
} }
test "completion - error union" { test "completion - error union" {