diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-15 13:44:48 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-15 13:44:48 -0400 |
| commit | ba460eeccf68bf7585bf4f51aa10654ba78d7877 (patch) | |
| tree | bce1f289a5a2454a446c732a8750c661e187602a | |
| parent | 428b54c588ba00c84b60ed5d24cec1b264fa5589 (diff) | |
Consolidate resolving proc param names
| -rw-r--r-- | src/server/analysis.odin | 25 | ||||
| -rw-r--r-- | src/server/hover.odin | 69 | ||||
| -rw-r--r-- | tests/references_test.odin | 4 |
3 files changed, 51 insertions, 47 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index e3e1f6d..170b477 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2232,6 +2232,31 @@ resolve_location_proc_param_name :: proc( return symbol, true } +resolve_type_location_proc_param_name :: proc( + ast_context: ^AstContext, + position_context: ^DocumentPositionContext, +) -> ( + call_symbol: Symbol, + ok: bool, +) { + ident := position_context.field_value.field.derived.(^ast.Ident) or_return + call := position_context.call.derived.(^ast.Call_Expr) or_return + call_symbol = resolve_type_expression(ast_context, call) or_return + + if value, ok := call_symbol.value.(SymbolProcedureValue); ok { + if arg_type, ok := get_proc_arg_type_from_name(value, ident.name); ok { + if symbol, ok := resolve_type_expression(ast_context, arg_type.type); ok { + symbol.type_pkg = symbol.pkg + symbol.type_name = symbol.name + symbol.pkg = call_symbol.name + symbol.name = ident.name + return symbol, true + } + } + } + return call_symbol, false +} + resolve_location_comp_lit_field :: proc( ast_context: ^AstContext, position_context: ^DocumentPositionContext, diff --git a/src/server/hover.odin b/src/server/hover.odin index 4843391..f23bc23 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -213,44 +213,27 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } } + } - if position_context.call != nil { - // Check if we're resolving the name of a parameter being passed to a proc call - if call, ok := position_context.call.derived.(^ast.Call_Expr); ok { - if proc_symbol, ok := resolve_type_expression(&ast_context, call); ok { - if value, ok := proc_symbol.value.(SymbolProcedureValue); ok { - for arg in call.args { - if field_value, ok := arg.derived.(^ast.Field_Value); ok { - if position_in_node(field_value.field, position_context.position) { - if identifier, ok := field_value.field.derived.(^ast.Ident); ok { - if arg_type, arg_type_ok := get_proc_arg_type_from_name(value, identifier.name); ok { - if symbol, ok := resolve_type_expression(&ast_context, arg_type.type); ok { - symbol.range = common.get_token_range(field_value.field, ast_context.file.src) - symbol.type_name = symbol.name - symbol.type_pkg = symbol.pkg - symbol.pkg = proc_symbol.name - symbol.name = identifier.name - symbol.signature = get_signature(&ast_context, symbol) - hover.contents = write_hover_content(&ast_context, symbol) - return hover, true, true - } - } + if position_context.field_value != nil && position_in_node(position_context.field_value.field, position_context.position) { + if position_context.comp_lit != nil { + if comp_symbol, ok := resolve_comp_literal(&ast_context, &position_context); ok { + if field, ok := position_context.field_value.field.derived.(^ast.Ident); ok { + if position_in_node(field, position_context.position) { + if v, ok := comp_symbol.value.(SymbolStructValue); ok { + for name, i in v.names { + if name == field.name { + if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok { + symbol.name = name + symbol.pkg = comp_symbol.name + symbol.signature = node_to_string(v.types[i]) + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true } } - break } } - } - } - } - } - } - - if position_context.field_value != nil && position_context.comp_lit != nil { - if comp_symbol, ok := resolve_comp_literal(&ast_context, &position_context); ok { - if field, ok := position_context.field_value.field.derived.(^ast.Ident); ok { - if position_in_node(field, position_context.position) { - if v, ok := comp_symbol.value.(SymbolStructValue); ok { + } else if v, ok := comp_symbol.value.(SymbolBitFieldValue); ok { for name, i in v.names { if name == field.name { if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok { @@ -263,21 +246,17 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } } - } else if v, ok := comp_symbol.value.(SymbolBitFieldValue); ok { - for name, i in v.names { - if name == field.name { - if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok { - symbol.name = name - symbol.pkg = comp_symbol.name - symbol.signature = node_to_string(v.types[i]) - hover.contents = write_hover_content(&ast_context, symbol) - return hover, true, true - } - } - } } } } + + if position_context.call != nil { + if symbol, ok := resolve_type_location_proc_param_name(&ast_context, &position_context); ok { + symbol.signature = get_signature(&ast_context, symbol) + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } } if position_context.selector != nil && diff --git a/tests/references_test.odin b/tests/references_test.odin index 961c0cf..00fca21 100644 --- a/tests/references_test.odin +++ b/tests/references_test.odin @@ -1047,8 +1047,8 @@ ast_reference_struct_comp_lit_field :: proc(t: ^testing.T) { } locations := []common.Location { - {range = {start = {line = 3, character = 3}, end = {line = 3, character = 4}}}, - {range = {start = {line = 13, character = 11}, end = {line = 13, character = 12}}}, + {range = {start = {line = 8, character = 3}, end = {line = 8, character = 6}}}, + {range = {start = {line = 13, character = 4}, end = {line = 13, character = 7}}}, } test.expect_reference_locations(t, &source, locations[:]) |