diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-05 15:51:38 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-05 17:44:35 -0400 |
| commit | 58748c93f2eea884034a128105a54c526edc3048 (patch) | |
| tree | b0a9a05bc4a2100081765443e078c37fad863f78 /src/server | |
| parent | 09b1c91170d9e011316fa93dc7e98069dcdc6625 (diff) | |
Improvements to bitsets with enums
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 24 | ||||
| -rw-r--r-- | src/server/completion.odin | 15 | ||||
| -rw-r--r-- | src/server/hover.odin | 23 |
3 files changed, 52 insertions, 10 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 766913d..7914d2f 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2226,6 +2226,18 @@ resolve_location_implicit_selector :: proc( } } } + case SymbolBitSetValue: + enum_symbol := resolve_type_expression(ast_context, v.expr) or_return + if value, ok := enum_symbol.value.(SymbolEnumValue); ok { + for name, i in value.names { + if strings.compare(name, implicit_selector.field.name) == 0 { + symbol.range = value.ranges[i] + symbol.uri = enum_symbol.uri + return symbol, ok + } + } + } + case: ok = false } @@ -3892,6 +3904,8 @@ unwrap_enum :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (SymbolEnumVal return unwrap_enum(ast_context, value.expr) case SymbolDynamicArrayValue: return unwrap_enum(ast_context, value.expr) + case SymbolBitSetValue: + return unwrap_enum(ast_context, value.expr) } } @@ -3924,8 +3938,6 @@ unwrap_super_enum :: proc( unwrap_union :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (SymbolUnionValue, bool) { if union_symbol, ok := resolve_type_expression(ast_context, node); ok { - //TODO: This current package is sus, it probably shouldn't be there. - ast_context.current_package = union_symbol.pkg if union_value, ok := union_symbol.value.(SymbolUnionValue); ok { return union_value, true } @@ -4006,6 +4018,14 @@ field_exists_in_comp_lit :: proc(comp_lit: ^ast.Comp_Lit, name: string) -> bool } } } + } else if selector, ok := elem.derived.(^ast.Implicit_Selector_Expr); ok { + if selector.field != nil { + if ident, ok := selector.field.derived.(^ast.Ident); ok { + if ident.name == name { + return true + } + } + } } } diff --git a/src/server/completion.odin b/src/server/completion.odin index 2a63e4f..53d4fb9 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -734,10 +734,11 @@ get_implicit_completion :: proc( } if position_context.comp_lit != nil { - if bitset_symbol, ok := resolve_type_expression(ast_context, position_context.value_decl.type); ok { - set_ast_package_from_symbol_scoped(ast_context, bitset_symbol) - if _enum_value, ok := unwrap_bitset(ast_context, bitset_symbol); ok { - enum_value = _enum_value + if symbol, ok := resolve_type_expression(ast_context, position_context.value_decl.type); ok { + if v, ok := symbol.value.(SymbolFixedArrayValue); ok { + if _enum_value, ok := unwrap_enum(ast_context, v.len); ok { + enum_value = _enum_value + } } } for elem in position_context.comp_lit.elems { @@ -752,6 +753,9 @@ get_implicit_completion :: proc( if ev, ok := enum_value.?; ok { for name in ev.names { if !slice.contains(exclude_names[:], name) { + if position_context.comp_lit != nil && field_exists_in_comp_lit(position_context.comp_lit, name) { + continue + } item := CompletionItem { label = name, kind = .EnumMember, @@ -813,6 +817,9 @@ get_implicit_completion :: proc( set_ast_package_set_scoped(ast_context, symbol.pkg) if value, ok := unwrap_bitset(ast_context, symbol); ok { for name in value.names { + if position_context.comp_lit != nil && field_exists_in_comp_lit(position_context.comp_lit, name) { + continue + } item := CompletionItem { label = name, diff --git a/src/server/hover.odin b/src/server/hover.odin index fafc023..7dd1e51 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -391,15 +391,30 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> } } case SymbolUnionValue: - if enum_value, ok := unwrap_super_enum(&ast_context, v); ok { - for name, i in enum_value.names { + for type in v.types { + enum_symbol := resolve_type_expression(&ast_context, type) or_continue + v := enum_symbol.value.(SymbolEnumValue) or_continue + 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) + enum_symbol.signature = get_enum_field_signature(v, i) + hover.contents = write_hover_content(&ast_context, enum_symbol) return hover, true, true } } } + case SymbolBitSetValue: + if enum_symbol, ok := resolve_type_expression(&ast_context, v.expr); ok { + if v, ok := enum_symbol.value.(SymbolEnumValue); ok { + for name, i in v.names { + if strings.compare(name, implicit_selector.field.name) == 0 { + enum_symbol.signature = get_enum_field_signature(v, i) + hover.contents = write_hover_content(&ast_context, enum_symbol) + return hover, true, true + } + } + } + } + } } return {}, false, true |