Add option to build on save

This commit is contained in:
Patrick Förster 2019-01-19 21:07:16 +01:00
parent 3811bdfd8b
commit bc74bca9ea
3 changed files with 12 additions and 1 deletions

View file

@ -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)

View file

@ -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<BuildConfig>("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) {

View file

@ -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<String>)
@SerializedName("args") val args: List<String>,
@SerializedName("onSave") val onSave: Boolean)