diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-02 20:24:59 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-02 20:24:59 -0400 |
| commit | 26bb60d1441bbc133dbe5d4df8e4b78d79b0b479 (patch) | |
| tree | 4ed4486361d9b77cc55c29fe0830654f3b7531d2 | |
| parent | 4ec40cec010b4c8c28fe4bb428c6b53a089a7d30 (diff) | |
Add completions for enum slice elements
| -rw-r--r-- | src/server/analysis.odin | 15 | ||||
| -rw-r--r-- | 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"}) +} |