diff --git a/gradle.properties b/gradle.properties index e0aa80117..68abee22c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ projectVersion=1.3.2 kotlinVersion=1.6.10 exposedVersion=0.37.3 -lsp4jVersion=0.12.0 +lsp4jVersion=0.14.0 javaVersion=11 diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt index d74d84540..1b483632a 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt @@ -156,6 +156,7 @@ class KotlinTextDocumentService( TODO("not implemented") } + @Suppress("DEPRECATION") override fun documentSymbol(params: DocumentSymbolParams): CompletableFuture>> = async.compute { LOG.info("Find symbols in {}", describeURI(params.textDocument.uri)) diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt b/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt index 470853cc4..766f76a5a 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt @@ -1,6 +1,5 @@ package org.javacs.kt -import com.intellij.openapi.project.Project import org.eclipse.lsp4j.* import org.eclipse.lsp4j.services.WorkspaceService import org.eclipse.lsp4j.services.LanguageClient @@ -9,12 +8,9 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either import org.javacs.kt.symbols.workspaceSymbols import org.javacs.kt.command.JAVA_TO_KOTLIN_COMMAND import org.javacs.kt.j2k.convertJavaToKotlin -import org.javacs.kt.KotlinTextDocumentService import org.javacs.kt.position.extractRange import org.javacs.kt.util.filePath import org.javacs.kt.util.parseURI -import org.javacs.kt.resolve.resolveMain -import java.net.URI import java.nio.file.Paths import java.util.concurrent.CompletableFuture import com.google.gson.JsonElement @@ -30,7 +26,7 @@ class KotlinWorkspaceService( ) : WorkspaceService, LanguageClientAware { private val gson = Gson() private var languageClient: LanguageClient? = null - + override fun connect(client: LanguageClient): Unit { languageClient = client } @@ -143,10 +139,11 @@ class KotlinWorkspaceService( LOG.info("Updated configuration: {}", settings) } - override fun symbol(params: WorkspaceSymbolParams): CompletableFuture> { + @Suppress("DEPRECATION") + override fun symbol(params: WorkspaceSymbolParams): CompletableFuture, List>> { val result = workspaceSymbols(params.query, sp) - return CompletableFuture.completedFuture(result) + return CompletableFuture.completedFuture(Either.forRight(result)) } override fun didChangeWorkspaceFolders(params: DidChangeWorkspaceFoldersParams) { diff --git a/server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt b/server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt index 8255992aa..cee4dbe42 100644 --- a/server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt +++ b/server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt @@ -1,10 +1,13 @@ +@file:Suppress("DEPRECATION") + package org.javacs.kt.symbols import com.intellij.psi.PsiElement -import org.eclipse.lsp4j.Location import org.eclipse.lsp4j.SymbolInformation import org.eclipse.lsp4j.SymbolKind import org.eclipse.lsp4j.DocumentSymbol +import org.eclipse.lsp4j.WorkspaceSymbol +import org.eclipse.lsp4j.WorkspaceSymbolLocation import org.eclipse.lsp4j.jsonrpc.messages.Either import org.javacs.kt.SourcePath import org.javacs.kt.position.range @@ -15,7 +18,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.parents fun documentSymbols(file: KtFile): List> = - doDocumentSymbols(file).map { Either.forRight(it) } + doDocumentSymbols(file).map { Either.forRight(it) } private fun doDocumentSymbols(element: PsiElement): List { val children = element.children.flatMap(::doDocumentSymbols) @@ -30,10 +33,10 @@ private fun doDocumentSymbols(element: PsiElement): List { } ?: children } -fun workspaceSymbols(query: String, sp: SourcePath): List = +fun workspaceSymbols(query: String, sp: SourcePath): List = doWorkspaceSymbols(sp) .filter { containsCharactersInOrder(it.name!!, query, false) } - .mapNotNull(::symbolInformation) + .mapNotNull(::workspaceSymbol) .toList() private fun doWorkspaceSymbols(sp: SourcePath): Sequence = @@ -53,10 +56,10 @@ private fun pickImportantElements(node: PsiElement, includeLocals: Boolean): KtN else -> null } -private fun symbolInformation(d: KtNamedDeclaration): SymbolInformation? { +private fun workspaceSymbol(d: KtNamedDeclaration): WorkspaceSymbol? { val name = d.name ?: return null - return SymbolInformation(name, symbolKind(d), symbolLocation(d), symbolContainer(d)) + return WorkspaceSymbol(name, symbolKind(d), Either.forRight(workspaceLocation(d)), symbolContainer(d)) } private fun symbolKind(d: KtNamedDeclaration): SymbolKind = @@ -70,12 +73,11 @@ private fun symbolKind(d: KtNamedDeclaration): SymbolKind = else -> throw IllegalArgumentException("Unexpected symbol $d") } -private fun symbolLocation(d: KtNamedDeclaration): Location { +private fun workspaceLocation(d: KtNamedDeclaration): WorkspaceSymbolLocation { val file = d.containingFile val uri = file.toPath().toUri().toString() - val range = range(file.text, d.textRange) - return Location(uri, range) + return WorkspaceSymbolLocation(uri) } private fun symbolContainer(d: KtNamedDeclaration): String? = diff --git a/server/src/test/kotlin/org/javacs/kt/WorkspaceSymbolsTest.kt b/server/src/test/kotlin/org/javacs/kt/WorkspaceSymbolsTest.kt index 80e70bc1d..5c4ebf2fa 100644 --- a/server/src/test/kotlin/org/javacs/kt/WorkspaceSymbolsTest.kt +++ b/server/src/test/kotlin/org/javacs/kt/WorkspaceSymbolsTest.kt @@ -5,12 +5,11 @@ import org.eclipse.lsp4j.WorkspaceSymbolParams import org.hamcrest.Matchers.hasItem import org.hamcrest.Matchers.not import org.junit.Assert.assertThat -import org.junit.Before import org.junit.Test class WorkspaceSymbolsTest : SingleFileTestFixture("symbols", "DocumentSymbols.kt") { @Test fun `find symbols in OtherFileSymbols`() { - val found = languageServer.workspaceService.symbol(WorkspaceSymbolParams("")).get() + val found = languageServer.workspaceService.symbol(WorkspaceSymbolParams("")).get().right val byKind = found.groupBy({ it.kind }, { it.name }) val all = found.map { it.name }.toList()