mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Implement proposed progress notification
This commit is contained in:
parent
2df5caa1a7
commit
e1497f5802
10 changed files with 39 additions and 41 deletions
|
|
@ -4,6 +4,6 @@ import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
|
|||
import org.eclipse.lsp4j.services.LanguageClient
|
||||
|
||||
interface CustomLanguageClient : LanguageClient {
|
||||
@JsonNotification("window/setStatus")
|
||||
fun setStatus(statusParams: StatusParams)
|
||||
@JsonNotification("window/progress")
|
||||
fun progress(params: ProgressParams)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ class LanguageServerImpl : LanguageServer {
|
|||
}
|
||||
|
||||
override fun initialized(params: InitializedParams?) {
|
||||
client.setStatus(StatusParams(ServerStatus.IDLE, null))
|
||||
}
|
||||
|
||||
private fun loadWorkspace(root: URI) {
|
||||
|
|
|
|||
5
src/main/kotlin/texlab/ProgressListener.kt
Normal file
5
src/main/kotlin/texlab/ProgressListener.kt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package texlab
|
||||
|
||||
interface ProgressListener {
|
||||
fun onReportProgress(params: ProgressParams)
|
||||
}
|
||||
7
src/main/kotlin/texlab/ProgressParams.kt
Normal file
7
src/main/kotlin/texlab/ProgressParams.kt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package texlab
|
||||
|
||||
data class ProgressParams(val id: String,
|
||||
val title: String,
|
||||
val message: String?,
|
||||
val percentage: Number? = null,
|
||||
val done: Boolean? = null)
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package texlab
|
||||
|
||||
enum class ServerStatus(val value: Int) {
|
||||
IDLE(0),
|
||||
BUILDING(1),
|
||||
INDEXING(2),
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
package texlab
|
||||
|
||||
data class StatusParams(val status: ServerStatus, val uri: String? = null)
|
||||
|
|
@ -13,7 +13,6 @@ import texlab.completion.bibtex.BibtexFieldNameProvider
|
|||
import texlab.completion.bibtex.BibtexKernelCommandProvider
|
||||
import texlab.completion.latex.*
|
||||
import texlab.completion.latex.data.LatexComponentDatabase
|
||||
import texlab.completion.latex.data.LatexComponentDatabaseListener
|
||||
import texlab.completion.latex.data.LatexComponentSourcePrefetcher
|
||||
import texlab.completion.latex.data.LatexResolver
|
||||
import texlab.definition.*
|
||||
|
|
@ -48,20 +47,16 @@ import java.util.concurrent.CompletableFuture
|
|||
class TextDocumentServiceImpl(private val workspace: Workspace) : CustomTextDocumentService {
|
||||
lateinit var client: CustomLanguageClient
|
||||
|
||||
private inner class DatabaseListener : LatexComponentDatabaseListener {
|
||||
override fun onStartIndexing(file: File) {
|
||||
client.setStatus(StatusParams(ServerStatus.INDEXING, file.name))
|
||||
}
|
||||
|
||||
override fun onStopIndexing() {
|
||||
client.setStatus(StatusParams(ServerStatus.IDLE))
|
||||
private val progressListener = object : ProgressListener {
|
||||
override fun onReportProgress(params: ProgressParams) {
|
||||
client.progress(params)
|
||||
}
|
||||
}
|
||||
|
||||
private val resolver = LatexResolver.create()
|
||||
private val databaseDirectory = Paths.get(javaClass.protectionDomain.codeSource.location.toURI()).parent
|
||||
private val databaseFile = databaseDirectory.resolve("components.json")
|
||||
private val database = LatexComponentDatabase.loadOrCreate(databaseFile, resolver, DatabaseListener())
|
||||
private val database = LatexComponentDatabase.loadOrCreate(databaseFile, resolver, progressListener)
|
||||
|
||||
init {
|
||||
LatexComponentSourcePrefetcher.start(workspace, database)
|
||||
|
|
@ -337,10 +332,8 @@ class TextDocumentServiceImpl(private val workspace: Workspace) : CustomTextDocu
|
|||
workspace.findParent(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, cancelChecker)
|
||||
val (status, allErrors) = BuildEngine.build(parent.uri, config, cancelChecker, progressListener)
|
||||
|
||||
buildDiagnosticsProvider.diagnosticsByUri = allErrors
|
||||
.groupBy { it.uri }
|
||||
|
|
@ -351,7 +344,6 @@ class TextDocumentServiceImpl(private val workspace: Workspace) : CustomTextDocu
|
|||
publishDiagnostics(document.uri)
|
||||
}
|
||||
}
|
||||
client.setStatus(StatusParams(ServerStatus.IDLE))
|
||||
status
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package texlab.build
|
||||
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker
|
||||
import texlab.ProgressListener
|
||||
import texlab.ProgressParams
|
||||
import java.io.IOException
|
||||
import java.net.URI
|
||||
import java.nio.file.Files
|
||||
|
|
@ -9,8 +11,14 @@ import java.util.concurrent.CancellationException
|
|||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object BuildEngine {
|
||||
fun build(uri: URI, config: BuildConfig, cancelChecker: CancelChecker): BuildResult {
|
||||
fun build(uri: URI,
|
||||
config: BuildConfig,
|
||||
cancelChecker: CancelChecker,
|
||||
listener: ProgressListener?): BuildResult {
|
||||
val texFile = Paths.get(uri).toFile()
|
||||
val progressParams = ProgressParams("build", "Building...", texFile.name)
|
||||
listener?.onReportProgress(progressParams)
|
||||
|
||||
val command = listOf(config.executable, *config.args.toTypedArray(), texFile.absolutePath)
|
||||
return try {
|
||||
val buildLogFile = Paths.get(texFile.parent, "texlab-build.log").toFile()
|
||||
|
|
@ -45,6 +53,8 @@ object BuildEngine {
|
|||
BuildResult(status, errors)
|
||||
} catch (e: IOException) {
|
||||
BuildResult(BuildStatus.FAILURE, emptyList())
|
||||
} finally {
|
||||
listener?.onReportProgress(progressParams.copy(done = true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import com.fasterxml.jackson.module.kotlin.readValue
|
|||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.launch
|
||||
import texlab.ProgressListener
|
||||
import texlab.ProgressParams
|
||||
import texlab.completion.latex.KernelPrimitives
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
|
@ -15,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap
|
|||
class LatexComponentDatabase(private val databaseFile: Path,
|
||||
private val resolver: LatexResolver,
|
||||
components: List<LatexComponent>,
|
||||
private val listener: LatexComponentDatabaseListener?) : LatexComponentSource {
|
||||
private val listener: ProgressListener?) : LatexComponentSource {
|
||||
private val componentsByName = ConcurrentHashMap<String, LatexComponent>()
|
||||
private val channel = Channel<File>(Channel.UNLIMITED)
|
||||
|
||||
|
|
@ -46,7 +48,9 @@ class LatexComponentDatabase(private val databaseFile: Path,
|
|||
return
|
||||
}
|
||||
|
||||
listener?.onStartIndexing(file)
|
||||
val progressParams = ProgressParams("index", "Indexing...", file.name)
|
||||
listener?.onReportProgress(progressParams)
|
||||
|
||||
val unitsByFile = loadRelatedUnits(file)
|
||||
if (unitsByFile == null) {
|
||||
componentsByName[file.name] =
|
||||
|
|
@ -61,7 +65,7 @@ class LatexComponentDatabase(private val databaseFile: Path,
|
|||
|
||||
for (units in components) {
|
||||
val unit = units.first()
|
||||
listener?.onStartIndexing(unit.file)
|
||||
listener?.onReportProgress(progressParams.copy(message = unit.file.name))
|
||||
|
||||
val candidates = unit.likelyPrimitives.toMutableSet()
|
||||
candidates.removeAll(KernelPrimitives.COMMANDS)
|
||||
|
|
@ -78,8 +82,8 @@ class LatexComponentDatabase(private val databaseFile: Path,
|
|||
names.forEach { componentsByName[it] = component }
|
||||
}
|
||||
|
||||
listener?.onReportProgress(progressParams.copy(done = true))
|
||||
save()
|
||||
listener?.onStopIndexing()
|
||||
}
|
||||
|
||||
private fun loadRelatedUnits(file: File): Map<File, LatexUnit>? {
|
||||
|
|
@ -99,7 +103,7 @@ class LatexComponentDatabase(private val databaseFile: Path,
|
|||
companion object {
|
||||
fun loadOrCreate(databaseFile: Path,
|
||||
resolver: LatexResolver,
|
||||
listener: LatexComponentDatabaseListener?): LatexComponentDatabase {
|
||||
listener: ProgressListener?): LatexComponentDatabase {
|
||||
return if (Files.exists(databaseFile)) {
|
||||
val json = Files.readAllBytes(databaseFile).toString(Charsets.UTF_8)
|
||||
val mapper = jacksonObjectMapper()
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
package texlab.completion.latex.data
|
||||
|
||||
import java.io.File
|
||||
|
||||
interface LatexComponentDatabaseListener {
|
||||
fun onStartIndexing(file: File)
|
||||
|
||||
fun onStopIndexing()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue