The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Restarting A Neovim LSP When Changing Buffers

TODO: Pull subtitle into page object

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)

Code
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,
})

Notes

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Restarting A Neovim LSP When Changing Buffers

-- warning

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

-- p

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)


-- code
-- 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,
})

-- notes

- The directions for how to restart came from the
faq. They said to use .get_clients(), but that didn't 
work for me whereas `.get_active_cliets()`` did. 


-- ref
-- title: Neovim LSP FAQ
-- url: https://neovim.io/doc/user/lsp.html#lsp-faq

-- iref
-- 2vus3pxs


-- categories
-- Neovim 

-- metadata
-- date: 2023-09-25 19:50:18
-- id: 2vuvbj8e
-- site: aws
-- type: post
-- status: scratch