diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-23 08:47:48 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-23 08:47:48 -0400 |
| commit | 1089170576b4cc4b6330c6e9852cf3598a74991c (patch) | |
| tree | 413cf6d0b34abc4fc1d50961a4ad4c1637aa0d90 /src/server | |
| parent | 51c8693023acb0d5b2e6b80fbb9a31f44fc37fd6 (diff) | |
Resolve allocator field for container types on hover
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 20 | ||||
| -rw-r--r-- | src/server/hover.odin | 13 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 076a7e7..7b78984 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2625,6 +2625,26 @@ resolve_location_implicit_selector :: proc( return symbol, ok } +resolve_container_allocator :: proc(ast_context: ^AstContext, container_name: string) -> (Symbol, bool) { + for built in indexer.builtin_packages { + if symbol, ok := lookup(container_name, built, ast_context.fullpath); ok { + if v, ok := symbol.value.(SymbolStructValue); ok { + for name, i in v.names { + if name == "allocator" { + if symbol, ok := resolve_type_expression(ast_context, v.types[i]); ok { + construct_struct_field_symbol(&symbol, container_name, v, i) + build_documentation(ast_context, &symbol, true) + return symbol, true + } + } + } + } + } + } + + return {}, false +} + resolve_location_selector :: proc(ast_context: ^AstContext, selector_expr: ^ast.Node) -> (symbol: Symbol, ok: bool) { reset_ast_context(ast_context) diff --git a/src/server/hover.odin b/src/server/hover.odin index bf64967..86fd6a8 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -356,9 +356,22 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> case SymbolSliceValue: return get_soa_field_hover(&ast_context, selector, v.expr, nil, field) case SymbolDynamicArrayValue: + if field == "allocator" { + if symbol, ok := resolve_container_allocator(&ast_context, "Raw_Dynamic_Array"); ok { + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } return get_soa_field_hover(&ast_context, selector, v.expr, nil, field) case SymbolFixedArrayValue: return get_soa_field_hover(&ast_context, selector, v.expr, v.len, field) + case SymbolMapValue: + if field == "allocator" { + if symbol, ok := resolve_container_allocator(&ast_context, "Raw_Map"); ok { + hover.contents = write_hover_content(&ast_context, symbol) + return hover, true, true + } + } } } else if position_context.implicit_selector_expr != nil { implicit_selector := position_context.implicit_selector_expr |