aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Saxe <NathanielSaxophone@gmail.com>2026-01-30 00:39:02 -0500
committerNathaniel Saxe <NathanielSaxophone@gmail.com>2026-01-30 00:39:02 -0500
commitdc0196b01092768689e2bc943a011440ae99119a (patch)
tree0c53214e0319b0f08a7d9344937aaf1de22f1879
parenteea11e9d1e3035b89351cd888b35b920a40de81b (diff)
more or less handle union types - TODO in appropriate places on why not completely handled
-rw-r--r--src/server/action.odin14
-rw-r--r--src/server/completion.odin3
2 files changed, 13 insertions, 4 deletions
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