Skip to content

Commit 8a26084

Browse files
committed
Prove semantic tokens for variable declarations
1 parent ea38c1b commit 8a26084

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptor
1515
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
1616
import org.jetbrains.kotlin.psi.KtVariableDeclaration
1717
import org.jetbrains.kotlin.psi.KtNamedDeclaration
18+
import org.jetbrains.kotlin.psi.KtProperty
19+
import org.jetbrains.kotlin.psi.KtParameter
1820
import org.jetbrains.kotlin.resolve.BindingContext
1921
import com.intellij.psi.PsiElement
22+
import com.intellij.psi.PsiNameIdentifierOwner
2023

2124
private enum class SemanticTokenType(val typeName: String) {
2225
VARIABLE(SemanticTokenTypes.Variable),
2326
FUNCTION(SemanticTokenTypes.Function),
2427
PROPERTY(SemanticTokenTypes.Property),
28+
PARAMETER(SemanticTokenTypes.Parameter),
2529
ENUM_MEMBER(SemanticTokenTypes.EnumMember),
2630
CLASS(SemanticTokenTypes.Class),
2731
INTERFACE(SemanticTokenTypes.Interface),
@@ -99,6 +103,17 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
99103
}
100104
SemanticToken(elementRange, tokenType)
101105
}
106+
is PsiNameIdentifierOwner -> {
107+
val tokenType = when (element) {
108+
is KtProperty -> SemanticTokenType.PROPERTY
109+
is KtParameter -> SemanticTokenType.PARAMETER
110+
is KtVariableDeclaration -> SemanticTokenType.VARIABLE
111+
else -> return null
112+
}
113+
val identifierRange = element.nameIdentifier?.let { range(file.text, it.textRange) } ?: return null
114+
val modifiers = setOf(SemanticTokenModifier.DECLARATION)
115+
SemanticToken(identifierRange, tokenType, modifiers)
116+
}
102117
else -> null
103118
}
104119
}

0 commit comments

Comments
 (0)