From d806b5fe037de83a21d5a68d3e8f71a4b13d4b37 Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Thu, 13 Nov 2025 04:05:46 -0500 Subject: Add docs for local value decls --- src/server/analysis.odin | 4 +++- src/server/ast.odin | 2 +- src/server/collector.odin | 2 +- src/server/locals.odin | 14 ++++++++++++-- src/server/symbol.odin | 6 +++--- tests/hover_test.odin | 13 +++++++++++++ 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index a7a5c2a..aa19e56 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1861,6 +1861,8 @@ resolve_local_identifier :: proc(ast_context: ^AstContext, node: ast.Ident, loca return_symbol.flags |= {.Local} return_symbol.value_expr = local.value_expr return_symbol.type_expr = local.type_expr + return_symbol.doc = get_doc(local.docs, ast_context.allocator) + return_symbol.comment = get_comment(local.comment) return return_symbol, ok } @@ -1948,7 +1950,7 @@ resolve_global_identifier :: proc(ast_context: ^AstContext, node: ast.Ident, glo } if global.docs != nil { - return_symbol.doc = get_doc(global.name_expr, global.docs, ast_context.allocator) + return_symbol.doc = get_doc(global.docs, ast_context.allocator) } if global.comment != nil { diff --git a/src/server/ast.odin b/src/server/ast.odin index 5d06eb2..c6966fa 100644 --- a/src/server/ast.odin +++ b/src/server/ast.odin @@ -564,7 +564,7 @@ get_ast_node_string :: proc(node: ^ast.Node, src: string) -> string { return string(src[node.pos.offset:node.end.offset]) } -get_doc :: proc(node: ^ast.Expr, comment: ^ast.Comment_Group, allocator: mem.Allocator) -> string { +get_doc :: proc(comment: ^ast.Comment_Group, allocator: mem.Allocator) -> string { if comment == nil { return "" } diff --git a/src/server/collector.odin b/src/server/collector.odin index 3491f63..f082b73 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -705,7 +705,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri symbol.range = common.get_token_range(expr.name_expr, file.src) symbol.name = get_index_unique_string(collection, name) symbol.type = token_type - symbol.doc = get_doc(expr.name_expr, expr.docs, collection.allocator) + symbol.doc = get_doc(expr.docs, collection.allocator) symbol.uri = get_index_unique_string(collection, uri) symbol.type_expr = clone_type(expr.type_expr, collection.allocator, &collection.unique_strings) symbol.value_expr = clone_type(expr.value_expr, collection.allocator, &collection.unique_strings) diff --git a/src/server/locals.odin b/src/server/locals.odin index e1e5a5f..a88a6d7 100644 --- a/src/server/locals.odin +++ b/src/server/locals.odin @@ -19,6 +19,8 @@ DocumentLocal :: struct { pkg: string, flags: bit_set[LocalFlag], parameter: bool, + docs: ^ast.Comment_Group, + comment: ^ast.Comment_Group, } LocalGroup :: map[string][dynamic]DocumentLocal @@ -36,6 +38,8 @@ store_local :: proc( parameter: bool, type_expr: ^ast.Expr = nil, value_expr: ^ast.Expr = nil, + docs: ^ast.Comment_Group = nil, + comment: ^ast.Comment_Group = nil, ) { local_group := get_local_group(ast_context) local_stack := &local_group[name] @@ -58,6 +62,8 @@ store_local :: proc( pkg = pkg, flags = flags, parameter = parameter, + docs = docs, + comment = comment, }, ) } @@ -320,7 +326,7 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co value_expr: ^ast.Expr if len(value_decl.values) > i { if is_variable_declaration(value_decl.values[i]) { - flags |= {.Variable} + flags |= {.Variable} value_expr = value_decl.values[i] } } @@ -337,6 +343,8 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co false, value_decl.type, value_expr, + value_decl.docs, + value_decl.comment, ) } return @@ -389,6 +397,8 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co false, value_decl.type, value_expr, + value_decl.docs, + value_decl.comment, ) } } @@ -498,7 +508,7 @@ get_locals_block_stmt :: proc( if !skip_position_check { if ast_context.non_mutable_only { if !(block.pos.offset <= document_position.nested_position && - document_position.nested_position <= block.end.offset) { + document_position.nested_position <= block.end.offset) { return } } else { diff --git a/src/server/symbol.odin b/src/server/symbol.odin index d10178d..b6239da 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -907,7 +907,7 @@ construct_struct_field_symbol :: proc(symbol: ^Symbol, parent_name: string, valu symbol.name = value.names[index] symbol.type = .Field symbol.parent_name = parent_name - symbol.doc = get_doc(value.types[index], value.docs[index], context.temp_allocator) + symbol.doc = get_doc(value.docs[index], context.temp_allocator) symbol.comment = get_comment(value.comments[index]) symbol.range = value.ranges[index] } @@ -921,7 +921,7 @@ construct_bit_field_field_symbol :: proc( symbol.name = value.names[index] symbol.parent_name = parent_name symbol.type = .Field - symbol.doc = get_doc(value.types[index], value.docs[index], context.temp_allocator) + symbol.doc = get_doc(value.docs[index], context.temp_allocator) symbol.comment = get_comment(value.comments[index]) symbol.signature = get_bit_field_field_signature(value, index) symbol.range = value.ranges[index] @@ -929,7 +929,7 @@ construct_bit_field_field_symbol :: proc( construct_enum_field_symbol :: proc(symbol: ^Symbol, value: SymbolEnumValue, index: int) { symbol.type = .Field - symbol.doc = get_doc(nil, value.docs[index], context.temp_allocator) + symbol.doc = get_doc(value.docs[index], context.temp_allocator) symbol.comment = get_comment(value.comments[index]) symbol.signature = get_enum_field_signature(value, index) symbol.range = value.ranges[index] diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 8a41efc..6ecfbd9 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -5599,6 +5599,19 @@ ast_hover_index_function_call :: proc(t: ^testing.T) { } test.expect_hover(t, &source, "test.x: int") } + +@(test) +ast_hover_local_proc_docs :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + main :: proc() { + // foo doc + f{*}oo :: proc() {} + } + `, + } + test.expect_hover(t, &source, "test.foo :: proc()\n foo doc") +} /* Waiting for odin fix -- cgit v1.2.3