From 9f9bf9eba87f6bc3c419f0cac0742f6e04f7854d Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 29 May 2023 23:59:20 +0200 Subject: [PATCH] include enum fields in enum completion set --- src/analysis.zig | 7 +++++-- tests/lsp_features/completion.zig | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 335fecb..10fcca2 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -2657,6 +2657,7 @@ fn makeInnerScope(context: ScopeContext, tree: Ast, node_idx: Ast.Node.Index) er const allocator = context.allocator; const scopes = &context.doc_scope.scopes; const tags = tree.nodes.items(.tag); + const token_tags = tree.tokens.items(.tag); const scope_index = try context.pushScope( 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 }); - 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; const doc = try getDocComments(allocator, tree, decl, .markdown); errdefer if (doc) |d| allocator.free(d); var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{ .label = name, - .kind = .Constant, + .kind = .Enum, .insertText = name, .insertTextFormat = .PlainText, .documentation = if (doc) |d| .{ .MarkupContent = types.MarkupContent{ .kind = .markdown, .value = d } } else null, diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig index d18dfa5..e31916b 100644 --- a/tests/lsp_features/completion.zig +++ b/tests/lsp_features/completion.zig @@ -300,6 +300,16 @@ test "completion - enum" { .{ .label = "alpha", .kind = .Enum }, .{ .label = "beta", .kind = .Enum }, }); + try testCompletion( + \\const E = enum { + \\ alpha, + \\ beta, + \\}; + \\const foo: E = . + , &.{ + .{ .label = "alpha", .kind = .Enum }, + .{ .label = "beta", .kind = .Enum }, + }); } test "completion - error union" {