summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-10-28 05:29:44 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-10-28 05:50:38 -0400
commit23f9be141bb0f7dc5eb35f395d5cf4011edac836 (patch)
tree0a49750e76553865431aa4803eee5e4b993e2eb0
parentffb7b58d3841cf50103ab21148b814a3ad29afa4 (diff)
Correctly resolve enum types that are array values
-rw-r--r--src/server/analysis.odin29
-rw-r--r--tests/completions_test.odin18
2 files changed, 41 insertions, 6 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 32d38eb..8cd75d6 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -2287,12 +2287,29 @@ resolve_implicit_selector_comp_literal :: proc(
return resolve_type_expression(ast_context, type)
case SymbolFixedArrayValue:
- //This will be a comp_lit for an enumerated array
- //EnumIndexedArray :: [TestEnum]u32 {
- // .valueOne = 1,
- // .valueTwo = 2,
- //}
- return resolve_type_expression(ast_context, v.len)
+ if position_in_node(v.len, position_context.position) {
+ return resolve_type_expression(ast_context, v.len)
+ } else if position_in_node(v.expr, position_context.position) {
+ return resolve_type_expression(ast_context, v.expr)
+ }
+ if _, _, ok := unwrap_enum(ast_context, v.len); ok {
+ for elem in comp_lit.elems {
+ if position_in_node(elem, position_context.position) {
+ if field, ok := elem.derived.(^ast.Field_Value); ok {
+ if position_in_node(field.field, position_context.position) {
+ return resolve_type_expression(ast_context, v.len)
+ }
+ return resolve_type_expression(ast_context, v.expr)
+ }
+ return resolve_type_expression(ast_context, v.len)
+ }
+ }
+ }
+ return resolve_type_expression(ast_context, v.expr)
+ case SymbolSliceValue:
+ return resolve_type_expression(ast_context, v.expr)
+ case SymbolDynamicArrayValue:
+ return resolve_type_expression(ast_context, v.expr)
case SymbolMapValue:
for elem in comp_lit.elems {
if position_in_node(elem, position_context.position) {
diff --git a/tests/completions_test.odin b/tests/completions_test.odin
index 01f718b..7b12828 100644
--- a/tests/completions_test.odin
+++ b/tests/completions_test.odin
@@ -4828,3 +4828,21 @@ ast_completion_named_proc_arg_comp_lit :: proc(t: ^testing.T) {
}
test.expect_completion_docs(t, &source, "", {"Bar.bar: int"})
}
+
+@(test)
+ast_completion_fixed_array_enum :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ Foo :: enum {
+ A,
+ B,
+ C,
+ }
+
+ foos := [3]Foo {
+ .{*}
+ }
+ `,
+ }
+ test.expect_completion_docs(t, &source, "", {"A", "B", "C"})
+}