diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-13 17:49:21 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-13 19:24:13 -0400 |
| commit | ab0ff1ba4fd3e35e330deb6979c5c1aa75907a98 (patch) | |
| tree | 95fe85408d8c6592f7c8c3d14dd6fe6a66474e1f /src/server | |
| parent | 023c8a0fd1d8d8e54b38bf990a74816a31dee68e (diff) | |
Improve resolution of comp literals
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 8 | ||||
| -rw-r--r-- | src/server/completion.odin | 57 |
2 files changed, 25 insertions, 40 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 1a7e4a7..b2ab4f2 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -211,6 +211,14 @@ resolve_type_comp_literal :: proc( ^ast.Comp_Lit, bool, ) { + // If the symbol is a MultiPointerValue, we retrieve the symbol of the underlying expression and + // retry with that. + if s, ok := current_symbol.value.(SymbolMultiPointerValue); ok { + if symbol, ok := resolve_type_expression(ast_context, s.expr); ok { + return resolve_type_comp_literal(ast_context, position_context, symbol, current_comp_lit) + } + } + if position_context.comp_lit == current_comp_lit { return current_symbol, current_comp_lit, true } else if current_comp_lit == nil { diff --git a/src/server/completion.odin b/src/server/completion.odin index 5136518..df4c260 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -267,8 +267,6 @@ get_comp_lit_completion :: proc( if symbol, ok := resolve_comp_literal(ast_context, position_context); ok { #partial switch v in symbol.value { case SymbolStructValue: - get_struct_field_completion(ast_context, position_context, &items, symbol) - case SymbolBitFieldValue: for name, i in v.names { if name == "_" { continue @@ -291,54 +289,33 @@ get_comp_lit_completion :: proc( append(&items, item) } } - case SymbolMultiPointerValue: - if resolved, ok := resolve_type_expression(ast_context, v.expr); ok { - if value, ok := resolved.value.(SymbolStructValue); ok { - get_struct_field_completion(ast_context, position_context, &items, resolved) + case SymbolBitFieldValue: + for name, i in v.names { + if name == "_" { + continue } - } - } - } - list.items = items[:] -} + set_ast_package_set_scoped(ast_context, symbol.pkg) -get_struct_field_completion :: proc( - ast_context: ^AstContext, - position_context: ^DocumentPositionContext, - items: ^[dynamic]CompletionItem, - symbol: Symbol, -) { - v := symbol.value.(SymbolStructValue) - for name, i in v.names { - if name == "_" { - continue - } + if resolved, ok := resolve_type_expression(ast_context, v.types[i]); ok { + if field_exists_in_comp_lit(position_context.comp_lit, name) { + continue + } - set_ast_package_set_scoped(ast_context, symbol.pkg) + item := CompletionItem { + label = name, + kind = .Field, + detail = fmt.tprintf("%v.%v: %v", symbol.name, name, common.node_to_string(v.types[i])), + documentation = resolved.doc, + } - if resolved, ok := resolve_type_expression(ast_context, v.types[i]); ok { - if field_exists_in_comp_lit(position_context.comp_lit, name) { - continue - } - - if value, ok := resolved.value.(SymbolStructValue); ok { - get_struct_field_completion(ast_context, position_context, items, resolved) - continue - } else { - item := CompletionItem { - label = name, - kind = .Field, - detail = fmt.tprintf("%v.%v: %v", symbol.name, name, common.node_to_string(v.types[i])), - documentation = resolved.doc, + append(&items, item) } - - append(items, item) } - } } + list.items = items[:] } get_selector_completion :: proc( |