Skip to content

Commit

Permalink
Fix detekt violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenz Bateman committed Mar 13, 2024
1 parent 2ae1252 commit 1abe6bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
9 changes: 6 additions & 3 deletions server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ class KotlinLanguageServer(
serverCapabilities.renameProvider = Either.forRight(RenameOptions(false))
}

config.workspace.symbolResolveSupport = clientCapabilities?.workspace?.symbol?.resolveSupport?.properties?.let { properties ->
if (properties.size > 0) SymbolResolveSupport(true, properties) else null
} ?: SymbolResolveSupport(false, emptyList())
config.workspace.symbolResolveSupport = clientHasWorkspaceSymbolResolveSupport(clientCapabilities)

@Suppress("DEPRECATION")
val folders = params.workspaceFolders?.takeIf { it.isNotEmpty() }
Expand Down Expand Up @@ -145,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())

private fun connectLoggingBackend() {
val backend: (LogMessage) -> Unit = {
client.logMessage(MessageParams().apply {
Expand Down
29 changes: 11 additions & 18 deletions server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ private fun pickImportantElements(node: PsiElement, includeLocals: Boolean): KtN
}

private fun workspaceSymbol(locationRequired: Boolean): (KtNamedDeclaration) -> WorkspaceSymbol? {
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))
Either.forRight(WorkspaceSymbolLocation(d.containingFile.toURIString()))
}

location?.let { WorkspaceSymbol(name, symbolKind(d), it, symbolContainer(d)) }
Expand All @@ -82,23 +92,6 @@ private fun symbolKind(d: KtNamedDeclaration): SymbolKind =
else -> throw IllegalArgumentException("Unexpected symbol $d")
}

private fun location(d: KtNamedDeclaration): Location? =
try {
val content = d.containingFile?.text
val locationInContent = (d.nameIdentifier?.textRange ?: d.textRange)
if (content != null && locationInContent != null) {
Location(d.containingFile.toURIString(), range(content, locationInContent))
} else {
null
}
} catch (e: Exception) {
null
}


private fun workspaceSymbolLocation(d: KtNamedDeclaration): WorkspaceSymbolLocation =
WorkspaceSymbolLocation(d.containingFile.toURIString())

private fun symbolContainer(d: KtNamedDeclaration): String? =
d.parents
.filterIsInstance<KtNamedDeclaration>()
Expand Down

0 comments on commit 1abe6bf

Please sign in to comment.