@@ -6,7 +6,7 @@ import org.eclipse.lsp4j.SemanticTokensLegend
6
6
import org.eclipse.lsp4j.Range
7
7
import org.javacs.kt.position.range
8
8
import org.javacs.kt.util.preOrderTraversal
9
- import org.jetbrains.kotlin.psi.KtProperty
9
+ import org.jetbrains.kotlin.psi.KtNameReferenceExpression
10
10
import org.jetbrains.kotlin.psi.KtVariableDeclaration
11
11
import org.jetbrains.kotlin.psi.KtNamedDeclaration
12
12
import com.intellij.psi.PsiElement
@@ -38,9 +38,9 @@ private fun encodeTokens(tokens: Sequence<SemanticToken>): List<Int> {
38
38
for (token in tokens) {
39
39
// Tokens must be on a single line
40
40
if (token.range.start.line == token.range.end.line) {
41
- val deltaLine = token.range.start.line - (last?.let { it.range.start.line } ? : 0 )
42
- val deltaStart = token.range.start.character - (last?.let { it.range.start.character } ? : 0 )
43
41
val length = token.range.end.character - token.range.start.character
42
+ val deltaLine = token.range.start.line - (last?.range?.start?.line ? : 0 )
43
+ val deltaStart = token.range.start.character - (last?.takeIf { deltaLine == 0 }?.range?.start?.character ? : 0 )
44
44
45
45
encoded.add(deltaLine)
46
46
encoded.add(deltaStart)
@@ -63,15 +63,16 @@ private fun encodeModifiers(modifiers: Set<SemanticTokenModifier>): Int = modifi
63
63
64
64
private fun elementTokens (element : PsiElement ): Sequence <SemanticToken > = element
65
65
.preOrderTraversal()
66
- .mapNotNull { (it as ? KtNamedDeclaration )?.nameIdentifier }
66
+ // .mapNotNull { (it as? KtNamedDeclaration)?.nameIdentifier }
67
67
.mapNotNull { elementToken(it) }
68
68
69
69
private fun elementToken (element : PsiElement ): SemanticToken ? {
70
70
val file = element.containingFile
71
71
val elementRange = range(file.text, element.textRange)
72
72
return when (element) {
73
- is KtProperty -> SemanticToken (elementRange, SemanticTokenType .PROPERTY )
74
- is KtVariableDeclaration -> SemanticToken (elementRange, SemanticTokenType .VARIABLE )
73
+ is KtNameReferenceExpression -> SemanticToken (elementRange, SemanticTokenType .VARIABLE )
74
+ // is KtProperty -> SemanticToken(elementRange, SemanticTokenType.PROPERTY)
75
+ // is KtVariableDeclaration -> SemanticToken(elementRange, SemanticTokenType.VARIABLE)
75
76
else -> null
76
77
}
77
78
}
0 commit comments