aboutsummaryrefslogtreecommitdiff
path: root/src/server/completion.odin
diff options
context:
space:
mode:
authorBradley Lewis <22850972+BradLewis@users.noreply.github.com>2026-02-08 10:55:17 +1100
committerGitHub <noreply@github.com>2026-02-08 10:55:17 +1100
commit193e6ebd245fca345d83e5c4cbfd6cf7b5b062de (patch)
treebeeb7487feabd1d3a064dcbc7a34adffb863a921 /src/server/completion.odin
parente898b2d8dfaa121ff1a9375a0b18074e824b1e24 (diff)
parent7d5b8ede0f4248773d71fbfffcf9cde40c9cc774 (diff)
Merge pull request #1273 from DireLines/master
feat: code action to populate remaining switch cases
Diffstat (limited to 'src/server/completion.odin')
-rw-r--r--src/server/completion.odin38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 9c9ea9c..a7b1720 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -1943,12 +1943,32 @@ get_used_switch_name :: proc(node: ^ast.Expr) -> (string, bool) {
return n.name, true
case ^ast.Selector_Expr:
return n.field.name, true
+ case ^ast.Implicit_Selector_Expr:
+ return n.field.name, true
case ^ast.Pointer_Type:
return get_used_switch_name(n.elem)
}
return "", false
}
+//handles pointers / packages
+get_qualified_union_case_name :: proc(
+ symbol: ^Symbol,
+ ast_context: ^AstContext,
+ position_context: ^DocumentPositionContext,
+) -> string {
+ if symbol.pkg == ast_context.document_package {
+ return fmt.aprintf("%v%v", repeat("^", symbol.pointers, context.temp_allocator), symbol.name)
+ } else {
+ return fmt.aprintf(
+ "%v%v.%v",
+ repeat("^", symbol.pointers, context.temp_allocator),
+ get_symbol_pkg_name(ast_context, symbol),
+ symbol.name,
+ )
+ }
+}
+
get_type_switch_completion :: proc(
ast_context: ^AstContext,
position_context: ^DocumentPositionContext,
@@ -1977,7 +1997,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
@@ -1986,19 +2007,8 @@ get_type_switch_completion :: proc(
item := CompletionItem {
kind = .EnumMember,
}
-
- if symbol.pkg == ast_context.document_package {
- item.label = fmt.aprintf("%v%v", repeat("^", symbol.pointers, context.temp_allocator), name)
- item.detail = item.label
- } else {
- item.label = fmt.aprintf(
- "%v%v.%v",
- repeat("^", symbol.pointers, context.temp_allocator),
- get_symbol_pkg_name(ast_context, &symbol),
- name,
- )
- item.detail = item.label
- }
+ item.label = get_qualified_union_case_name(&symbol, ast_context, position_context)
+ item.detail = item.label
if position_context.implicit_selector_expr != nil {
if remove_edit, ok := create_implicit_selector_remove_edit(position_context); ok {
item.additionalTextEdits = remove_edit