diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-11 21:29:56 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-11 21:52:50 -0400 |
| commit | 4cb9acda12fa0bb0a0b6fd6d46c163adc0544a4a (patch) | |
| tree | 2dab8c6a774f0be610048b145081f08f9f6f2282 /src | |
| parent | e90a29ed4682530243e10ae91e880ed2eeba4dfd (diff) | |
Resolve references for bit field fields
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/file_resolve.odin | 9 | ||||
| -rw-r--r-- | src/server/references.odin | 93 |
2 files changed, 63 insertions, 39 deletions
diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin index d4db280..53fda8f 100644 --- a/src/server/file_resolve.odin +++ b/src/server/file_resolve.odin @@ -561,6 +561,15 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) { resolve_node(n.name, data) resolve_node(n.type, data) resolve_node(n.bit_size, data) + if data.flag != .None { + data.symbols[cast(uintptr)n.name] = SymbolAndNode { + node = n.name, + symbol = Symbol{ + range = common.get_token_range(n.name, string(data.document.text)), + uri = strings.clone(common.create_uri(n.pos.file, data.ast_context.allocator).uri, data.ast_context.allocator), + }, + } + } case: } diff --git a/src/server/references.odin b/src/server/references.odin index d3dc98f..f7be8c6 100644 --- a/src/server/references.odin +++ b/src/server/references.odin @@ -50,42 +50,13 @@ prepare_references :: proc( ok = false pkg := "" - if position_context.struct_type != nil { - found := false - done_struct: for field in position_context.struct_type.fields.list { - for name in field.names { - if position_in_node(name, position_context.position) { - symbol = Symbol { - range = common.get_token_range(name, ast_context.file.src), - pkg = ast_context.current_package, - } - found = true - resolve_flag = .Field - break done_struct - } - } - if position_in_node(field.type, position_context.position) { - node := get_desired_expr(field.type, position_context.position) - symbol, ok = resolve_location_type_expression(ast_context, node) - if !ok { - return - } - - found = true - resolve_flag = .Identifier - break done_struct - } - } - if !found { - return - } - } else if position_context.enum_type != nil { + if position_context.enum_type != nil { found := false done_enum: for field in position_context.enum_type.fields { if ident, ok := field.derived.(^ast.Ident); ok { if position_in_node(ident, position_context.position) { symbol = Symbol { - pkg = ast_context.current_package, + pkg = ast_context.current_package, range = common.get_token_range(ident, ast_context.file.src), } found = true @@ -96,7 +67,7 @@ prepare_references :: proc( if position_in_node(value.field, position_context.position) { symbol = Symbol { range = common.get_token_range(value.field, ast_context.file.src), - pkg = ast_context.current_package, + pkg = ast_context.current_package, } found = true resolve_flag = .Field @@ -198,17 +169,61 @@ prepare_references :: proc( if !ok { return } - } else if position_context.identifier != nil { - ident := position_context.identifier.derived.(^ast.Ident) - symbol, ok = resolve_location_identifier(ast_context, ident^) + } else { + // The order of these is important as a lot of the above can be defined within a struct so we + // need to make sure we resolve that last + if position_context.bit_field_type != nil { + for field in position_context.bit_field_type.fields { + if position_in_node(field.name, position_context.position) { + symbol = Symbol { + range = common.get_token_range(field.name, ast_context.file.src), + pkg = ast_context.current_package, + uri = document.uri.uri, + } + return symbol, .Field, true + } + if position_in_node(field.type, position_context.position) { + node := get_desired_expr(field.type, position_context.position) + if symbol, ok = resolve_location_type_expression(ast_context, node); ok { + return symbol, .Identifier, true + } + } + } + } - resolve_flag = .Identifier + if position_context.struct_type != nil { + for field in position_context.struct_type.fields.list { + for name in field.names { + if position_in_node(name, position_context.position) { + symbol = Symbol { + range = common.get_token_range(name, ast_context.file.src), + pkg = ast_context.current_package, + uri = document.uri.uri, + } + return symbol, .Field, true + } + } + if position_in_node(field.type, position_context.position) { + node := get_desired_expr(field.type, position_context.position) + if symbol, ok = resolve_location_type_expression(ast_context, node); ok { + return symbol, .Identifier, true + } + } + } + } - if !ok { + if position_context.identifier != nil { + ident := position_context.identifier.derived.(^ast.Ident) + symbol, ok = resolve_location_identifier(ast_context, ident^) + + resolve_flag = .Identifier + + if !ok { + return + } + } else { return } - } else { - return } if symbol.uri == "" { symbol.uri = document.uri.uri |