diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-30 21:01:54 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-02 07:54:29 -0400 |
| commit | de9bacba2cf724401e04fd5a2572053754817f9c (patch) | |
| tree | f09eb63680dd4eafb8f0a1ee23152b509c81e858 /src/server | |
| parent | b0c738ee087a57eebaa4c7626c29434a3b7fc524 (diff) | |
Improve references of enums with field values
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 32 | ||||
| -rw-r--r-- | src/server/file_resolve.odin | 15 | ||||
| -rw-r--r-- | src/server/references.odin | 21 |
3 files changed, 54 insertions, 14 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 95c3a82..e7496da 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1906,7 +1906,7 @@ resolve_implicit_selector :: proc( if s, ok := comp_symbol.value.(SymbolStructValue); ok { set_ast_package_set_scoped(ast_context, comp_symbol.pkg) - //We can either have the final + //We can either have the final elem_index := -1 for elem, i in comp_lit.elems { @@ -1934,7 +1934,7 @@ resolve_implicit_selector :: proc( } else if s, ok := comp_symbol.value.(SymbolBitFieldValue); ok { set_ast_package_set_scoped(ast_context, comp_symbol.pkg) - //We can either have the final + //We can either have the final elem_index := -1 for elem, i in comp_lit.elems { @@ -2756,17 +2756,9 @@ make_symbol_enum_from_ast :: proc( ranges := make([dynamic]common.Range, ast_context.allocator) for n in v.fields { - append(&ranges, common.get_token_range(n, ast_context.file.src)) - - if ident, ok := n.derived.(^ast.Ident); ok { - append(&names, ident.name) - } else if field, ok := n.derived.(^ast.Field_Value); ok { - if ident, ok := field.field.derived.(^ast.Ident); ok { - append(&names, ident.name) - } else if binary, ok := field.field.derived.(^ast.Binary_Expr); ok { - append(&names, binary.left.derived.(^ast.Ident).name) - } - } + name, range := get_enum_field_name_and_range(n, ast_context.file.src) + append(&names, name) + append(&ranges, range) } symbol.value = SymbolEnumValue { @@ -2777,6 +2769,20 @@ make_symbol_enum_from_ast :: proc( return symbol } +get_enum_field_name_and_range :: proc(n: ^ast.Expr, document_text: string) -> (string, common.Range) { + if ident, ok := n.derived.(^ast.Ident); ok { + return ident.name, common.get_token_range(ident, document_text) + } + if field, ok := n.derived.(^ast.Field_Value); ok { + if ident, ok := field.field.derived.(^ast.Ident); ok { + return ident.name, common.get_token_range(ident, document_text) + } else if binary, ok := field.field.derived.(^ast.Binary_Expr); ok { + return binary.left.derived.(^ast.Ident).name, common.get_token_range(binary, document_text) + } + } + return "", {} +} + make_symbol_bitset_from_ast :: proc( ast_context: ^AstContext, v: ast.Bit_Set_Type, diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin index a63161d..9b1ffa0 100644 --- a/src/server/file_resolve.odin +++ b/src/server/file_resolve.odin @@ -415,6 +415,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) { resolve_nodes(n.rhs, data) case ^Value_Decl: data.position_context.value_decl = n + reset_position_context(data.position_context) resolve_nodes(n.names, data) resolve_node(n.type, data) @@ -492,6 +493,20 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) { node = field, symbol = Symbol{range = common.get_token_range(field, string(data.document.text))}, } + // In the case of a Field_Value, we explicitly add them so we can find the LHS correctly for things like renaming + if field, ok := field.derived.(^ast.Field_Value); ok { + if ident, ok := field.field.derived.(^ast.Ident); ok { + data.symbols[cast(uintptr)ident] = SymbolAndNode { + node = ident, + symbol = Symbol{name = ident.name, range = common.get_token_range(ident, string(data.document.text))}, + } + } else if binary, ok := field.field.derived.(^ast.Binary_Expr); ok { + data.symbols[cast(uintptr)binary] = SymbolAndNode { + node = binary, + symbol = Symbol{name = "binary",range = common.get_token_range(binary, string(data.document.text))}, + } + } + } } } case ^Bit_Set_Type: diff --git a/src/server/references.odin b/src/server/references.odin index 04666ea..9002756 100644 --- a/src/server/references.odin +++ b/src/server/references.odin @@ -93,8 +93,27 @@ prepare_references :: proc( resolve_flag = .Field break done_enum } - } + } else if value, ok := field.derived.(^ast.Field_Value); ok { + if position_in_node(value.field, position_context.position) { + symbol = Symbol { + range = common.get_token_range(value.field, string(document.text)), + } + found = true + resolve_flag = .Field + break done_enum + } else if position_in_node(value.value, position_context.position) { + if ident, ok := value.value.derived.(^ast.Ident); ok { + symbol, ok = resolve_location_identifier(ast_context, ident^) + if !ok { + return + } + found = true + resolve_flag = .Identifier + break done_enum + } + } + } } if !found { return |