Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Restarting A Neovim LSP When Changing Buffers

This currently only works some times. Not sure yet, but I think if the client crashes it doesn't restart properly. Leaving this hear as a work in progress

I'm working on a LSP for my custom file format. I set up the following autocmd and added it to my nvim.lua config file to restart the LSP everytime I enter the buffer for a .tmp file (which is what I'm testing with for now)

lua
vim.api.nvim_create_autocmd("BufEnter", {
  pattern = "*.tmp",
  group = vim.api.nvim_create_augroup("LSPTestRestartGroup", { clear = true }),
  callback = function() 
    print("restarting lsp")
    vim.lsp.stop_client(vim.lsp.get_active_clients())
    vim.lsp.start({
      name = 'neopolitan',
      cmd = {'/Users/alan/workshop/neopolitan-lsp/target/debug/nrs-language-server'},
      root_dir = vim.fs.dirname(vim.fs.find({'Cargo.toml'}, { upward = true })[1]),
    })
  end,
})

- The directions for how to restart came from the faq. They said to use .get _ clients(), but that didn't work for me whereas [TODO: Code shorthand span ] did.

Footnotes And References