You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The semantic tokens assigned to variables in declaration statements are inconsistent with the tokens assigned to those same variables everywhere they are used.
The following sample code illustrates the issue.
funmain(args:Array<String>) {
var mutable_variable =42println("The answer to life, the universe, and everything is "+ mutable_variable)
}
Using an inspection tool, I could see that mutable_variable was assigned the token lsp.type.property.kotlin in the declaration statement:
var mutable_variable =42
However, mutable_variable was assigned lsp.type.variable everywhere else (which is obvious from the different highlighting) .
I am new to Kotlin, but my intuition tells me that the language server shouldn't treat a variable in a var declaration as a property unless the declaration occurs within the context of a class. Is this the expected behavior? Or am I completely off base?
EDIT:
After a few days of experimentation, I discovered other inconsistencies.
for loop variables parsed as parameters in the for header.
funmain() {
val fruits =listOf("apple", "banana", "citrus")
for (fruit in fruits) {
println("I love $fruit")
}
}
Using an inspection tool on the sample code above reveals the following semantic token assignments for various references of the variable fruit:
Once again, it appears that the language server relies on syntax rather than semantics when assigning tokens to variables.
The text was updated successfully, but these errors were encountered:
anthony-S93
changed the title
The semantic tokens assigned to mutable variables seem inconsistent.
Inconsistent Semantic Tokens
Nov 12, 2023
The semantic tokens assigned to variables in declaration statements are inconsistent with the tokens assigned to those same variables everywhere they are used.
The following sample code illustrates the issue.
Using an inspection tool, I could see that
mutable_variable
was assigned the tokenlsp.type.property.kotlin
in the declaration statement:However,
mutable_variable
was assignedlsp.type.variable
everywhere else (which is obvious from the different highlighting) .I am new to Kotlin, but my intuition tells me that the language server shouldn't treat a variable in a
var
declaration as aproperty
unless the declaration occurs within the context of aclass
. Is this the expected behavior? Or am I completely off base?EDIT:
After a few days of experimentation, I discovered other inconsistencies.
for
loop variables parsed as parameters in thefor
header.Using an inspection tool on the sample code above reveals the following semantic token assignments for various references of the variable
fruit
:Once again, it appears that the language server relies on syntax rather than semantics when assigning tokens to variables.
The text was updated successfully, but these errors were encountered: