diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-11 15:51:53 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-11 15:51:53 -0400 |
| commit | 8e4a3861bb6130c311fa22b9f9c71cf6990deaf2 (patch) | |
| tree | 97f703ddc8c30a134cbdedabf254d91554f6f459 /src/server | |
| parent | 3d1b2d482f9c1e0ddb0c3acf2890724f36b51643 (diff) | |
Resolve type definitions from comp lits
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 31 | ||||
| -rw-r--r-- | src/server/type_definition.odin | 6 |
2 files changed, 32 insertions, 5 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 8f2ca1c..b63c89b 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1935,13 +1935,34 @@ resolve_comp_literal :: proc( symbol: Symbol, ok: bool, ) { + return internal_resolve_comp_literal(ast_context, position_context, resolve_type_expression) +} + +resolve_location_comp_literal :: proc( + ast_context: ^AstContext, + position_context: ^DocumentPositionContext, +) -> ( + symbol: Symbol, + ok: bool, +) { + return internal_resolve_comp_literal(ast_context, position_context, resolve_location_type_expression) +} + +internal_resolve_comp_literal :: proc( + ast_context: ^AstContext, + position_context: ^DocumentPositionContext, + resolve_proc: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (Symbol, bool), +) -> ( + symbol: Symbol, + ok: bool, +) { if position_context.parent_comp_lit != nil && position_context.parent_comp_lit.type != nil { - symbol = resolve_type_expression(ast_context, position_context.parent_comp_lit.type) or_return + symbol = resolve_proc(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 := find_position_in_call_param(position_context, call_expr^) or_return - symbol = resolve_type_expression(ast_context, position_context.call) or_return + symbol = resolve_proc(ast_context, position_context.call) or_return value := symbol.value.(SymbolProcedureValue) or_return @@ -1953,7 +1974,7 @@ resolve_comp_literal :: proc( return {}, false } - symbol = resolve_type_expression(ast_context, value.arg_types[arg_index].type) or_return + symbol = resolve_proc(ast_context, value.arg_types[arg_index].type) or_return } } else if position_context.returns != nil { return_index: int @@ -1978,13 +1999,13 @@ resolve_comp_literal :: proc( } if len(position_context.function.type.results.list) > return_index { - symbol = resolve_type_expression( + symbol = resolve_proc( ast_context, position_context.function.type.results.list[return_index].type, ) or_return } } else if position_context.value_decl != nil && position_context.value_decl.type != nil { - symbol = resolve_type_expression(ast_context, position_context.value_decl.type) or_return + symbol = resolve_proc(ast_context, position_context.value_decl.type) or_return } set_ast_package_set_scoped(ast_context, symbol.pkg) diff --git a/src/server/type_definition.odin b/src/server/type_definition.odin index 94fb211..db0b587 100644 --- a/src/server/type_definition.odin +++ b/src/server/type_definition.odin @@ -103,6 +103,12 @@ get_type_definition_locations :: proc(document: ^Document, position: common.Posi } } + if position_context.comp_lit != nil { + if symbol, ok := resolve_location_comp_literal(&ast_context, &position_context); ok { + append_symbol_to_locations(&locations, document, symbol) + return locations[:], true + } + } if position_context.call != nil { if call, ok := position_context.call.derived.(^ast.Call_Expr); ok { |