From dc0196b01092768689e2bc943a011440ae99119a Mon Sep 17 00:00:00 2001 From: Nathaniel Saxe Date: Fri, 30 Jan 2026 00:39:02 -0500 Subject: more or less handle union types - TODO in appropriate places on why not completely handled --- src/server/action.odin | 14 +++++++++++--- src/server/completion.odin | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/server/action.odin b/src/server/action.odin index 2099950..d5b4a90 100644 --- a/src/server/action.odin +++ b/src/server/action.odin @@ -239,8 +239,10 @@ get_switch_cases_info :: proc( break } } else { - if ident, ok := name.derived.(^ast.Ident); ok { - case_name = ident.name + if ty, ok := resolve_type_expression(ast_context, name); ok { + //TODO: this is wrong for anonymous enums and structs, where the name field is "enum" or "struct" respectively but we want to use the full signature + //we also can't use the signature all the time because type aliases need to use specifically the alias name here and not the signature + case_name = ty.name != "" ? ty.name : get_signature(ast_context, ty) break } } @@ -260,7 +262,13 @@ get_switch_cases_info :: proc( if !unwrap_ok {return nil, nil, false, false} case_names := make([]string, len(union_value.types), context.temp_allocator) for t, i in union_value.types { - case_names[i] = t.derived.(^ast.Ident).name + if ty, ok := resolve_type_expression(ast_context, t); ok { + //TODO: this is wrong for anonymous enums and structs, where the name field is "enum" or "struct" respectively but we want to use the full signature + //we also can't use the signature all the time because type aliases need to use specifically the alias name here and not the signature + case_names[i] = ty.name != "" ? ty.name : get_signature(ast_context, ty) + } else { + case_names[i] = "invalid type expression" + } } return existing_cases, case_names, false, true } diff --git a/src/server/completion.odin b/src/server/completion.odin index 31ecf0e..1fbae93 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1974,7 +1974,8 @@ get_type_switch_completion :: proc( if union_value, ok := unwrap_union(ast_context, assign.rhs[0]); ok { for type, i in union_value.types { if symbol, ok := resolve_type_expression(ast_context, union_value.types[i]); ok { - + //TODO: using symbol.name is wrong for anonymous enums and structs, where the name field is "enum" or "struct" respectively but we want to use the full signature + //we also can't use the signature all the time because type aliases need to use specifically the alias name here and not the signature name := symbol.name if _, ok := used_unions[name]; ok { continue -- cgit v1.2.3