aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-21 09:26:17 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-21 09:26:17 -0400
commit405e8ede2eaf2fbccb6ffbaa6b24a434665b056d (patch)
tree94260d847a212263ea5c4303f16fb4748921bca5
parentee22998e6e8beec8e3926c9c6b1a0dbd99b3d6db (diff)
Improve comp lit hover formatting
-rw-r--r--src/server/documentation.odin51
-rw-r--r--tests/hover_test.odin36
2 files changed, 68 insertions, 19 deletions
diff --git a/src/server/documentation.odin b/src/server/documentation.odin
index 47c6d7e..965e331 100644
--- a/src/server/documentation.odin
+++ b/src/server/documentation.odin
@@ -779,29 +779,44 @@ write_node :: proc(
symbol = make_symbol_procedure_from_ast(ast_context, nil, n^, name, {}, true, .None, nil)
ok = true
case ^ast.Comp_Lit:
- build_string(n.type, sb, false)
- if len(n.elems) == 0 {
- strings.write_string(sb, "{}")
- return
+ same_line := true
+ start_line := -1
+ for elem in n.elems {
+ if start_line == -1 {
+ start_line = elem.pos.line
+ } else if start_line != elem.pos.line {
+ same_line = false
+ break
+ }
}
- if n.type != nil {
- strings.write_string(sb, " {\n")
+ if same_line {
+ build_string(n, sb, false)
} else {
- strings.write_string(sb, "{\n")
- }
-
- for elem, i in n.elems {
- write_indent(sb, depth)
- if field, ok := elem.derived.(^ast.Field_Value); ok {
- build_string(field.field, sb, false)
- strings.write_string(sb, " = ")
- build_string(field.value, sb, false)
+ build_string(n.type, sb, false)
+ if len(n.elems) == 0 {
+ strings.write_string(sb, "{}")
+ return
+ }
+ if n.type != nil {
+ strings.write_string(sb, " {\n")
} else {
- build_string(elem, sb, false)
+ strings.write_string(sb, "{\n")
}
- strings.write_string(sb, ",\n")
+
+ for elem, i in n.elems {
+ write_indent(sb, depth)
+ if field, ok := elem.derived.(^ast.Field_Value); ok {
+ build_string(field.field, sb, false)
+ strings.write_string(sb, " = ")
+ write_node(sb, ast_context, field.value, "", depth+1, false)
+ } else {
+ build_string(elem, sb, false)
+ }
+ strings.write_string(sb, ",\n")
+ }
+ write_indent(sb, depth-1)
+ strings.write_string(sb, "}")
}
- strings.write_string(sb, "}")
return
}
if ok {
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index bed597c..fc66f64 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -237,7 +237,7 @@ ast_hover_on_array_infer_length_variable :: proc(t: ^testing.T) {
`,
}
- test.expect_hover(t, &source, "test.vec :: [?]f32 {\n\t1,\n\t2,\n\t3,\n}")
+ test.expect_hover(t, &source, "test.vec :: [?]f32{1, 2, 3}")
}
@(test)
@@ -4924,6 +4924,40 @@ ast_hover_const_binary_expr :: proc(t: ^testing.T) {
}
test.expect_hover(t, &source, "test.FOO :: 3 + 4")
}
+
+@(test)
+ast_hover_const_complex_comp_lit :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ frgba :: distinct [4]f32
+
+ COLOUR_BLUE :: frgba{0.1, 0.1, 0.1, 0.1}
+
+ Foo :: struct {
+ a: int,
+ b: string,
+ }
+
+ Colours :: struct {
+ blue: frgba,
+ green: frgba,
+ foo: Foo,
+ bar: int,
+ }
+
+ COL{*}OURS :: Colours {
+ blue = frgba{0.1, 0.1, 0.1, 0.1},
+ green = frgba{0.1, 0.1, 0.1, 0.1},
+ foo = {
+ a = 32,
+ b = "testing"
+ },
+ bar = 1 + 2,
+ }
+ `,
+ }
+ test.expect_hover(t, &source, "test.COLOURS :: Colours {\n\tblue = frgba{0.1, 0.1, 0.1, 0.1},\n\tgreen = frgba{0.1, 0.1, 0.1, 0.1},\n\tfoo = {\n\t\ta = 32,\n\t\tb = \"testing\",\n\t},\n\tbar = 1 + 2,\n}")
+}
/*
Waiting for odin fix