From 8f44d4c36c2712b9d230238b58042e79df67cefd Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Wed, 10 Sep 2025 12:39:07 -0400 Subject: Add where clauses to hover information --- src/server/documentation.odin | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/server/documentation.odin') diff --git a/src/server/documentation.odin b/src/server/documentation.odin index 285119d..49674ad 100644 --- a/src/server/documentation.odin +++ b/src/server/documentation.odin @@ -216,6 +216,7 @@ write_signature :: proc(sb: ^strings.Builder, ast_context: ^AstContext, symbol: strings.write_string(sb, " #align") build_string_node(v.align, sb, false) } + write_where_clauses(sb, v.where_clauses) if len(v.types) == 0 { strings.write_string(sb, " {}") return @@ -530,6 +531,7 @@ write_procedure_symbol_signature :: proc(sb: ^strings.Builder, value: SymbolProc } } write_proc_param_list_and_return(sb, value) + write_where_clauses(sb, value.where_clauses) if detailed_signature { for tag in value.tags { s := "" @@ -549,6 +551,18 @@ write_procedure_symbol_signature :: proc(sb: ^strings.Builder, value: SymbolProc } } +write_where_clauses :: proc(sb: ^strings.Builder, where_clauses: []^ast.Expr) { + if len(where_clauses) > 0 { + strings.write_string(sb, " where ") + for clause, i in where_clauses { + build_string_node(clause, sb, false) + if i != len(where_clauses) - 1 { + strings.write_string(sb, ", ") + } + } + } +} + write_struct_hover :: proc(sb: ^strings.Builder, ast_context: ^AstContext, v: SymbolStructValue, depth: int) { strings.write_string(sb, "struct") write_poly_list(sb, v.poly, v.poly_names) @@ -578,6 +592,9 @@ write_struct_hover :: proc(sb: ^strings.Builder, ast_context: ^AstContext, v: Sy strings.write_string(sb, " #no_copy") } } + + write_where_clauses(sb, v.where_clauses) + if len(v.names) == 0 { strings.write_string(sb, " {}") return @@ -718,7 +735,7 @@ write_node :: proc( symbol = make_symbol_bit_field_from_ast(ast_context, n, name, true) ok = true case ^ast.Proc_Type: - symbol = make_symbol_procedure_from_ast(ast_context, nil, n^, name, {}, true, .None) + symbol = make_symbol_procedure_from_ast(ast_context, nil, n^, name, {}, true, .None, nil) ok = true } if ok { -- cgit v1.2.3 From a60d0daad2ff3e57eb9942c58c532007794bbd63 Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Wed, 10 Sep 2025 13:40:04 -0400 Subject: Add parentheses around named proc returns --- src/server/documentation.odin | 9 ++++++++- tests/hover_test.odin | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/server/documentation.odin') diff --git a/src/server/documentation.odin b/src/server/documentation.odin index 49674ad..6f591a4 100644 --- a/src/server/documentation.odin +++ b/src/server/documentation.odin @@ -486,7 +486,14 @@ write_proc_param_list_and_return :: proc(sb: ^strings.Builder, value: SymbolProc if len(value.orig_return_types) != 0 { strings.write_string(sb, " -> ") + add_parens := false if len(value.orig_return_types) > 1 { + add_parens = true + } else if field, ok := value.orig_return_types[0].derived.(^ast.Field); ok && len(field.names) > 0{ + add_parens = true + } + + if add_parens { strings.write_string(sb, "(") } @@ -497,7 +504,7 @@ write_proc_param_list_and_return :: proc(sb: ^strings.Builder, value: SymbolProc } } - if len(value.orig_return_types) > 1 { + if add_parens { strings.write_string(sb, ")") } } else if value.diverging { diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 8879cc9..5370804 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -4533,6 +4533,18 @@ ast_hover_parapoly_union_with_where_clause :: proc(t: ^testing.T) { } test.expect_hover(t, &source, "test.Foo: union($T: typeid) #no_nil where type_is_integer(T) {\n\tT,\n\tstring,\n}") } + +@(test) +ast_hover_proc_named_return_parens :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + f{*}oo :: proc() -> (a: int) { + return + } + `, + } + test.expect_hover(t, &source, "test.foo: proc() -> (a: int)") +} /* Waiting for odin fix -- cgit v1.2.3