mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Add server status protocol extension
This commit is contained in:
parent
6b52898b25
commit
e042ef0b61
6 changed files with 37 additions and 9 deletions
9
src/main/kotlin/texlab/LanguageClientExtensions.kt
Normal file
9
src/main/kotlin/texlab/LanguageClientExtensions.kt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package texlab
|
||||
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
|
||||
import org.eclipse.lsp4j.services.LanguageClient
|
||||
|
||||
interface LanguageClientExtensions : LanguageClient {
|
||||
@JsonNotification("window/setStatus")
|
||||
fun setStatus(statusParams: StatusParams)
|
||||
}
|
||||
|
|
@ -3,7 +3,9 @@ package texlab
|
|||
import org.eclipse.lsp4j.*
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest
|
||||
import org.eclipse.lsp4j.services.*
|
||||
import org.eclipse.lsp4j.services.LanguageServer
|
||||
import org.eclipse.lsp4j.services.TextDocumentService
|
||||
import org.eclipse.lsp4j.services.WorkspaceService
|
||||
import texlab.build.BuildConfig
|
||||
import texlab.build.BuildEngine
|
||||
import texlab.build.BuildParams
|
||||
|
|
@ -16,13 +18,13 @@ import java.nio.file.Path
|
|||
import java.nio.file.Paths
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class LanguageServerImpl : LanguageServer, LanguageClientAware {
|
||||
class LanguageServerImpl : LanguageServer {
|
||||
private val workspace: Workspace = Workspace()
|
||||
private val textDocumentService = TextDocumentServiceImpl(workspace)
|
||||
private val workspaceService = WorkspaceServiceImpl()
|
||||
private lateinit var client: LanguageClient
|
||||
private lateinit var client: LanguageClientExtensions
|
||||
|
||||
override fun connect(client: LanguageClient) {
|
||||
fun connect(client: LanguageClientExtensions) {
|
||||
this.client = client
|
||||
this.textDocumentService.client = client
|
||||
}
|
||||
|
|
@ -50,6 +52,10 @@ class LanguageServerImpl : LanguageServer, LanguageClientAware {
|
|||
}
|
||||
}
|
||||
|
||||
override fun initialized(params: InitializedParams?) {
|
||||
client.setStatus(StatusParams(ServerStatus.IDLE, null))
|
||||
}
|
||||
|
||||
private fun loadWorkspace(root: URI) {
|
||||
if (root.scheme == "file") {
|
||||
val matcher = FileSystems.getDefault().getPathMatcher("glob:**.{tex,sty,cls,bib}")
|
||||
|
|
@ -94,6 +100,9 @@ class LanguageServerImpl : LanguageServer, LanguageClientAware {
|
|||
.firstOrNull { it.tree.isStandalone }
|
||||
?: workspace.documents.first { it.uri == childUri }
|
||||
|
||||
val parentName = Paths.get(parent.uri).fileName
|
||||
client.setStatus(StatusParams(ServerStatus.BUILDING, parentName.toString()))
|
||||
|
||||
val config = client.configuration<BuildConfig>("latex.build", parent.uri)
|
||||
val (status, allErrors) = BuildEngine.build(parent.uri, config)
|
||||
|
||||
|
|
@ -106,7 +115,8 @@ class LanguageServerImpl : LanguageServer, LanguageClientAware {
|
|||
val diagnostics = PublishDiagnosticsParams(uri.toString(), errors.map { it.toDiagnostic() })
|
||||
client.publishDiagnostics(diagnostics)
|
||||
}
|
||||
|
||||
|
||||
client.setStatus(StatusParams(ServerStatus.IDLE))
|
||||
status
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package texlab
|
||||
|
||||
import org.eclipse.lsp4j.launch.LSPLauncher
|
||||
import org.eclipse.lsp4j.jsonrpc.Launcher
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val server = LanguageServerImpl()
|
||||
val launcher = LSPLauncher.createServerLauncher(server, System.`in`, System.out)
|
||||
val launcher = Launcher.createLauncher(server, LanguageClientExtensions::class.java, System.`in`, System.out)
|
||||
server.connect(launcher.remoteProxy)
|
||||
launcher.startListening().get()
|
||||
}
|
||||
|
|
|
|||
7
src/main/kotlin/texlab/ServerStatus.kt
Normal file
7
src/main/kotlin/texlab/ServerStatus.kt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package texlab
|
||||
|
||||
enum class ServerStatus(val value: Int) {
|
||||
IDLE(0),
|
||||
BUILDING(1),
|
||||
INDEXING(2),
|
||||
}
|
||||
3
src/main/kotlin/texlab/StatusParams.kt
Normal file
3
src/main/kotlin/texlab/StatusParams.kt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package texlab
|
||||
|
||||
data class StatusParams(val status: ServerStatus, val uri: String? = null)
|
||||
|
|
@ -2,7 +2,6 @@ package texlab
|
|||
|
||||
import org.eclipse.lsp4j.*
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either
|
||||
import org.eclipse.lsp4j.services.LanguageClient
|
||||
import org.eclipse.lsp4j.services.TextDocumentService
|
||||
import texlab.completion.AggregateCompletionProvider
|
||||
import texlab.completion.CompletionRequest
|
||||
|
|
@ -21,7 +20,7 @@ import java.net.URI
|
|||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class TextDocumentServiceImpl(private val workspace: Workspace) : TextDocumentService {
|
||||
lateinit var client: LanguageClient
|
||||
lateinit var client: LanguageClientExtensions
|
||||
|
||||
private val resolver = LatexResolver.create()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue