diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-10-05 21:49:33 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-10-05 21:49:33 +0200 |
| commit | ca2b55c02d91f3df76c748686a72a42a62a7991a (patch) | |
| tree | 2c9aec77820c48d0822288f8f0efb937b48cea60 /src | |
| parent | 90c90ae5dd0619f246c2379f48a4f0a7b5f5e0b7 (diff) | |
function overload now handles shared types in function. Hover should also show the function that was picked based on the arguments.
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/analysis.odin | 111 | ||||
| -rw-r--r-- | src/server/hover.odin | 6 |
2 files changed, 67 insertions, 50 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 5755fac..6319e47 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -592,74 +592,85 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou } if procedure, ok := f.value.(SymbolProcedureValue); ok { - count_required_params := 0 + i := 0 + named := false - for arg in procedure.arg_types { - if arg.default_value == nil { - count_required_params += 1 - } - } + for proc_arg in procedure.arg_types { + for name in proc_arg.names { + if i >= len(call_expr.args) { + continue + } - if len(procedure.arg_types) < len(call_expr.args) { - continue - } + call_arg := call_expr.args[i] - for arg, i in call_expr.args { - ast_context.use_locals = true + ast_context.use_locals = true - call_symbol: Symbol - arg_symbol: Symbol - ok: bool - i := i + call_symbol: Symbol + arg_symbol: Symbol + ok: bool - if _, ok = arg.derived.(^ast.Bad_Expr); ok { - continue - } + if _, ok = call_arg.derived.(^ast.Bad_Expr); ok { + continue + } + + //named parameter + if field, is_field := call_arg.derived.(^ast.Field_Value); is_field { + named = true + call_symbol, ok = resolve_type_expression(ast_context, field.value) + if !ok { + break next_fn + } + + if ident, is_ident := field.field.derived.(^ast.Ident); is_ident { + i, ok = get_field_list_name_index( + field.field.derived.(^ast.Ident).name, + procedure.arg_types, + ) + } else { + break next_fn + } + } else { + if named { + log.error("Expected name parameter after starting named parmeter phase") + return {}, false + } + call_symbol, ok = resolve_type_expression(ast_context, call_arg) + } - //named parameter - if field, is_field := arg.derived.(^ast.Field_Value); is_field { - call_symbol, ok = resolve_type_expression(ast_context, field.value) if !ok { break next_fn } - if ident, is_ident := field.field.derived.(^ast.Ident); is_ident { - i, ok = get_field_list_name_index( - field.field.derived.(^ast.Ident).name, - procedure.arg_types, - ) - } else { - break next_fn + if p, ok := call_symbol.value.(SymbolProcedureValue); ok { + if len(p.return_types) != 1 { + break next_fn + } + if s, ok := resolve_type_expression(ast_context, p.return_types[0].type); ok { + call_symbol = s + } } - } else { - call_symbol, ok = resolve_type_expression(ast_context, arg) - } - if !ok { - break next_fn - } + proc_arg := proc_arg - if p, ok := call_symbol.value.(SymbolProcedureValue); ok { - if len(p.return_types) != 1 { - break next_fn + if named { + proc_arg = procedure.arg_types[i] } - if s, ok := resolve_type_expression(ast_context, p.return_types[0].type); ok { - call_symbol = s + + if proc_arg.type != nil { + arg_symbol, ok = resolve_type_expression(ast_context, proc_arg.type) + } else { + arg_symbol, ok = resolve_type_expression(ast_context, proc_arg.default_value) } - } - if procedure.arg_types[i].type != nil { - arg_symbol, ok = resolve_type_expression(ast_context, procedure.arg_types[i].type) - } else { - arg_symbol, ok = resolve_type_expression(ast_context, procedure.arg_types[i].default_value) - } + if !ok { + break next_fn + } - if !ok { - break next_fn - } + if !is_symbol_same_typed(ast_context, call_symbol, arg_symbol, proc_arg.flags) { + break next_fn + } - if !is_symbol_same_typed(ast_context, call_symbol, arg_symbol, procedure.arg_types[i].flags) { - break next_fn + i += 1 } } diff --git a/src/server/hover.odin b/src/server/hover.odin index 5fdbff1..9b53a18 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -247,6 +247,12 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> hover.range = common.get_token_range(position_context.identifier^, document.ast.src) + if position_context.call != nil { + if call, ok := position_context.call.derived.(^ast.Call_Expr); ok { + ast_context.call = call + } + } + if resolved, ok := resolve_type_identifier(&ast_context, ident); ok { resolved.signature = get_signature(&ast_context, ident, resolved) resolved.name = ident.name |