From 26bb60d1441bbc133dbe5d4df8e4b78d79b0b479 Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Wed, 2 Jul 2025 20:24:59 -0400 Subject: Add completions for enum slice elements --- src/server/analysis.odin | 15 +++++++++++---- tests/completions_test.odin | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index e7496da..9f7018f 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -3830,10 +3830,17 @@ unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (SymbolEnumVal } if enum_symbol, ok := resolve_type_expression(ast_context, node); ok { - if enum_value, ok := enum_symbol.value.(SymbolEnumValue); ok { - return enum_value, true - } else if union_value, ok := enum_symbol.value.(SymbolUnionValue); ok { - return unwrap_super_enum(ast_context, union_value) + #partial switch value in enum_symbol.value { + case SymbolEnumValue: + return value, true + case SymbolUnionValue: + return unwrap_super_enum(ast_context, value) + case SymbolSliceValue: + return unwrap_enum(ast_context, value.expr) + case SymbolFixedArrayValue: + return unwrap_enum(ast_context, value.expr) + case SymbolDynamicArrayValue: + return unwrap_enum(ast_context, value.expr) } } diff --git a/tests/completions_test.odin b/tests/completions_test.odin index ae3b023..e0edb78 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -3481,3 +3481,19 @@ ast_completion_poly_proc_mixed_packages :: proc(t: ^testing.T) { test.expect_completion_details(t, &source, "", {"Bar.bar: int"}) } + +@(test) +ast_completion_enum_slice :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + E :: enum { A, B } + Eslice :: []E + + main :: proc() { + a: Eslice = { .{*} } + } + `, + } + + test.expect_completion_details(t, &source, "", {"A", "B"}) +} -- cgit v1.2.3 From 5348ee2fc5b7609e58baaa835b4fb55d5c13fc3e Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Wed, 2 Jul 2025 21:03:35 -0400 Subject: Exclude already added enum fields when adding multiple to a bitset --- src/server/completion.odin | 20 +++++++++++++++----- tests/completions_test.odin | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/server/completion.odin b/src/server/completion.odin index 6a172ef..80c5ae1 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -727,6 +727,7 @@ get_implicit_completion :: proc( //value decl infer a : My_Enum = .* if position_context.value_decl != nil && position_context.value_decl.type != nil { enum_value: Maybe(SymbolEnumValue) + exclude_names := make([dynamic]string, context.temp_allocator) if _enum_value, ok := unwrap_enum(ast_context, position_context.value_decl.type); ok { enum_value = _enum_value @@ -739,16 +740,25 @@ get_implicit_completion :: proc( enum_value = _enum_value } } + for elem in position_context.comp_lit.elems { + if expr, ok := elem.derived.(^ast.Implicit_Selector_Expr); ok { + if expr.field.name != "_" { + append(&exclude_names, expr.field.name) + } + } + } } if ev, ok := enum_value.?; ok { for name in ev.names { - item := CompletionItem { - label = name, - kind = .EnumMember, - detail = name, + if !slice.contains(exclude_names[:], name) { + item := CompletionItem { + label = name, + kind = .EnumMember, + detail = name, + } + append(&items, item) } - append(&items, item) } list.items = items[:] diff --git a/tests/completions_test.odin b/tests/completions_test.odin index e0edb78..a9c3f7b 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -3497,3 +3497,21 @@ ast_completion_enum_slice :: proc(t: ^testing.T) { test.expect_completion_details(t, &source, "", {"A", "B"}) } + +@(test) +ast_completion_bitset :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + E :: enum { A, B, C } + + Ebitset :: bit_set[E] + + main :: proc() { + b: Ebitset = { .A, .C, .{*} } + } + `, + } + + // I think this test will pass even if there is A and C + test.expect_completion_details(t, &source, "", {"B"}) +} -- cgit v1.2.3