diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-03 13:41:02 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-03 13:41:11 -0400 |
| commit | 662e8358b79de212a3a2b39d077fd7407a850058 (patch) | |
| tree | ebe1dc03a00ce0594b952e80d5461bb70e6a0973 /src/server | |
| parent | 7c8439ef9ab2243339583a492eac0c867a0b1d4e (diff) | |
Add documentation to union variants
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 8 | ||||
| -rw-r--r-- | src/server/collector.odin | 13 | ||||
| -rw-r--r-- | src/server/documentation.odin | 5 | ||||
| -rw-r--r-- | src/server/symbol.odin | 2 |
4 files changed, 22 insertions, 6 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index b741aef..385b20c 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -3105,9 +3105,13 @@ make_symbol_union_from_ast :: proc( } } + docs, comments := get_field_docs_and_comments(ast_context.file, v.variants, ast_context.allocator) + symbol.value = SymbolUnionValue { - types = types[:], - poly = v.poly_params, + types = types[:], + poly = v.poly_params, + docs = docs[:], + comments = comments[:], } if v.poly_params != nil { diff --git a/src/server/collector.odin b/src/server/collector.odin index 37ba74c..c06879d 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -247,6 +247,7 @@ collect_union_fields :: proc( collection: ^SymbolCollection, union_type: ast.Union_Type, package_map: map[string]string, + file: ast.File, ) -> SymbolUnionValue { types := make([dynamic]^ast.Expr, 0, collection.allocator) @@ -256,9 +257,15 @@ collect_union_fields :: proc( append(&types, cloned) } + temp_docs, temp_comments := get_field_docs_and_comments(file, union_type.variants, context.temp_allocator) + docs := clone_dynamic_array(temp_docs, collection.allocator, &collection.unique_strings) + comments := clone_dynamic_array(temp_comments, collection.allocator, &collection.unique_strings) + value := SymbolUnionValue { - types = types[:], - poly = cast(^ast.Field_List)clone_type(union_type.poly_params, collection.allocator, &collection.unique_strings), + types = types[:], + poly = cast(^ast.Field_List)clone_type(union_type.poly_params, collection.allocator, &collection.unique_strings), + comments = comments[:], + docs = docs[:], } return value @@ -567,7 +574,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri case ^ast.Union_Type: token = v^ token_type = .Union - symbol.value = collect_union_fields(collection, v^, package_map) + symbol.value = collect_union_fields(collection, v^, package_map, file) symbol.signature = "union" case ^ast.Bit_Set_Type: token = v^ diff --git a/src/server/documentation.odin b/src/server/documentation.odin index 4d284ec..c22bbb4 100644 --- a/src/server/documentation.odin +++ b/src/server/documentation.odin @@ -216,9 +216,12 @@ get_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string { } strings.write_string(&sb, " {\n") for i in 0 ..< len(v.types) { + append_docs(&sb, v.docs, i) strings.write_string(&sb, "\t") build_string_node(v.types[i], &sb, false) - strings.write_string(&sb, ",\n") + strings.write_string(&sb, ",") + append_comments(&sb, v.comments, i) + strings.write_string(&sb, "\n") } strings.write_string(&sb, "}") return strings.to_string(sb) diff --git a/src/server/symbol.odin b/src/server/symbol.odin index ab3c287..7352425 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -85,6 +85,8 @@ SymbolUnionValue :: struct { types: []^ast.Expr, poly: ^ast.Field_List, poly_names: []string, + docs: []^ast.Comment_Group, + comments: []^ast.Comment_Group, } SymbolDynamicArrayValue :: struct { |