aboutsummaryrefslogtreecommitdiff
path: root/src/server/completion.odin
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-06 20:47:27 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-06 20:48:31 -0400
commit4a78b4ad1dca9a1218c4df2d97bfb5d9465bc063 (patch)
tree3eea76835d1180692492190988999c753434ac43 /src/server/completion.odin
parentd4b195cf6dba5894f9597c935106d190860d9de8 (diff)
Correctly filter used unions when ptr
Diffstat (limited to 'src/server/completion.odin')
-rw-r--r--src/server/completion.odin18
1 files changed, 14 insertions, 4 deletions
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
}
}
}