(not uploaded yet)npm install lsp-live-reload
Motivation: While running a server, its executable is locked and can't be rewritten.
Solution: Copy all files of the server to another directory and instead execute it. On rebuilt, stop server, copy files again, and restart.
export const active = async (context: ExtensionContext) => {
const { command, backupOptions } = computeBackupOptions(LSP_SERVER_COMMAND, { backup: "parentDirectory" })
const client = newLanguageClient(command)
context.subscriptions.push(client)
const liveReload = new LspLiveReload(client, backupOptions)
context.subscriptions.push(liveReload)
liveReload.addEventListener("error", (ev: ErrorEvent) => {
console.error("error:", ev.error.message)
})
}
Points:
- Need an absolute path to the LSP server command,
LSP_SERVER_COMMAND
. - Call
computeBackupOptions
function. - Create a
LanguageClient
instance, usingvscode-languageclient
package. - Create a
LspLiveReload
instance, which automatically starts LSP client. - Attach
error
event to watch reloading error.
See example for details.