@@ -35,7 +35,10 @@ private enum class SemanticTokenType(val typeName: String) {
35
35
36
36
private enum class SemanticTokenModifier (val modifierName : String ) {
37
37
DECLARATION (SemanticTokenModifiers .Declaration ),
38
- DEFINITION (SemanticTokenModifiers .Definition )
38
+ DEFINITION (SemanticTokenModifiers .Definition ),
39
+ ABSTRACT (SemanticTokenModifiers .Abstract ),
40
+ STATIC (SemanticTokenModifiers .Static ),
41
+ READONLY (SemanticTokenModifiers .Readonly )
39
42
}
40
43
41
44
val semanticTokensLegend = SemanticTokensLegend (
@@ -101,7 +104,9 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
101
104
}
102
105
else -> return null
103
106
}
104
- SemanticToken (elementRange, tokenType)
107
+ val isConstant = (target as ? VariableDescriptor )?.let { ! it.isVar() || it.isConst() } ? : false
108
+ val modifiers = if (isConstant) setOf (SemanticTokenModifier .READONLY ) else setOf ()
109
+ SemanticToken (elementRange, tokenType, modifiers)
105
110
}
106
111
is PsiNameIdentifierOwner -> {
107
112
val tokenType = when (element) {
@@ -111,7 +116,11 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
111
116
else -> return null
112
117
}
113
118
val identifierRange = element.nameIdentifier?.let { range(file.text, it.textRange) } ? : return null
114
- val modifiers = setOf (SemanticTokenModifier .DECLARATION )
119
+ val modifiers = mutableSetOf (SemanticTokenModifier .DECLARATION )
120
+ val isConstant = (element as ? KtVariableDeclaration )?.let { ! it.isVar() } ? : false
121
+ if (isConstant) {
122
+ modifiers.add(SemanticTokenModifier .READONLY )
123
+ }
115
124
SemanticToken (identifierRange, tokenType, modifiers)
116
125
}
117
126
else -> null
0 commit comments