aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-28 22:35:24 -0400
committerGitHub <noreply@github.com>2025-07-28 22:35:24 -0400
commit6c769f52ffd2cd40def26f758498ca4a8b2bce2b (patch)
tree3c468db8ba5bd9ba4c5aae3d1cbdd1fec1393f84
parent87da843330c8f7e7cab55951fd1536d9f21e17cd (diff)
parent886ae45e2736bf0406948c7302ae9a259ac43835 (diff)
Merge pull request #798 from BradLewis/fix/handle-compile-time-call-expr
Handle semantic token for const global variables returned from functions
-rw-r--r--src/server/semantic_tokens.odin4
-rw-r--r--tests/semantic_tokens_test.odin3
2 files changed, 6 insertions, 1 deletions
diff --git a/src/server/semantic_tokens.odin b/src/server/semantic_tokens.odin
index ac1beed..1a5fcb6 100644
--- a/src/server/semantic_tokens.odin
+++ b/src/server/semantic_tokens.odin
@@ -390,9 +390,11 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder) {
}
}
+// TODO: it seems the global symbols don't distinguish between a type decl and
+// 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:
+ case ^ast.Comp_Lit, ^ast.Basic_Lit, ^ast.Type_Cast, ^ast.Call_Expr:
return true
case:
return false
diff --git a/tests/semantic_tokens_test.odin b/tests/semantic_tokens_test.odin
index 88ad3c9..1a50dc5 100644
--- a/tests/semantic_tokens_test.odin
+++ b/tests/semantic_tokens_test.odin
@@ -58,6 +58,7 @@ semantic_tokens_literals_with_explicit_types :: proc(t: ^testing.T) {
Foo :: 1
Foo2 : int : 1
Foo3 :: cast(string) "hello"
+ Foo4 :: cstring("hello")
`
}
@@ -67,5 +68,7 @@ semantic_tokens_literals_with_explicit_types :: proc(t: ^testing.T) {
{0, 7, 3, .Type, {.ReadOnly}}, // [2] int
{1, 2, 4, .Variable, {.ReadOnly}}, // [3] Foo3
{0, 13, 6, .Type, {.ReadOnly}}, // [4] string
+ {1, 2, 4, .Variable, {.ReadOnly}}, // [5] Foo4
+ {0, 8, 7, .Type, {.ReadOnly}}, // [6] cstring
})
}