From 4a78b4ad1dca9a1218c4df2d97bfb5d9465bc063 Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Sun, 6 Jul 2025 20:47:27 -0400 Subject: Correctly filter used unions when ptr --- src/server/completion.odin | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/server/completion.odin b/src/server/completion.odin index 13a589d..a84631f 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1581,6 +1581,18 @@ search_for_packages :: proc(fullpath: string) -> []string { return packages[:] } +get_used_switch_name :: proc(node: ^ast.Expr) -> (string, bool) { + #partial switch n in node.derived { + case ^ast.Ident: + return n.name, true + case ^ast.Selector_Expr: + return n.field.name, true + case ^ast.Pointer_Type: + return get_used_switch_name(n.elem) + } + return "", false +} + get_type_switch_completion :: proc( ast_context: ^AstContext, position_context: ^DocumentPositionContext, @@ -1595,10 +1607,8 @@ get_type_switch_completion :: proc( for stmt in block.stmts { if case_clause, ok := stmt.derived.(^ast.Case_Clause); ok { for name in case_clause.list { - if ident, ok := name.derived.(^ast.Ident); ok { - used_unions[ident.name] = true - } else if selector, ok := name.derived.(^ast.Selector_Expr); ok { - used_unions[selector.field.name] = true + if n, ok := get_used_switch_name(name); ok { + used_unions[n] = true } } } -- cgit v1.2.3