diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-05-17 18:13:34 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2025-05-17 18:13:34 +0200 |
| commit | 07ea39ecdcf02dba84c82d90b028055463f6562c (patch) | |
| tree | 871c9659513cc053108b453411af421666b033f7 /src | |
| parent | 89f83305019a70d714af015aec734700dfee967c (diff) | |
Fixed issue with magic completion in call expressions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/analysis.odin | 106 | ||||
| -rw-r--r-- | src/server/completion.odin | 16 |
2 files changed, 74 insertions, 48 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 98f44c0..7202fe2 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1335,7 +1335,10 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide if return_symbol, ok = internal_resolve_type_expression(ast_context, v.expr); ok { if proc_value, ok := return_symbol.value.(SymbolProcedureValue); ok { if len(proc_value.return_types) >= 1 && proc_value.return_types[0].type != nil { - return_symbol, ok = internal_resolve_type_expression(ast_context, proc_value.return_types[0].type) + return_symbol, ok = internal_resolve_type_expression( + ast_context, + proc_value.return_types[0].type, + ) } } // Otherwise should be a parapoly style @@ -2748,34 +2751,34 @@ get_generic_assignment :: proc( if symbol, ok := resolve_type_expression(ast_context, v.expr); ok { #partial switch symbol_value in symbol.value { - case SymbolProcedureValue: - for ret in symbol_value.return_types { - if ret.type != nil { - calls[len(results)] = true - append(results, ret.type) - } else if ret.default_value != nil { - calls[len(results)] = true - append(results, ret.default_value) - } + case SymbolProcedureValue: + for ret in symbol_value.return_types { + if ret.type != nil { + calls[len(results)] = true + append(results, ret.type) + } else if ret.default_value != nil { + calls[len(results)] = true + append(results, ret.default_value) } - case SymbolAggregateValue: - //In case we can't resolve the proc group, just save it anyway, so it won't cause any issues further down the line. - append(results, value) - - case SymbolStructValue: - // Parametrized struct - get_generic_assignment(file, v.expr, ast_context, results, calls, flags) - case SymbolUnionValue: - // Parametrized union - get_generic_assignment(file, v.expr, ast_context, results, calls, flags) + } + case SymbolAggregateValue: + //In case we can't resolve the proc group, just save it anyway, so it won't cause any issues further down the line. + append(results, value) - case: - if ident, ok := v.expr.derived.(^ast.Ident); ok { - //TODO: Simple assumption that you are casting it the type. - type_ident := new_type(Ident, ident.pos, ident.end, ast_context.allocator) - type_ident.name = ident.name - append(results, type_ident) - } + case SymbolStructValue: + // Parametrized struct + get_generic_assignment(file, v.expr, ast_context, results, calls, flags) + case SymbolUnionValue: + // Parametrized union + get_generic_assignment(file, v.expr, ast_context, results, calls, flags) + + case: + if ident, ok := v.expr.derived.(^ast.Ident); ok { + //TODO: Simple assumption that you are casting it the type. + type_ident := new_type(Ident, ident.pos, ident.end, ast_context.allocator) + type_ident.name = ident.name + append(results, type_ident) + } } } case ^Comp_Lit: @@ -3155,25 +3158,28 @@ get_locals_for_range_stmt :: proc( if ident, ok := unwrap_ident(val); ok { expr: ^ast.Expr - if v.return_types[i].type != nil { - expr = v.return_types[i].type - } else if v.return_types[i].default_value != nil { - expr = v.return_types[i].default_value - } + if len(v.return_types) > i { - store_local( - ast_context, - ident, - expr, - ident.pos.offset, - ident.name, - ast_context.local_id, - ast_context.non_mutable_only, - false, - true, - symbol.pkg, - false, - ) + if v.return_types[i].type != nil { + expr = v.return_types[i].type + } else if v.return_types[i].default_value != nil { + expr = v.return_types[i].default_value + } + + store_local( + ast_context, + ident, + expr, + ident.pos.offset, + ident.name, + ast_context.local_id, + ast_context.non_mutable_only, + false, + true, + symbol.pkg, + false, + ) + } } } case SymbolUntypedValue: @@ -4402,6 +4408,16 @@ position_in_node :: proc(node: ^ast.Node, position: common.AbsolutePosition) -> return node != nil && node.pos.offset <= position && position <= node.end.offset } +position_in_exprs :: proc(nodes: []^ast.Expr, position: common.AbsolutePosition) -> bool { + for node in nodes { + if node != nil && node.pos.offset <= position && position <= node.end.offset { + return true + } + } + + return false +} + get_document_position_label :: proc(label: ^ast.Expr, position_context: ^DocumentPositionContext) { if label == nil { return diff --git a/src/server/completion.odin b/src/server/completion.odin index 7383785..8d61e3e 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1831,12 +1831,22 @@ append_magic_map_completion :: proc( get_expression_string_from_position_context :: proc(position_context: ^DocumentPositionContext) -> string { src := position_context.file.src if position_context.call != nil { - return src[position_context.call.pos.offset:position_context.call.end.offset] - } else if position_context.field != nil { + if call_expr, ok := position_context.call.derived.(^ast.Call_Expr); ok { + if position_in_node(call_expr.expr, position_context.position) { + return src[position_context.call.pos.offset:position_context.call.end.offset] + } + } + + } + + if position_context.field != nil { return src[position_context.field.pos.offset:position_context.field.end.offset] - } else if position_context.selector != nil { + } + + if position_context.selector != nil { return src[position_context.selector.pos.offset:position_context.selector.end.offset] } + return "" } |