Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/server/semantic_tokens.odin
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ visit_proc_type :: proc(node: ^ast.Proc_Type, builder: ^SemanticTokenBuilder) {
for name in param.names {
if ident, ok := name.derived.(^ast.Ident); ok {
write_semantic_node(builder, name, .Parameter)
} else if poly, ok := name.derived.(^ast.Poly_Type); ok {
write_semantic_node(builder, poly.type, .Parameter)
}
}

Expand Down Expand Up @@ -563,7 +565,11 @@ visit_ident :: proc(
}

if .PolyType in symbol.flags {
write_semantic_node(builder, ident, .TypeParameter, modifiers)
if is_type_parameter(symbol) {
write_semantic_node(builder, ident, .TypeParameter, modifiers)
} else {
write_semantic_node(builder, ident, .Parameter, modifiers)
}
return
}

Expand Down Expand Up @@ -632,3 +638,15 @@ visit_ident :: proc(
}
}
}

is_type_parameter :: proc(symbol: Symbol) -> bool {
if basic, ok := symbol.value.(SymbolBasicValue); ok {
return basic.ident != nil && basic.ident.name == "typeid"
}

if _, ok := symbol.value.(SymbolPolyTypeValue); ok {
return true
}

return false
}
18 changes: 18 additions & 0 deletions tests/semantic_tokens_test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,21 @@ semantic_tokens_alias_from_poly_struct :: proc(t: ^testing.T) {
{0, 4, 3, .Type, {.ReadOnly}}, // [4] int
})
}

@(test)
semantic_tokens_poly_proc_value_param :: proc(t: ^testing.T) {
src := test.Source {
main = `package test
generic_proc :: proc($FOO: int) {
FOO
}
`
}

test.expect_semantic_tokens(t, &src, {
{1, 2, 12, .Function, {.ReadOnly}}, // [0] generic_proc
{0, 22, 3, .Parameter, {}}, // [1] FOO
{0, 5, 3, .Type, {.ReadOnly}}, // [2] int
{1, 3, 3, .Parameter, {}}, // [3] FOO
})
}
Loading