aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-05 20:34:46 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-09 13:28:11 -0400
commit96c2fad666f5820db1455e15059959296392e97e (patch)
treea8644282db84c46a9c818cd55dc68fc9915e8b90
parent2c2c3052607fce94dce400eb47c60a05c7cc1048 (diff)
Add union align and kind to hover information
-rw-r--r--src/server/analysis.odin2
-rw-r--r--src/server/collector.odin2
-rw-r--r--src/server/documentation.odin18
-rw-r--r--src/server/symbol.odin2
-rw-r--r--tests/hover_test.odin29
5 files changed, 53 insertions, 0 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index dbe9d48..8f2ca1c 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -3150,6 +3150,8 @@ make_symbol_union_from_ast :: proc(
poly = v.poly_params,
docs = docs[:],
comments = comments[:],
+ kind = v.kind,
+ align = v.align,
}
if v.poly_params != nil {
diff --git a/src/server/collector.odin b/src/server/collector.odin
index eaf1229..cc72509 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -266,6 +266,8 @@ collect_union_fields :: proc(
poly = cast(^ast.Field_List)clone_type(union_type.poly_params, collection.allocator, &collection.unique_strings),
comments = comments[:],
docs = docs[:],
+ kind = union_type.kind,
+ align = clone_type(union_type.align, collection.allocator, &collection.unique_strings),
}
return value
diff --git a/src/server/documentation.odin b/src/server/documentation.odin
index d7c3295..c572e79 100644
--- a/src/server/documentation.odin
+++ b/src/server/documentation.odin
@@ -210,6 +210,13 @@ get_signature :: proc(ast_context: ^AstContext, symbol: Symbol) -> string {
}
strings.write_string(&sb, "union")
write_poly_list(&sb, v.poly, v.poly_names)
+ if v.kind != .Normal {
+ write_union_kind(&sb, v.kind)
+ }
+ if v.align != nil {
+ strings.write_string(&sb, " #align")
+ build_string_node(v.align, &sb, false)
+ }
if len(v.types) == 0 {
strings.write_string(&sb, " {}")
return strings.to_string(sb)
@@ -631,6 +638,17 @@ write_poly_list :: proc(sb: ^strings.Builder, poly: ^ast.Field_List, poly_names:
}
}
+write_union_kind :: proc(sb: ^strings.Builder, kind: ast.Union_Type_Kind) {
+ #partial switch kind {
+ case .maybe:
+ strings.write_string(sb, " #maybe")
+ case .no_nil:
+ strings.write_string(sb, " #no_nil")
+ case .shared_nil:
+ strings.write_string(sb, " #shared_nil")
+ }
+}
+
append_type_information :: proc(
sb: ^strings.Builder,
ast_context: ^AstContext,
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index ff88099..77c4cb0 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -87,6 +87,8 @@ SymbolUnionValue :: struct {
poly_names: []string,
docs: []^ast.Comment_Group,
comments: []^ast.Comment_Group,
+ kind: ast.Union_Type_Kind,
+ align: ^ast.Expr,
}
SymbolDynamicArrayValue :: struct {
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 4e5dfd9..684d457 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -3633,6 +3633,35 @@ ast_hover_parapoly_proc_multi_pointer_param :: proc(t: ^testing.T) {
}
test.expect_hover(t, &source, "test.bar: ^[^]u8")
}
+
+@(test)
+ast_hover_union_with_tag :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ F{*}oo :: union #no_nil {
+ int, string,
+ }
+ `,
+ }
+
+ test.expect_hover(t, &source, "test.Foo: union #no_nil {\n\tint,\n\tstring,\n}")
+}
+
+@(test)
+ast_hover_union_with_align :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ F{*}oo :: union #no_nil #align(4) {
+ int, string,
+ }
+ `,
+ }
+ test.expect_hover(
+ t,
+ &source,
+ "test.Foo: union #no_nil #align(4) {\n\tint,\n\tstring,\n}"
+ )
+}
/*
Waiting for odin fix