Skip to content

Commit 2dac9ea

Browse files
committed
Check for const keyword in semantic tokens
1 parent b39050e commit 2dac9ea

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

server/src/main/kotlin/org/javacs/kt/semantictokens/SemanticTokens.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
1212
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
1313
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
1414
import org.jetbrains.kotlin.descriptors.VariableDescriptor
15+
import org.jetbrains.kotlin.lexer.KtTokens
1516
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
1617
import org.jetbrains.kotlin.psi.KtVariableDeclaration
1718
import org.jetbrains.kotlin.psi.KtNamedDeclaration
@@ -22,6 +23,7 @@ import com.intellij.psi.PsiElement
2223
import com.intellij.psi.PsiNameIdentifierOwner
2324

2425
private enum class SemanticTokenType(val typeName: String) {
26+
KEYWORD(SemanticTokenTypes.Keyword),
2527
VARIABLE(SemanticTokenTypes.Variable),
2628
FUNCTION(SemanticTokenTypes.Function),
2729
PROPERTY(SemanticTokenTypes.Property),
@@ -117,7 +119,7 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
117119
}
118120
val identifierRange = element.nameIdentifier?.let { range(file.text, it.textRange) } ?: return null
119121
val modifiers = mutableSetOf(SemanticTokenModifier.DECLARATION)
120-
val isConstant = (element as? KtVariableDeclaration)?.let { !it.isVar() } ?: false
122+
val isConstant = (element as? KtVariableDeclaration)?.let { !it.isVar() || it.hasModifier(KtTokens.CONST_KEYWORD) } ?: false
121123
if (isConstant) {
122124
modifiers.add(SemanticTokenModifier.READONLY)
123125
}

0 commit comments

Comments
 (0)