Skip to content

Upgrade lsp4j version to 0.14.0 #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class KotlinTextDocumentService(
TODO("not implemented")
}

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

Expand Down
11 changes: 4 additions & 7 deletions server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -143,10 +139,11 @@ class KotlinWorkspaceService(
LOG.info("Updated configuration: {}", settings)
}

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

return CompletableFuture.completedFuture(result)
return CompletableFuture.completedFuture(Either.forRight(result))
}

override fun didChangeWorkspaceFolders(params: DidChangeWorkspaceFoldersParams) {
Expand Down
20 changes: 11 additions & 9 deletions server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +18,7 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.parents

fun documentSymbols(file: KtFile): List<Either<SymbolInformation, DocumentSymbol>> =
doDocumentSymbols(file).map { Either.forRight<SymbolInformation, DocumentSymbol>(it) }
doDocumentSymbols(file).map { Either.forRight(it) }

private fun doDocumentSymbols(element: PsiElement): List<DocumentSymbol> {
val children = element.children.flatMap(::doDocumentSymbols)
Expand All @@ -30,10 +33,10 @@ private fun doDocumentSymbols(element: PsiElement): List<DocumentSymbol> {
} ?: children
}

fun workspaceSymbols(query: String, sp: SourcePath): List<SymbolInformation> =
fun workspaceSymbols(query: String, sp: SourcePath): List<WorkspaceSymbol> =
doWorkspaceSymbols(sp)
.filter { containsCharactersInOrder(it.name!!, query, false) }
.mapNotNull(::symbolInformation)
.mapNotNull(::workspaceSymbol)
.toList()

private fun doWorkspaceSymbols(sp: SourcePath): Sequence<KtNamedDeclaration> =
Expand All @@ -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 =
Expand All @@ -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? =
Expand Down
3 changes: 1 addition & 2 deletions server/src/test/kotlin/org/javacs/kt/WorkspaceSymbolsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down