mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Change return types of custom requests
This commit is contained in:
parent
bf825c20ff
commit
02fa158a0d
8 changed files with 28 additions and 22 deletions
|
|
@ -5,15 +5,15 @@ import org.eclipse.lsp4j.jsonrpc.services.JsonRequest
|
|||
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment
|
||||
import org.eclipse.lsp4j.services.TextDocumentService
|
||||
import texlab.build.BuildParams
|
||||
import texlab.build.BuildStatus
|
||||
import texlab.forwardSearch.ForwardSearchStatus
|
||||
import texlab.build.BuildResult
|
||||
import texlab.search.ForwardSearchResult
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
@JsonSegment("textDocument")
|
||||
interface CustomTextDocumentService : TextDocumentService {
|
||||
@JsonRequest
|
||||
fun build(params: BuildParams): CompletableFuture<BuildStatus>
|
||||
fun build(params: BuildParams): CompletableFuture<BuildResult>
|
||||
|
||||
@JsonRequest
|
||||
fun forwardSearch(params: TextDocumentPositionParams): CompletableFuture<ForwardSearchStatus>
|
||||
fun forwardSearch(params: TextDocumentPositionParams): CompletableFuture<ForwardSearchResult>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either
|
|||
import texlab.build.BuildConfig
|
||||
import texlab.build.BuildEngine
|
||||
import texlab.build.BuildParams
|
||||
import texlab.build.BuildStatus
|
||||
import texlab.build.BuildResult
|
||||
import texlab.completion.*
|
||||
import texlab.completion.bibtex.BibtexEntryTypeProvider
|
||||
import texlab.completion.bibtex.BibtexFieldNameProvider
|
||||
|
|
@ -20,9 +20,6 @@ import texlab.diagnostics.*
|
|||
import texlab.folding.*
|
||||
import texlab.formatting.BibtexFormatter
|
||||
import texlab.formatting.BibtexFormatterConfig
|
||||
import texlab.forwardSearch.ForwardSearchConfig
|
||||
import texlab.forwardSearch.ForwardSearchStatus
|
||||
import texlab.forwardSearch.ForwardSearchTool
|
||||
import texlab.highlight.AggregateHighlightProvider
|
||||
import texlab.highlight.HighlightProvider
|
||||
import texlab.highlight.HighlightRequest
|
||||
|
|
@ -39,6 +36,9 @@ import texlab.rename.*
|
|||
import texlab.resolver.InvalidTexDistributionException
|
||||
import texlab.resolver.LatexResolver
|
||||
import texlab.resolver.TexDistributionError
|
||||
import texlab.search.ForwardSearchConfig
|
||||
import texlab.search.ForwardSearchResult
|
||||
import texlab.search.ForwardSearchTool
|
||||
import texlab.symbol.*
|
||||
import texlab.syntax.bibtex.BibtexDeclarationSyntax
|
||||
import java.io.File
|
||||
|
|
@ -371,7 +371,7 @@ class TextDocumentServiceImpl(val workspace: Workspace) : CustomTextDocumentServ
|
|||
}
|
||||
}
|
||||
|
||||
override fun build(params: BuildParams): CompletableFuture<BuildStatus> = future {
|
||||
override fun build(params: BuildParams): CompletableFuture<BuildResult> = future {
|
||||
val childUri = URIHelper.parse(params.textDocument.uri)
|
||||
val parent = workspace.withLock {
|
||||
workspace.findParent(childUri)
|
||||
|
|
@ -382,7 +382,7 @@ class TextDocumentServiceImpl(val workspace: Workspace) : CustomTextDocumentServ
|
|||
}
|
||||
|
||||
override fun forwardSearch(params: TextDocumentPositionParams)
|
||||
: CompletableFuture<ForwardSearchStatus> = future {
|
||||
: CompletableFuture<ForwardSearchResult> = future {
|
||||
val childUri = URIHelper.parse(params.textDocument.uri)
|
||||
val parent = workspace.withLock {
|
||||
workspace.findParent(childUri)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import java.net.URI
|
|||
import java.nio.file.Paths
|
||||
|
||||
object BuildEngine {
|
||||
suspend fun build(uri: URI, config: BuildConfig, listener: ProgressListener?): BuildStatus {
|
||||
suspend fun build(uri: URI, config: BuildConfig, listener: ProgressListener?): BuildResult {
|
||||
val texFile = Paths.get(uri).toFile()
|
||||
val progressParams = ProgressParams("build", "Building...", texFile.name)
|
||||
listener?.onReportProgress(progressParams)
|
||||
|
|
@ -41,13 +41,14 @@ object BuildEngine {
|
|||
throw e
|
||||
}
|
||||
|
||||
if (process.exitValue() == 0) {
|
||||
val status = if (process.exitValue() == 0) {
|
||||
BuildStatus.SUCCESS
|
||||
} else {
|
||||
BuildStatus.ERROR
|
||||
}
|
||||
BuildResult(status)
|
||||
} catch (e: IOException) {
|
||||
BuildStatus.FAILURE
|
||||
BuildResult(BuildStatus.FAILURE)
|
||||
} finally {
|
||||
listener?.onReportProgress(progressParams.copy(done = true))
|
||||
}
|
||||
|
|
|
|||
3
src/main/kotlin/texlab/build/BuildResult.kt
Normal file
3
src/main/kotlin/texlab/build/BuildResult.kt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package texlab.build
|
||||
|
||||
data class BuildResult(val status: BuildStatus)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package texlab.forwardSearch
|
||||
package texlab.search
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
3
src/main/kotlin/texlab/search/ForwardSearchResult.kt
Normal file
3
src/main/kotlin/texlab/search/ForwardSearchResult.kt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package texlab.search
|
||||
|
||||
data class ForwardSearchResult(val status: ForwardSearchStatus)
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package texlab.forwardSearch
|
||||
package texlab.search
|
||||
|
||||
enum class ForwardSearchStatus(val value: Int) {
|
||||
SUCCESS(0),
|
||||
ERROR(1),
|
||||
UNCONFIGURED(2);
|
||||
}
|
||||
|
||||
|
|
@ -1,14 +1,11 @@
|
|||
package texlab.forwardSearch
|
||||
package texlab.search
|
||||
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.file.Paths
|
||||
|
||||
object ForwardSearchTool {
|
||||
fun search(file: File,
|
||||
parent: File,
|
||||
lineNumber: Int,
|
||||
config: ForwardSearchConfig): ForwardSearchStatus {
|
||||
fun search(file: File, parent: File, lineNumber: Int, config: ForwardSearchConfig): ForwardSearchResult {
|
||||
val pdfFile = Paths.get(parent.parent, parent.nameWithoutExtension + ".pdf").toString()
|
||||
|
||||
fun replacePlaceholder(argument: String): String {
|
||||
|
|
@ -19,14 +16,14 @@ object ForwardSearchTool {
|
|||
}
|
||||
|
||||
if (config.executable == null) {
|
||||
return ForwardSearchStatus.UNCONFIGURED
|
||||
return ForwardSearchResult(ForwardSearchStatus.UNCONFIGURED)
|
||||
}
|
||||
|
||||
val args = config.args
|
||||
.map { replacePlaceholder(it) }
|
||||
.toTypedArray()
|
||||
val command = listOf(config.executable, *args)
|
||||
return try {
|
||||
val status = try {
|
||||
val process = ProcessBuilder(command)
|
||||
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
||||
.redirectError(ProcessBuilder.Redirect.PIPE)
|
||||
|
|
@ -36,5 +33,6 @@ object ForwardSearchTool {
|
|||
} catch (e: IOException) {
|
||||
ForwardSearchStatus.ERROR
|
||||
}
|
||||
return ForwardSearchResult(status)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue