diff options
| -rw-r--r-- | src/server/analysis.odin | 9 | ||||
| -rw-r--r-- | tests/completions_test.odin | 46 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index e9e5d30..ef97a80 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2031,6 +2031,15 @@ resolve_implicit_selector_comp_literal :: proc( // .valueTwo = 2, //} return resolve_type_expression(ast_context, v.len) + case SymbolMapValue: + for elem in comp_lit.elems { + if position_in_node(elem, position_context.position) { + if _, ok := elem.derived.(^ast.Field_Value); ok { + return resolve_type_expression(ast_context, v.value) + } + return resolve_type_expression(ast_context, v.key) + } + } } } return {}, false diff --git a/tests/completions_test.odin b/tests/completions_test.odin index ca1d5a5..339b195 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -4343,3 +4343,49 @@ ast_completion_within_struct_decl :: proc(t: ^testing.T) { } test.expect_completion_docs( t, &source, "", {"test.Foo: enum {..}"}, {"test.foo: proc(f: Foo)"}) } + +@(test) +ast_completion_enum_map_key_global :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + E :: enum { A, B, C } + + m: map[E]int = { + .{*} + } + `, + } + + test.expect_completion_docs(t, &source, "", {"A", "B", "C"}) +} + +@(test) +ast_completion_enum_map_key_global_with_value :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + E :: enum { A, B, C } + + m: map[E]int = { + .{*} = 0, + } + `, + } + + test.expect_completion_docs(t, &source, "", {"A", "B", "C"}) +} + +@(test) +ast_completion_enum_map_value_global :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + E :: enum { A, B, C } + + m: map[int]E = { + 0 = .A, + 1 = .{*} + } + `, + } + + test.expect_completion_docs(t, &source, "", {"A", "B", "C"}) +} |