diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-03-12 00:27:26 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-03-12 00:27:26 +0100 |
| commit | 207fe98a46b28297755608904dbf08d06fc50970 (patch) | |
| tree | ad50171aa05b2a7275243d722ec991c2afdd2278 /src/server | |
| parent | 447284f2366d8cf51ab4417427cdb3c079670282 (diff) | |
Support completion and gotos for comp literals in procs
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 41 | ||||
| -rw-r--r-- | src/server/completion.odin | 74 |
2 files changed, 68 insertions, 47 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 2e3839c..e3857c1 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1690,10 +1690,43 @@ resolve_comp_literal :: proc( symbol: Symbol, ok: bool, ) { - symbol = resolve_type_expression( - ast_context, - position_context.parent_comp_lit.type, - ) or_return + if position_context.parent_comp_lit.type != nil { + symbol = resolve_type_expression( + ast_context, + position_context.parent_comp_lit.type, + ) or_return + } else if position_context.call != nil { + if call_expr, ok := position_context.call.derived.(^ast.Call_Expr); + ok { + arg_index := 0 + for arg, i in call_expr.args { + if position_in_node(arg, position_context.position) { + arg_index = i + break + } + } + + symbol = resolve_type_expression( + ast_context, + position_context.call, + ) or_return + + value := symbol.value.(SymbolProcedureValue) or_return + + if len(value.arg_types) <= arg_index { + return {}, false + } + + if value.arg_types[arg_index].type == nil { + return {}, false + } + + symbol = resolve_type_expression( + ast_context, + value.arg_types[arg_index].type, + ) or_return + } + } symbol, _ = resolve_type_comp_literal( ast_context, diff --git a/src/server/completion.odin b/src/server/completion.odin index 2f5c1ce..eb83432 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -222,57 +222,45 @@ get_comp_lit_completion :: proc( ) { items := make([dynamic]CompletionItem, context.temp_allocator) - if position_context.parent_comp_lit.type == nil { - return - } - if symbol, ok := resolve_type_expression( - ast_context, - position_context.parent_comp_lit.type, - ); ok { - if comp_symbol, _, ok := resolve_type_comp_literal( - ast_context, - position_context, - symbol, - position_context.parent_comp_lit, - ); ok { - ast_context.current_package = comp_symbol.pkg - #partial switch v in comp_symbol.value { - case SymbolStructValue: - for name, i in v.names { - if name == "_" { + if symbol, ok := resolve_comp_literal(ast_context, position_context); ok { + //ast_context.current_package = comp_symbol.pkg + #partial switch v in symbol.value { + case SymbolStructValue: + for name, i in v.names { + if name == "_" { + continue + } + + ast_context.current_package = symbol.pkg + + if resolved, ok := resolve_type_expression( + ast_context, + v.types[i], + ); ok { + if field_exists_in_comp_lit( + position_context.comp_lit, + name, + ) { continue } - ast_context.current_package = comp_symbol.pkg - - if resolved, ok := resolve_type_expression( - ast_context, - v.types[i], - ); ok { - if field_exists_in_comp_lit( - position_context.comp_lit, + item := CompletionItem { + label = name, + kind = .Field, + detail = fmt.tprintf( + "%v.%v: %v", + symbol.name, name, - ) { - continue - } - - item := CompletionItem { - label = name, - kind = .Field, - detail = fmt.tprintf( - "%v.%v: %v", - comp_symbol.name, - name, - common.node_to_string(v.types[i]), - ), - documentation = resolved.doc, - } - - append(&items, item) + common.node_to_string(v.types[i]), + ), + documentation = resolved.doc, } + + append(&items, item) } } + } } |