Skip to content

Commit b0f06de

Browse files
author
Omar El Halabi
committed
Upgrade lsp4j version to 0.14.0
1 parent 8d8af15 commit b0f06de

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
projectVersion=1.3.2
22
kotlinVersion=1.6.10
33
exposedVersion=0.37.3
4-
lsp4jVersion=0.12.0
4+
lsp4jVersion=0.14.0
55
javaVersion=11

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class KotlinTextDocumentService(
156156
TODO("not implemented")
157157
}
158158

159+
@Suppress("DEPRECATION")
159160
override fun documentSymbol(params: DocumentSymbolParams): CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> = async.compute {
160161
LOG.info("Find symbols in {}", describeURI(params.textDocument.uri))
161162

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.javacs.kt
22

3-
import com.intellij.openapi.project.Project
43
import org.eclipse.lsp4j.*
54
import org.eclipse.lsp4j.services.WorkspaceService
65
import org.eclipse.lsp4j.services.LanguageClient
@@ -9,12 +8,9 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either
98
import org.javacs.kt.symbols.workspaceSymbols
109
import org.javacs.kt.command.JAVA_TO_KOTLIN_COMMAND
1110
import org.javacs.kt.j2k.convertJavaToKotlin
12-
import org.javacs.kt.KotlinTextDocumentService
1311
import org.javacs.kt.position.extractRange
1412
import org.javacs.kt.util.filePath
1513
import org.javacs.kt.util.parseURI
16-
import org.javacs.kt.resolve.resolveMain
17-
import java.net.URI
1814
import java.nio.file.Paths
1915
import java.util.concurrent.CompletableFuture
2016
import com.google.gson.JsonElement
@@ -30,7 +26,7 @@ class KotlinWorkspaceService(
3026
) : WorkspaceService, LanguageClientAware {
3127
private val gson = Gson()
3228
private var languageClient: LanguageClient? = null
33-
29+
3430
override fun connect(client: LanguageClient): Unit {
3531
languageClient = client
3632
}
@@ -143,10 +139,11 @@ class KotlinWorkspaceService(
143139
LOG.info("Updated configuration: {}", settings)
144140
}
145141

146-
override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<List<SymbolInformation>> {
142+
@Suppress("DEPRECATION")
143+
override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<Either<List<SymbolInformation>, List<WorkspaceSymbol>>> {
147144
val result = workspaceSymbols(params.query, sp)
148145

149-
return CompletableFuture.completedFuture(result)
146+
return CompletableFuture.completedFuture(Either.forRight(result))
150147
}
151148

152149
override fun didChangeWorkspaceFolders(params: DidChangeWorkspaceFoldersParams) {

server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package org.javacs.kt.symbols
24

35
import com.intellij.psi.PsiElement
4-
import org.eclipse.lsp4j.Location
56
import org.eclipse.lsp4j.SymbolInformation
67
import org.eclipse.lsp4j.SymbolKind
78
import org.eclipse.lsp4j.DocumentSymbol
9+
import org.eclipse.lsp4j.WorkspaceSymbol
10+
import org.eclipse.lsp4j.WorkspaceSymbolLocation
811
import org.eclipse.lsp4j.jsonrpc.messages.Either
912
import org.javacs.kt.SourcePath
1013
import org.javacs.kt.position.range
@@ -15,7 +18,7 @@ import org.jetbrains.kotlin.psi.*
1518
import org.jetbrains.kotlin.psi.psiUtil.parents
1619

1720
fun documentSymbols(file: KtFile): List<Either<SymbolInformation, DocumentSymbol>> =
18-
doDocumentSymbols(file).map { Either.forRight<SymbolInformation, DocumentSymbol>(it) }
21+
doDocumentSymbols(file).map { Either.forRight(it) }
1922

2023
private fun doDocumentSymbols(element: PsiElement): List<DocumentSymbol> {
2124
val children = element.children.flatMap(::doDocumentSymbols)
@@ -30,10 +33,10 @@ private fun doDocumentSymbols(element: PsiElement): List<DocumentSymbol> {
3033
} ?: children
3134
}
3235

33-
fun workspaceSymbols(query: String, sp: SourcePath): List<SymbolInformation> =
36+
fun workspaceSymbols(query: String, sp: SourcePath): List<WorkspaceSymbol> =
3437
doWorkspaceSymbols(sp)
3538
.filter { containsCharactersInOrder(it.name!!, query, false) }
36-
.mapNotNull(::symbolInformation)
39+
.mapNotNull(::workspaceSymbol)
3740
.toList()
3841

3942
private fun doWorkspaceSymbols(sp: SourcePath): Sequence<KtNamedDeclaration> =
@@ -53,10 +56,10 @@ private fun pickImportantElements(node: PsiElement, includeLocals: Boolean): KtN
5356
else -> null
5457
}
5558

56-
private fun symbolInformation(d: KtNamedDeclaration): SymbolInformation? {
59+
private fun workspaceSymbol(d: KtNamedDeclaration): WorkspaceSymbol? {
5760
val name = d.name ?: return null
5861

59-
return SymbolInformation(name, symbolKind(d), symbolLocation(d), symbolContainer(d))
62+
return WorkspaceSymbol(name, symbolKind(d), Either.forRight(workspaceLocation(d)), symbolContainer(d))
6063
}
6164

6265
private fun symbolKind(d: KtNamedDeclaration): SymbolKind =
@@ -70,12 +73,11 @@ private fun symbolKind(d: KtNamedDeclaration): SymbolKind =
7073
else -> throw IllegalArgumentException("Unexpected symbol $d")
7174
}
7275

73-
private fun symbolLocation(d: KtNamedDeclaration): Location {
76+
private fun workspaceLocation(d: KtNamedDeclaration): WorkspaceSymbolLocation {
7477
val file = d.containingFile
7578
val uri = file.toPath().toUri().toString()
76-
val range = range(file.text, d.textRange)
7779

78-
return Location(uri, range)
80+
return WorkspaceSymbolLocation(uri)
7981
}
8082

8183
private fun symbolContainer(d: KtNamedDeclaration): String? =

server/src/test/kotlin/org/javacs/kt/WorkspaceSymbolsTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import org.eclipse.lsp4j.WorkspaceSymbolParams
55
import org.hamcrest.Matchers.hasItem
66
import org.hamcrest.Matchers.not
77
import org.junit.Assert.assertThat
8-
import org.junit.Before
98
import org.junit.Test
109

1110
class WorkspaceSymbolsTest : SingleFileTestFixture("symbols", "DocumentSymbols.kt") {
1211
@Test fun `find symbols in OtherFileSymbols`() {
13-
val found = languageServer.workspaceService.symbol(WorkspaceSymbolParams("")).get()
12+
val found = languageServer.workspaceService.symbol(WorkspaceSymbolParams("")).get().right
1413
val byKind = found.groupBy({ it.kind }, { it.name })
1514
val all = found.map { it.name }.toList()
1615

0 commit comments

Comments
 (0)