Skip to content

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

License

Notifications You must be signed in to change notification settings

vain0x/lsp-live-reload

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published