aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-21 09:08:31 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-21 09:08:31 -0400
commitee22998e6e8beec8e3926c9c6b1a0dbd99b3d6db (patch)
tree6c894a1f39ec66c631d67b4f8519e620c06638bd
parent5bdd01db885abb3df58a2ed9501f418fc58e7ee8 (diff)
Improve hover for global constant variables
-rw-r--r--src/server/ast.odin2
-rw-r--r--src/server/documentation.odin2
-rw-r--r--tests/hover_test.odin18
3 files changed, 16 insertions, 6 deletions
diff --git a/src/server/ast.odin b/src/server/ast.odin
index 386d051..edb9007 100644
--- a/src/server/ast.odin
+++ b/src/server/ast.odin
@@ -375,7 +375,7 @@ merge_attributes :: proc(attrs: []^ast.Attribute, foreign_attrs: []^ast.Attribut
// a const variable declaration, so we do a quick check here to distinguish the cases.
is_variable_declaration :: proc(expr: ^ast.Expr) -> bool {
#partial switch v in expr.derived {
- case ^ast.Comp_Lit, ^ast.Basic_Lit, ^ast.Type_Cast, ^ast.Call_Expr:
+ case ^ast.Comp_Lit, ^ast.Basic_Lit, ^ast.Type_Cast, ^ast.Call_Expr, ^ast.Binary_Expr:
return true
case:
return false
diff --git a/src/server/documentation.odin b/src/server/documentation.odin
index fda1050..47c6d7e 100644
--- a/src/server/documentation.odin
+++ b/src/server/documentation.odin
@@ -853,7 +853,7 @@ construct_symbol_information :: proc(ast_context: ^AstContext, symbol: Symbol) -
strings.write_string(&sb, " : ")
write_node(&sb, ast_context, symbol.value_expr, "", 1, false)
return strings.to_string(sb)
- } else if _, ok := symbol.value_expr.derived.(^ast.Comp_Lit); ok {
+ } else if .Variable in symbol.flags {
strings.write_string(&sb, " :: ")
write_node(&sb, ast_context, symbol.value_expr, "", 1, false)
return strings.to_string(sb)
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 9f41c2c..bed597c 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -2895,7 +2895,7 @@ ast_hover_builtin_max_with_type_global :: proc(t: ^testing.T) {
ma{*}x_u32 :: max(u32)
`,
}
- test.expect_hover(t, &source, "test.max_u32 :: u32")
+ test.expect_hover(t, &source, "test.max_u32 :: max(u32)")
}
@(test)
@@ -2905,7 +2905,7 @@ ast_hover_builtin_max_ints :: proc(t: ^testing.T) {
ma{*}x_int :: max(1, 2, 3, 4)
`,
}
- test.expect_hover(t, &source, "test.max_int :: 4")
+ test.expect_hover(t, &source, "test.max_int :: max(1, 2, 3, 4)")
}
@(test)
@@ -2941,7 +2941,7 @@ ast_hover_builtin_max_mix_global_const :: proc(t: ^testing.T) {
m{*} :: max(1, 2.0, 3, 4.6)
`,
}
- test.expect_hover(t, &source, "test.m :: 4.6")
+ test.expect_hover(t, &source, "test.m :: max(1, 2.0, 3, 4.6)")
}
@(test)
@@ -4247,7 +4247,7 @@ ast_hover_binary_expr_with_type :: proc(t: ^testing.T) {
F{*}OO :: 1 + u8(2)
`,
}
- test.expect_hover(t, &source, "test.FOO :: u8")
+ test.expect_hover(t, &source, "test.FOO :: 1 + u8(2)")
}
@(test)
@@ -4914,6 +4914,16 @@ ast_hover_const_comp_lit_with_type :: proc(t: ^testing.T) {
}
test.expect_hover(t, &source, "test.FOO : Foo : {\n\ta = 1,\n\tb = \"b\",\n}")
}
+
+@(test)
+ast_hover_const_binary_expr :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ F{*}OO :: 3 + 4
+ `,
+ }
+ test.expect_hover(t, &source, "test.FOO :: 3 + 4")
+}
/*
Waiting for odin fix