-
Notifications
You must be signed in to change notification settings - Fork 219
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
Fix compatibility issues + bugs #556
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,8 @@ class KotlinLanguageServer( | |
serverCapabilities.renameProvider = Either.forRight(RenameOptions(false)) | ||
} | ||
|
||
config.workspace.symbolResolveSupport = clientHasWorkspaceSymbolResolveSupport(clientCapabilities) | ||
|
||
@Suppress("DEPRECATION") | ||
val folders = params.workspaceFolders?.takeIf { it.isNotEmpty() } | ||
?: params.rootUri?.let(::WorkspaceFolder)?.let(::listOf) | ||
|
@@ -141,6 +143,11 @@ class KotlinLanguageServer( | |
InitializeResult(serverCapabilities, serverInfo) | ||
} | ||
|
||
private fun clientHasWorkspaceSymbolResolveSupport(clientCapabilities: ClientCapabilities) = | ||
clientCapabilities?.workspace?.symbol?.resolveSupport?.properties?.let { properties -> | ||
if (properties.size > 0) SymbolResolveSupport(true, properties) else null | ||
} ?: SymbolResolveSupport(false, emptyList()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If the function does not return a boolean, its name should not be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went for the SymbolResolveSupport. I think technically more properties can me masked in the symbol calls in the future although the only example of this is the location property, based on the types available for return. |
||
|
||
private fun connectLoggingBackend() { | ||
val backend: (LogMessage) -> Unit = { | ||
client.logMessage(MessageParams().apply { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||
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 | ||||||
|
@@ -11,9 +12,9 @@ import org.eclipse.lsp4j.WorkspaceSymbolLocation | |||||
import org.eclipse.lsp4j.jsonrpc.messages.Either | ||||||
import org.javacs.kt.SourcePath | ||||||
import org.javacs.kt.position.range | ||||||
import org.javacs.kt.position.toURIString | ||||||
import org.javacs.kt.util.containsCharactersInOrder | ||||||
import org.javacs.kt.util.preOrderTraversal | ||||||
import org.javacs.kt.util.toPath | ||||||
import org.jetbrains.kotlin.psi.* | ||||||
import org.jetbrains.kotlin.psi.psiUtil.parents | ||||||
|
||||||
|
@@ -33,10 +34,10 @@ private fun doDocumentSymbols(element: PsiElement): List<DocumentSymbol> { | |||||
} ?: children | ||||||
} | ||||||
|
||||||
fun workspaceSymbols(query: String, sp: SourcePath): List<WorkspaceSymbol> = | ||||||
fun workspaceSymbols(locationRequired: Boolean, query: String, sp: SourcePath): List<WorkspaceSymbol> = | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style nit: I would pass the |
||||||
doWorkspaceSymbols(sp) | ||||||
.filter { containsCharactersInOrder(it.name!!, query, false) } | ||||||
.mapNotNull(::workspaceSymbol) | ||||||
.mapNotNull(workspaceSymbol(locationRequired)) | ||||||
.toList() | ||||||
|
||||||
private fun doWorkspaceSymbols(sp: SourcePath): Sequence<KtNamedDeclaration> = | ||||||
|
@@ -56,10 +57,28 @@ private fun pickImportantElements(node: PsiElement, includeLocals: Boolean): KtN | |||||
else -> null | ||||||
} | ||||||
|
||||||
private fun workspaceSymbol(d: KtNamedDeclaration): WorkspaceSymbol? { | ||||||
val name = d.name ?: return null | ||||||
private fun workspaceSymbol(locationRequired: Boolean): (KtNamedDeclaration) -> WorkspaceSymbol? { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another style nit: Most functions in this codebase are not curried, therefore I would prefer the uncurried versions here too (even though it requires using a lambda at the call site):
Suggested change
This would keep the naming pattern more consistent too (most singular thing-named functions also return the thing in question and not a function). |
||||||
fun location(d: KtNamedDeclaration): Location? { | ||||||
val content = d.containingFile?.text | ||||||
val locationInContent = (d.nameIdentifier?.textRange ?: d.textRange) | ||||||
return if (content != null && locationInContent != null) { | ||||||
Location(d.containingFile.toURIString(), range(content, locationInContent)) | ||||||
} else { | ||||||
null | ||||||
} | ||||||
} | ||||||
|
||||||
return { d -> | ||||||
d.name?.let { name -> | ||||||
val location: Either<Location, WorkspaceSymbolLocation>? = if (locationRequired) { | ||||||
location(d)?.let { l -> Either.forLeft(l) } | ||||||
} else { | ||||||
Either.forRight(WorkspaceSymbolLocation(d.containingFile.toURIString())) | ||||||
} | ||||||
|
||||||
return WorkspaceSymbol(name, symbolKind(d), Either.forRight(workspaceLocation(d)), symbolContainer(d)) | ||||||
location?.let { WorkspaceSymbol(name, symbolKind(d), it, symbolContainer(d)) } | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
private fun symbolKind(d: KtNamedDeclaration): SymbolKind = | ||||||
|
@@ -73,13 +92,6 @@ private fun symbolKind(d: KtNamedDeclaration): SymbolKind = | |||||
else -> throw IllegalArgumentException("Unexpected symbol $d") | ||||||
} | ||||||
|
||||||
private fun workspaceLocation(d: KtNamedDeclaration): WorkspaceSymbolLocation { | ||||||
val file = d.containingFile | ||||||
val uri = file.toPath().toUri().toString() | ||||||
|
||||||
return WorkspaceSymbolLocation(uri) | ||||||
} | ||||||
|
||||||
private fun symbolContainer(d: KtNamedDeclaration): String? = | ||||||
d.parents | ||||||
.filterIsInstance<KtNamedDeclaration>() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configuration classes are intended to map (1-to-1) to the user-provided configuration. I'm not sure how I feel about adding a special case for a value derived from the client capabilities. IMO it would probably be better to just pass the client capabilities to
KotlinWorkspaceService
directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem, I change it to pass the client capabilities into the KotlinWorkspaceService