From bc74bca9ea9113dd4e8665aa54f7852cbeb7b2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20F=C3=B6rster?= Date: Sat, 19 Jan 2019 21:07:16 +0100 Subject: [PATCH] Add option to build on save --- src/main/kotlin/texlab/LanguageServerImpl.kt | 1 + src/main/kotlin/texlab/TextDocumentServiceImpl.kt | 9 +++++++++ src/main/kotlin/texlab/build/BuildConfig.kt | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/texlab/LanguageServerImpl.kt b/src/main/kotlin/texlab/LanguageServerImpl.kt index 75c3e8ef..5ab0ea4e 100644 --- a/src/main/kotlin/texlab/LanguageServerImpl.kt +++ b/src/main/kotlin/texlab/LanguageServerImpl.kt @@ -38,6 +38,7 @@ class LanguageServerImpl : LanguageServer { val capabilities = ServerCapabilities().apply { val syncOptions = TextDocumentSyncOptions().apply { openClose = true + save = SaveOptions(false) change = TextDocumentSyncKind.Full } textDocumentSync = Either.forRight(syncOptions) diff --git a/src/main/kotlin/texlab/TextDocumentServiceImpl.kt b/src/main/kotlin/texlab/TextDocumentServiceImpl.kt index a476dbd8..36d34264 100644 --- a/src/main/kotlin/texlab/TextDocumentServiceImpl.kt +++ b/src/main/kotlin/texlab/TextDocumentServiceImpl.kt @@ -174,6 +174,15 @@ class TextDocumentServiceImpl(private val workspace: Workspace) : CustomTextDocu } override fun didSave(params: DidSaveTextDocumentParams) { + CompletableFuture.supplyAsync { + val uri = URIHelper.parse(params.textDocument.uri) + val config = client.configuration("latex.build", uri) + if (config.onSave) { + val document = workspace.findParent(uri) + val identifier = TextDocumentIdentifier(document.uri.toString()) + build(BuildParams(identifier)).get() + } + } } override fun didClose(params: DidCloseTextDocumentParams) { diff --git a/src/main/kotlin/texlab/build/BuildConfig.kt b/src/main/kotlin/texlab/build/BuildConfig.kt index a470fc92..fb4420c3 100644 --- a/src/main/kotlin/texlab/build/BuildConfig.kt +++ b/src/main/kotlin/texlab/build/BuildConfig.kt @@ -3,4 +3,5 @@ package texlab.build import com.google.gson.annotations.SerializedName data class BuildConfig(@SerializedName("executable") val executable: String, - @SerializedName("args") val args: List) + @SerializedName("args") val args: List, + @SerializedName("onSave") val onSave: Boolean)