Skip to content

Commit

Permalink
fix(nvim): properly restart LSP after session switching
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamHsieh committed Dec 25, 2024
1 parent 197fd8b commit d9f1c17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
21 changes: 18 additions & 3 deletions config/nvim/lua/plugins/lsp/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ M.setup_auto_detach = function()
timeout,
0,
vim.schedule_wrap(function()
pcall(vim.cmd.LspStop)
M.stop_lsp()
end)
)
end,
Expand All @@ -26,8 +26,7 @@ M.setup_auto_detach = function()
group = lsp_detach_group,
callback = function()
if not timer:is_active() then
pcall(vim.cmd.LspStart)
vim.cmd("Lazy reload lazydev.nvim")
M.start_lsp()
if not vim.g.copilot_disabled then
require("copilot.command").enable()
end
Expand All @@ -39,4 +38,20 @@ M.setup_auto_detach = function()
})
end

M.start_lsp = function()
pcall(vim.cmd.LspStart)
vim.cmd("Lazy reload lazydev.nvim")
vim.cmd("Lazy reload none-ls.nvim")
vim.cmd("Lazy reload mason-null-ls.nvim")
end

M.stop_lsp = function()
pcall(vim.cmd.LspStop)
end

M.restart_lsp = function()
vim.schedule(M.stop_lsp)
vim.defer_fn(M.start_lsp, 2000)
end

return M
1 change: 1 addition & 0 deletions config/nvim/lua/plugins/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ M.config = function()
-- HACK: this is a workaround for a race condition from `focus` plugin (resizer.lua)
-- it will set `cmdheight` to 1, when loading a session
vim.o.cmdheight = 0
require("plugins.lsp.utils").restart_lsp()
end),
})

Expand Down

0 comments on commit d9f1c17

Please sign in to comment.