@@ -13,6 +13,8 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
13
13
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
14
14
import org.jetbrains.kotlin.descriptors.VariableDescriptor
15
15
import org.jetbrains.kotlin.lexer.KtTokens
16
+ import org.jetbrains.kotlin.psi.KtClassOrObject
17
+ import org.jetbrains.kotlin.psi.KtModifierListOwner
16
18
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
17
19
import org.jetbrains.kotlin.psi.KtVariableDeclaration
18
20
import org.jetbrains.kotlin.psi.KtNamedDeclaration
@@ -39,7 +41,6 @@ private enum class SemanticTokenModifier(val modifierName: String) {
39
41
DECLARATION (SemanticTokenModifiers .Declaration ),
40
42
DEFINITION (SemanticTokenModifiers .Definition ),
41
43
ABSTRACT (SemanticTokenModifiers .Abstract ),
42
- STATIC (SemanticTokenModifiers .Static ),
43
44
READONLY (SemanticTokenModifiers .Readonly )
44
45
}
45
46
@@ -90,6 +91,7 @@ private fun elementTokens(element: PsiElement, bindingContext: BindingContext):
90
91
private fun elementToken (element : PsiElement , bindingContext : BindingContext ): SemanticToken ? {
91
92
val file = element.containingFile
92
93
val elementRange = range(file.text, element.textRange)
94
+
93
95
return when (element) {
94
96
is KtNameReferenceExpression -> {
95
97
val target = bindingContext[BindingContext .REFERENCE_TARGET , element]
@@ -108,21 +110,32 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
108
110
}
109
111
val isConstant = (target as ? VariableDescriptor )?.let { ! it.isVar() || it.isConst() } ? : false
110
112
val modifiers = if (isConstant) setOf (SemanticTokenModifier .READONLY ) else setOf ()
113
+
111
114
SemanticToken (elementRange, tokenType, modifiers)
112
115
}
113
116
is PsiNameIdentifierOwner -> {
114
117
val tokenType = when (element) {
115
118
is KtProperty -> SemanticTokenType .PROPERTY
116
119
is KtParameter -> SemanticTokenType .PARAMETER
117
120
is KtVariableDeclaration -> SemanticTokenType .VARIABLE
121
+ is KtClassOrObject -> SemanticTokenType .CLASS
118
122
else -> return null
119
123
}
120
124
val identifierRange = element.nameIdentifier?.let { range(file.text, it.textRange) } ? : return null
121
125
val modifiers = mutableSetOf (SemanticTokenModifier .DECLARATION )
122
- val isConstant = (element as ? KtVariableDeclaration )?.let { ! it.isVar() || it.hasModifier(KtTokens .CONST_KEYWORD ) } ? : false
123
- if (isConstant) {
124
- modifiers.add(SemanticTokenModifier .READONLY )
126
+
127
+ if (element is KtVariableDeclaration ) {
128
+ if (! element.isVar() || element.hasModifier(KtTokens .CONST_KEYWORD )) {
129
+ modifiers.add(SemanticTokenModifier .READONLY )
130
+ }
125
131
}
132
+
133
+ if (element is KtModifierListOwner ) {
134
+ if (element.hasModifier(KtTokens .ABSTRACT_KEYWORD )) {
135
+ modifiers.add(SemanticTokenModifier .ABSTRACT )
136
+ }
137
+ }
138
+
126
139
SemanticToken (identifierRange, tokenType, modifiers)
127
140
}
128
141
else -> null
0 commit comments