Skip to content

Commit ea38c1b

Browse files
committed
Prove more fine-grained semantic tokens for types
1 parent 8361f9b commit ea38c1b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class KotlinTextDocumentService(
231231

232232
reportTime {
233233
val uri = parseURI(params.textDocument.uri)
234-
val file = sp.latestCompiledVersion(uri)
234+
val file = sp.currentVersion(uri)
235235

236236
val tokens = semanticTokens(file)
237237
LOG.info("Found {} tokens", tokens.size)

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import org.eclipse.lsp4j.Range
77
import org.javacs.kt.CompiledFile
88
import org.javacs.kt.position.range
99
import org.javacs.kt.util.preOrderTraversal
10-
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
10+
import org.jetbrains.kotlin.descriptors.ClassDescriptor
11+
import org.jetbrains.kotlin.descriptors.ClassKind
1112
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
1213
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
1314
import org.jetbrains.kotlin.descriptors.VariableDescriptor
@@ -22,6 +23,9 @@ private enum class SemanticTokenType(val typeName: String) {
2223
FUNCTION(SemanticTokenTypes.Function),
2324
PROPERTY(SemanticTokenTypes.Property),
2425
ENUM_MEMBER(SemanticTokenTypes.EnumMember),
26+
CLASS(SemanticTokenTypes.Class),
27+
INTERFACE(SemanticTokenTypes.Interface),
28+
ENUM(SemanticTokenTypes.Enum),
2529
TYPE(SemanticTokenTypes.Type)
2630
}
2731

@@ -84,7 +88,13 @@ private fun elementToken(element: PsiElement, bindingContext: BindingContext): S
8488
is PropertyDescriptor -> SemanticTokenType.PROPERTY
8589
is VariableDescriptor -> SemanticTokenType.VARIABLE
8690
is FunctionDescriptor -> SemanticTokenType.FUNCTION
87-
is ClassifierDescriptor -> SemanticTokenType.TYPE
91+
is ClassDescriptor -> when (target.kind) {
92+
ClassKind.CLASS -> SemanticTokenType.CLASS
93+
ClassKind.OBJECT -> SemanticTokenType.CLASS
94+
ClassKind.INTERFACE -> SemanticTokenType.INTERFACE
95+
ClassKind.ENUM_CLASS -> SemanticTokenType.ENUM
96+
else -> SemanticTokenType.TYPE
97+
}
8898
else -> return null
8999
}
90100
SemanticToken(elementRange, tokenType)

0 commit comments

Comments
 (0)