Skip to content

Commit b39050e

Browse files
committed
Add semantic token modifier for constants
1 parent 8a26084 commit b39050e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ private enum class SemanticTokenType(val typeName: String) {
3535

3636
private enum class SemanticTokenModifier(val modifierName: String) {
3737
DECLARATION(SemanticTokenModifiers.Declaration),
38-
DEFINITION(SemanticTokenModifiers.Definition)
38+
DEFINITION(SemanticTokenModifiers.Definition),
39+
ABSTRACT(SemanticTokenModifiers.Abstract),
40+
STATIC(SemanticTokenModifiers.Static),
41+
READONLY(SemanticTokenModifiers.Readonly)
3942
}
4043

4144
val semanticTokensLegend = SemanticTokensLegend(
@@ -101,7 +104,9 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
101104
}
102105
else -> return null
103106
}
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)
105110
}
106111
is PsiNameIdentifierOwner -> {
107112
val tokenType = when (element) {
@@ -111,7 +116,11 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
111116
else -> return null
112117
}
113118
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+
}
115124
SemanticToken(identifierRange, tokenType, modifiers)
116125
}
117126
else -> null

0 commit comments

Comments
 (0)