diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-12 19:21:26 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-12 19:21:26 -0400 |
| commit | 8f626259507c4f6534dba4bc863dabbe30cee440 (patch) | |
| tree | 4381f610bfcf16f965c353e1a7f325a83008cbd2 /src/server | |
| parent | 5b380814bda90377c003b0174b7ae1dbe5da9f14 (diff) | |
Add methods for untyped symbols the same as their typed variants
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 39 | ||||
| -rw-r--r-- | src/server/methods.odin | 46 | ||||
| -rw-r--r-- | src/server/symbol.odin | 14 |
3 files changed, 63 insertions, 36 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index e8999dd..e9e5d30 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1,3 +1,4 @@ +#+feature dynamic-literals package server import "core:fmt" @@ -359,40 +360,24 @@ resolve_type_comp_literal :: proc( return current_symbol, current_comp_lit, true } +untyped_map: map[SymbolUntypedValueType][]string = { + .Integer = {"int", "uint", "u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "u128", "i128", "byte"}, + .Bool = {"bool", "b8", "b16", "b32", "b64"}, + .Float = {"f16", "f32", "f64"}, + .String = {"string", "cstring"} +} + // NOTE: This function is not commutative are_symbol_untyped_basic_same_typed :: proc(a, b: Symbol) -> (bool, bool) { if untyped, ok := a.value.(SymbolUntypedValue); ok { if basic, ok := b.value.(SymbolBasicValue); ok { - switch untyped.type { - case .Integer: - switch basic.ident.name { - case "int", "uint", "u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "u128", "i128", "byte": - return true, true - case: - return false, true - } - case .Bool: - switch basic.ident.name { - case "bool", "b8", "b16", "b32", "b64": - return true, true - case: - return false, true - } - case .String: - switch basic.ident.name { - case "string", "cstring": - return true, true - case: - return false, true - } - case .Float: - switch basic.ident.name { - case "f16", "f32", "f64": + names := untyped_map[untyped.type] + for name in names { + if basic.ident.name == name { return true, true - case: - return false, true } } + return false, true } else if untyped_b, ok := b.value.(SymbolUntypedValue); ok { return untyped.type == untyped_b.type, true } diff --git a/src/server/methods.odin b/src/server/methods.odin index 1826ef6..e60b84e 100644 --- a/src/server/methods.odin +++ b/src/server/methods.odin @@ -54,16 +54,56 @@ append_method_completion :: proc( } remove_edit, ok := create_remove_edit(position_context) - if !ok { return } - for k, v in indexer.index.collection.packages { + if value, ok := selector_symbol.value.(SymbolUntypedValue); ok { + cases := untyped_map[value.type] + for c in cases { + method := Method { + name = c, + pkg = selector_symbol.pkg, + } + collect_methods( + ast_context, + position_context, + method, + selector_symbol.pointers, + receiver, + remove_edit, + results, + ) + } + } else { method := Method { name = selector_symbol.name, pkg = selector_symbol.pkg, } + collect_methods( + ast_context, + position_context, + method, + selector_symbol.pointers, + receiver, + remove_edit, + results, + ) + } + +} + +@(private = "file") +collect_methods :: proc( + ast_context: ^AstContext, + position_context: ^DocumentPositionContext, + method: Method, + pointers: int, + receiver: string, + remove_edit: []TextEdit, + results: ^[dynamic]CompletionResult, +) { + for k, v in indexer.index.collection.packages { if symbols, ok := &v.methods[method]; ok { for &symbol in symbols { resolve_unresolved_symbol(ast_context, &symbol) @@ -92,7 +132,7 @@ append_method_completion :: proc( continue } - pointers_to_add := first_arg.pointers - selector_symbol.pointers + pointers_to_add := first_arg.pointers - pointers references := "" dereferences := "" diff --git a/src/server/symbol.odin b/src/server/symbol.odin index 4574c2d..8fcf89c 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -124,13 +124,15 @@ SymbolBitSetValue :: struct { expr: ^ast.Expr, } +SymbolUntypedValueType :: enum { + Integer, + Float, + String, + Bool, +} + SymbolUntypedValue :: struct { - type: enum { - Integer, - Float, - String, - Bool, - }, + type: SymbolUntypedValueType, tok: tokenizer.Token, } |