summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-10-25 19:31:03 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-10-25 19:31:03 -0400
commitebc70c286e1817f225525e7e27089cb5d7eb548a (patch)
treea1bb099aad1e4c1915a464aaa82df45d8ae22328
parent3ea1da1ff4f5d0a6e69339da9dd0f065a3455770 (diff)
Fix displayed return type when inlining a enum, struct, or union
-rw-r--r--src/server/ast.odin23
-rw-r--r--tests/hover_test.odin30
2 files changed, 50 insertions, 3 deletions
diff --git a/src/server/ast.odin b/src/server/ast.odin
index 60e7d00..f60116d 100644
--- a/src/server/ast.odin
+++ b/src/server/ast.odin
@@ -1218,7 +1218,7 @@ build_string_node :: proc(node: ^ast.Node, builder: ^strings.Builder, remove_poi
for field, i in n.list {
build_string(field, builder, remove_pointers)
if len(n.list) - 1 != i {
- strings.write_string(builder, ",")
+ strings.write_string(builder, ", ")
}
}
case ^Typeid_Type:
@@ -1265,16 +1265,33 @@ build_string_node :: proc(node: ^ast.Node, builder: ^strings.Builder, remove_poi
strings.write_string(builder, "[dynamic]")
build_string(n.elem, builder, remove_pointers)
case ^Struct_Type:
+ strings.write_string(builder, "struct{")
build_string(n.poly_params, builder, remove_pointers)
build_string(n.align, builder, remove_pointers)
build_string(n.fields, builder, remove_pointers)
+ strings.write_string(builder, "}")
case ^Union_Type:
+ strings.write_string(builder, "union{")
build_string(n.poly_params, builder, remove_pointers)
build_string(n.align, builder, remove_pointers)
- build_string(n.variants, builder, remove_pointers)
+ for variant, i in n.variants {
+ if i != 0 {
+ strings.write_string(builder, ", ")
+ }
+ build_string(variant, builder, remove_pointers)
+ }
+ strings.write_string(builder, "}")
case ^Enum_Type:
+ strings.write_string(builder, "enum")
build_string(n.base_type, builder, remove_pointers)
- build_string(n.fields, builder, remove_pointers)
+ strings.write_string(builder, "{")
+ for field, i in n.fields {
+ if i != 0 {
+ strings.write_string(builder, ", ")
+ }
+ build_string(field, builder, remove_pointers)
+ }
+ strings.write_string(builder, "}")
case ^Bit_Set_Type:
strings.write_string(builder, "bit_set")
strings.write_string(builder, "[")
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index a90346e..e51d116 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -5282,6 +5282,36 @@ ast_hover_proc_group_named_arg_with_nil :: proc(t: ^testing.T) {
}
test.expect_hover(t, &source, "test.bar :: proc(i: int, foo: ^Foo)")
}
+
+@(test)
+ast_hover_proc_return_with_union :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ f{*}oo :: proc() -> union{string, [4]u8} {}
+ `,
+ }
+ test.expect_hover(t, &source, "test.foo :: proc() -> union{string, [4]u8}")
+}
+
+@(test)
+ast_hover_proc_return_with_struct :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ f{*}oo :: proc() -> struct{s: string, i: int} {}
+ `,
+ }
+ test.expect_hover(t, &source, "test.foo :: proc() -> struct{s: string, i: int}")
+}
+
+@(test)
+ast_hover_proc_return_with_enum :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ f{*}oo :: proc() -> enum{A, B} {}
+ `,
+ }
+ test.expect_hover(t, &source, "test.foo :: proc() -> enum{A, B}")
+}
/*
Waiting for odin fix