Skip to content

Commit 7c783c8

Browse files
committed
Scaffold out semantic token support
1 parent f820c26 commit 7c783c8

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.javacs.kt.util.TemporaryDirectory
1414
import org.javacs.kt.util.parseURI
1515
import org.javacs.kt.progress.Progress
1616
import org.javacs.kt.progress.LanguageClientProgress
17+
import org.javacs.kt.semantictokens.semanticTokensLegend
1718
import java.net.URI
1819
import java.io.Closeable
1920
import java.nio.file.Paths
@@ -81,6 +82,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
8182
serverCapabilities.documentSymbolProvider = Either.forLeft(true)
8283
serverCapabilities.workspaceSymbolProvider = Either.forLeft(true)
8384
serverCapabilities.referencesProvider = Either.forLeft(true)
85+
serverCapabilities.semanticTokensProvider = SemanticTokensWithRegistrationOptions(semanticTokensLegend, true)
8486
serverCapabilities.codeActionProvider = Either.forLeft(true)
8587
serverCapabilities.documentFormattingProvider = Either.forLeft(true)
8688
serverCapabilities.documentRangeFormattingProvider = Either.forLeft(true)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,12 @@ class KotlinTextDocumentService(
223223
val offset = offset(content, position.position.line, position.position.character)
224224
findReferences(file, offset, sp)
225225
}
226-
}
226+
}
227+
228+
override fun semanticTokensFull(params: SemanticTokensParams) = async.compute {
229+
// TODO
230+
SemanticTokens(listOf())
231+
}
227232

228233
override fun resolveCodeLens(unresolved: CodeLens): CompletableFuture<CodeLens> {
229234
TODO("not implemented")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.javacs.kt.semantictokens
2+
3+
import org.eclipse.lsp4j.SemanticTokenTypes
4+
import org.eclipse.lsp4j.SemanticTokenModifiers
5+
import org.eclipse.lsp4j.SemanticTokensLegend
6+
import org.eclipse.lsp4j.Range
7+
import org.jetbrains.kotlin.psi.KtElement
8+
9+
private enum class SemanticTokenType(val typeName: String) {
10+
VARIABLE(SemanticTokenTypes.Variable),
11+
PROPERTY(SemanticTokenTypes.Property),
12+
ENUM_MEMBER(SemanticTokenTypes.EnumMember)
13+
}
14+
15+
private enum class SemanticTokenModifier(val modifierName: String) {
16+
DECLARATION(SemanticTokenModifiers.Declaration),
17+
DEFINITION(SemanticTokenModifiers.Definition)
18+
}
19+
20+
val semanticTokensLegend = SemanticTokensLegend(
21+
SemanticTokenType.values().map { it.typeName },
22+
SemanticTokenModifier.values().map { it.modifierName }
23+
)
24+
25+
private data class SemanticToken(val range: Range, val type: SemanticTokenType, val modifiers: Set<SemanticTokenModifier>)
26+
27+
private fun semanticTokens(element: KtElement): List<Int> {
28+
return listOf() // TODO
29+
}
30+

0 commit comments

Comments
 (0)