aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-04 20:20:14 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-04 20:39:32 -0400
commit067efb7e8e3901eb9eaf0de8050997d4d4d07498 (patch)
tree78960751e7082cdde5a39f1527193c4f271c1281 /src
parent5227e9ff89b0290eefcec945867fa216aca7f51e (diff)
Improve bit_field field and variable hover information
Diffstat (limited to 'src')
-rw-r--r--src/server/documentation.odin22
-rw-r--r--src/server/hover.odin54
2 files changed, 57 insertions, 19 deletions
diff --git a/src/server/documentation.odin b/src/server/documentation.odin
index be54b40..b7196e5 100644
--- a/src/server/documentation.odin
+++ b/src/server/documentation.odin
@@ -228,11 +228,20 @@ get_short_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string
}
return strings.to_string(sb)
case SymbolBitFieldValue:
+ sb := strings.builder_make(ast_context.allocator)
if is_variable {
- return strings.concatenate({pointer_prefix, symbol.name}, ast_context.allocator)
+ append_variable_full_name(&sb, ast_context, symbol, pointer_prefix)
+ } else if symbol.type_name != "" {
+ write_symbol_type_information(ast_context, &sb, symbol, pointer_prefix)
} else {
- return "bit_field"
+ strings.write_string(&sb, "bit_field ")
+ build_string_node(v.backing_type, &sb, false)
+ }
+ if symbol.comment != "" {
+ fmt.sbprintf(&sb, " %s", symbol.comment)
}
+ return strings.to_string(sb)
+
case SymbolMultiPointerValue:
return strings.concatenate(
a = {pointer_prefix, "[^]", node_to_string(v.expr)},
@@ -295,6 +304,15 @@ get_enum_field_signature :: proc(value: SymbolEnumValue, index: int, allocator :
return strings.to_string(sb)
}
+get_bit_field_field_signature :: proc(value: SymbolBitFieldValue, index: int, allocator := context.temp_allocator) -> string {
+ sb := strings.builder_make(allocator)
+ build_string_node(value.types[index], &sb, false)
+ strings.write_string(&sb, " | ")
+ build_string_node(value.bit_sizes[index], &sb, false)
+ append_comments(&sb, value.comments, index)
+ return strings.to_string(sb)
+}
+
write_symbol_type_information :: proc(ast_context: ^AstContext, sb: ^strings.Builder, symbol: Symbol, pointer_prefix: string) {
append_type_pkg := false
pkg_name := get_pkg_name(ast_context, symbol.type_pkg)
diff --git a/src/server/hover.odin b/src/server/hover.odin
index 4965621..fafc023 100644
--- a/src/server/hover.odin
+++ b/src/server/hover.odin
@@ -156,8 +156,8 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
}
if position_context.struct_type != nil {
- for field in position_context.struct_type.fields.list {
- for name in field.names {
+ for field, field_index in position_context.struct_type.fields.list {
+ for name, name_index in field.names {
if position_in_node(name, position_context.position) {
if identifier, ok := name.derived.(^ast.Ident); ok && field.type != nil {
if symbol, ok := resolve_type_expression(&ast_context, field.type); ok {
@@ -171,21 +171,8 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
symbol.type_pkg = symbol.pkg
symbol.pkg = struct_symbol.name
symbol.name = identifier.name
-
- // Get the inline comment from the field definition if it exists
if value, ok := struct_symbol.value.(SymbolStructValue); ok {
- index := -1
- for n, i in value.names {
- if n == symbol.name {
- index = i
- break
- }
- }
- if index != -1 &&
- value.comments[index] != nil &&
- len(value.comments[index].list) > 0 {
- symbol.comment = value.comments[index].list[0].text
- }
+ symbol.comment = get_comment(value.comments[field_index + name_index])
}
symbol.signature = get_short_signature(&ast_context, symbol)
@@ -198,6 +185,37 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
}
}
}
+
+ if position_context.bit_field_type != nil {
+ for field, i in position_context.bit_field_type.fields {
+ if position_in_node(field.name, position_context.position) {
+ if identifier, ok := field.name.derived.(^ast.Ident); ok && field.type != nil {
+ if symbol, ok := resolve_type_expression(&ast_context, field.type); ok {
+ if bit_field_symbol, ok := resolve_type_expression(
+ &ast_context,
+ position_context.value_decl.names[0],
+ ); ok {
+ if value, ok := bit_field_symbol.value.(SymbolBitFieldValue); ok {
+ symbol.type = .Field
+ symbol.range = common.get_token_range(field.node, ast_context.file.src)
+ symbol.type_name = symbol.name
+ symbol.type_pkg = symbol.pkg
+ symbol.pkg = bit_field_symbol.name
+ symbol.name = identifier.name
+ symbol.signature = get_bit_field_field_signature(value, i)
+
+ if value, ok := bit_field_symbol.value.(SymbolBitFieldValue); ok {
+ symbol.comment = get_comment(value.comments[i])
+ }
+ hover.contents = write_hover_content(&ast_context, symbol)
+ return hover, true, true
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
if position_context.field_value != nil && position_context.comp_lit != nil {
@@ -220,6 +238,7 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
} else if v, ok := comp_symbol.value.(SymbolBitFieldValue); ok {
for name, i in v.names {
if name == field.name {
+ log.info("here?")
if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok {
symbol.name = name
symbol.pkg = comp_symbol.name
@@ -314,7 +333,8 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok {
symbol.name = name
symbol.pkg = selector.name
- symbol.signature = node_to_string(v.types[i])
+ symbol.signature = get_bit_field_field_signature(v, i)
+ symbol.doc = get_doc(v.docs[i], ast_context.allocator)
hover.contents = write_hover_content(&ast_context, symbol)
return hover, true, true
}