diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-02 21:03:35 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-02 21:04:23 -0400 |
| commit | 5348ee2fc5b7609e58baaa835b4fb55d5c13fc3e (patch) | |
| tree | 79b2170876a8492f7a427c637b3407eedfd9c48a | |
| parent | 26bb60d1441bbc133dbe5d4df8e4b78d79b0b479 (diff) | |
Exclude already added enum fields when adding multiple to a bitset
| -rw-r--r-- | src/server/completion.odin | 20 | ||||
| -rw-r--r-- | 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"}) +} |