diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-06-10 20:29:06 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2025-06-10 20:29:06 +0200 |
| commit | 14cedf5f30b96cccd9d3b977c6e39fe3e1c0e009 (patch) | |
| tree | 78f9f76215911e4f51edf3cee24c03367f0a4f19 /src/server | |
| parent | dba39a1e8420eacb60719e02d9a2fcfd3cb5f537 (diff) | |
| parent | d375ab72e557552223d248bd30966732c4eb8166 (diff) | |
Merge branch 'BradLewis-fix/hover-inside-field-assignment'
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 16 | ||||
| -rw-r--r-- | src/server/hover.odin | 45 |
2 files changed, 44 insertions, 17 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 7202fe2..668260b 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1669,12 +1669,7 @@ resolve_implicit_selector :: proc( } } - if position_context.switch_stmt != nil { - return resolve_type_expression(ast_context, position_context.switch_stmt.cond) - } - if position_context.assign != nil && len(position_context.assign.lhs) == len(position_context.assign.rhs) { - for _, i in position_context.assign.lhs { if position_in_node(position_context.assign.rhs[i], position_context.position) { return resolve_type_expression(ast_context, position_context.assign.lhs[i]) @@ -1682,6 +1677,10 @@ resolve_implicit_selector :: proc( } } + if position_context.switch_stmt != nil { + return resolve_type_expression(ast_context, position_context.switch_stmt.cond) + } + if position_context.binary != nil { if position_in_node(position_context.binary.left, position_context.position) { return resolve_type_expression(ast_context, position_context.binary.right) @@ -3728,9 +3727,10 @@ unwrap_super_enum :: proc( for type in symbol_union.types { symbol := resolve_type_expression(ast_context, type) or_return - value := symbol.value.(SymbolEnumValue) or_return - append(&names, ..value.names) - append(&ranges, ..value.ranges) + if value, ok := symbol.value.(SymbolEnumValue); ok { + append(&names, ..value.names) + append(&ranges, ..value.ranges) + } } ret_value.names = names[:] diff --git a/src/server/hover.odin b/src/server/hover.odin index 9e4e20c..d1e861a 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -111,15 +111,17 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> 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 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 = common.node_to_string(v.types[i]) - hover.contents = write_hover_content(&ast_context, symbol) - return hover, true, true + 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 = common.node_to_string(v.types[i]) + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } } } } @@ -234,6 +236,31 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } } + } else if position_context.implicit_selector_expr != nil { + implicit_selector := position_context.implicit_selector_expr + if symbol, ok := resolve_implicit_selector(&ast_context, &position_context, implicit_selector); ok { + #partial switch v in symbol.value { + case SymbolEnumValue: + for name, i in v.names { + if strings.compare(name, implicit_selector.field.name) == 0 { + symbol.signature = fmt.tprintf(".%s", name) + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } + case SymbolUnionValue: + if enum_value, ok := unwrap_super_enum(&ast_context, v); ok { + for name, i in enum_value.names { + if strings.compare(name, implicit_selector.field.name) == 0 { + symbol.signature = fmt.tprintf(".%s", name) + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } + } + } + } + return {}, false, true } else if position_context.identifier != nil { reset_ast_context(&ast_context) |