vain0x / lsp-live-reload

Library to live-reload LSP client in VSCode extension for faster development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LspLiveReload

npm install lsp-live-reload (not uploaded yet)

What

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.

Usage

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, using vscode-languageclient package.
  • Create a LspLiveReload instance, which automatically starts LSP client.
  • Attach error event to watch reloading error.

See example for details.

About

Library to live-reload LSP client in VSCode extension for faster development

License:Creative Commons Zero v1.0 Universal


Languages

Language:F# 50.9%Language:TypeScript 42.2%Language:JavaScript 4.9%Language:Shell 2.1%