Skip to content

Commit a242db5

Browse files
committed
Provide semantic tokens for literals
1 parent 2a0531c commit a242db5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ import org.jetbrains.kotlin.psi.KtVariableDeclaration
2222
import org.jetbrains.kotlin.psi.KtNamedDeclaration
2323
import org.jetbrains.kotlin.psi.KtProperty
2424
import org.jetbrains.kotlin.psi.KtParameter
25+
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
2526
import org.jetbrains.kotlin.resolve.BindingContext
2627
import com.intellij.psi.PsiElement
2728
import com.intellij.psi.PsiNameIdentifierOwner
29+
import com.intellij.psi.PsiLiteralExpression
30+
import com.intellij.psi.PsiType
2831
import com.intellij.openapi.util.TextRange
2932

3033
enum class SemanticTokenType(val typeName: String) {
@@ -37,7 +40,9 @@ enum class SemanticTokenType(val typeName: String) {
3740
CLASS(SemanticTokenTypes.Class),
3841
INTERFACE(SemanticTokenTypes.Interface),
3942
ENUM(SemanticTokenTypes.Enum),
40-
TYPE(SemanticTokenTypes.Type)
43+
TYPE(SemanticTokenTypes.Type),
44+
STRING(SemanticTokenTypes.String),
45+
NUMBER(SemanticTokenTypes.Number)
4146
}
4247

4348
enum class SemanticTokenModifier(val modifierName: String) {
@@ -160,6 +165,15 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
160165

161166
SemanticToken(identifierRange, tokenType, modifiers)
162167
}
168+
is KtStringTemplateExpression -> SemanticToken(elementRange, SemanticTokenType.STRING)
169+
is PsiLiteralExpression -> {
170+
val tokenType = when (element.type) {
171+
PsiType.INT, PsiType.LONG, PsiType.DOUBLE -> SemanticTokenType.NUMBER
172+
PsiType.CHAR -> SemanticTokenType.STRING
173+
else -> return null
174+
}
175+
SemanticToken(elementRange, tokenType)
176+
}
163177
else -> null
164178
}
165179
}

0 commit comments

Comments
 (0)