Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Semantic Tokens #525

Open
anthony-S93 opened this issue Nov 11, 2023 · 0 comments
Open

Inconsistent Semantic Tokens #525

anthony-S93 opened this issue Nov 11, 2023 · 0 comments

Comments

@anthony-S93
Copy link

anthony-S93 commented Nov 11, 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.

fun main(args: Array<String>) {
    var mutable_variable = 42
    println("The answer to life, the universe, and everything is " + mutable_variable)
}

2023-11-11-21-11-21

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) .

2023-11-11-21-14-22

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.

  1. for loop variables parsed as parameters in the for header.
fun main() {
    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:

2023-11-14-22-31-09

2023-11-14-22-31-58

Once again, it appears that the language server relies on syntax rather than semantics when assigning tokens to variables.

@anthony-S93 anthony-S93 changed the title The semantic tokens assigned to mutable variables seem inconsistent. Inconsistent Semantic Tokens Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant