From 26afec87c81c5731aa116333f5c5e1b75cb8b091 Mon Sep 17 00:00:00 2001 From: Joshua Wood Date: Tue, 9 Jul 2024 19:04:40 +1200 Subject: [PATCH] feat!: stop lsp clients plugin (#70) The plugin `delete_buffers` now won't stop lsp clients, there is separate `stop_lsp_clients` plugin. Users that had `delete_buffers` set to true and want to keep the previous behavior should also set `stop_lsp_clients` to true. --- README.md | 1 + doc/possession.txt | 4 ++++ lua/possession/config.lua | 1 + lua/possession/plugins/init.lua | 1 + lua/possession/plugins/stop_lsp_clients.lua | 10 ++++++++++ lua/possession/session.lua | 1 + lua/possession/utils.lua | 8 +++++--- 7 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 lua/possession/plugins/stop_lsp_clients.lua diff --git a/README.md b/README.md index 6c627b3..d5ac1ff 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ require('possession').setup { dapui = true, neotest = true, delete_buffers = false, + stop_lsp_clients = false, }, telescope = { previewer = { diff --git a/doc/possession.txt b/doc/possession.txt index 926f745..9688bfc 100644 --- a/doc/possession.txt +++ b/doc/possession.txt @@ -307,6 +307,10 @@ Closes and restores dapui view in a tab. Closes and restores the summary window. + *possession-stop-lsp-clients* + +Stops all attached language server protocol clients. + *possession-telescope* telescope~ diff --git a/lua/possession/config.lua b/lua/possession/config.lua index 17a2b48..8920c55 100644 --- a/lua/possession/config.lua +++ b/lua/possession/config.lua @@ -69,6 +69,7 @@ local function defaults() dapui = true, neotest = true, delete_buffers = false, + stop_lsp_clients = false, }, telescope = { previewer = { diff --git a/lua/possession/plugins/init.lua b/lua/possession/plugins/init.lua index ca87a10..3671234 100644 --- a/lua/possession/plugins/init.lua +++ b/lua/possession/plugins/init.lua @@ -15,6 +15,7 @@ local plugins = { 'dapui', 'dap', 'delete_buffers', + 'stop_lsp_clients', } local function req(plugin) diff --git a/lua/possession/plugins/stop_lsp_clients.lua b/lua/possession/plugins/stop_lsp_clients.lua new file mode 100644 index 0000000..1cdf3f4 --- /dev/null +++ b/lua/possession/plugins/stop_lsp_clients.lua @@ -0,0 +1,10 @@ +local M = {} + +local utils = require('possession.utils') + +function M.before_load(_, _, plugin_data) + utils.stop_lsp_clients() + return plugin_data +end + +return M diff --git a/lua/possession/session.lua b/lua/possession/session.lua index 2bfd288..3f1d407 100644 --- a/lua/possession/session.lua +++ b/lua/possession/session.lua @@ -291,6 +291,7 @@ function M.close(force) end utils.delete_all_buffers(force) + utils.stop_lsp_clients() state.session_name = nil end diff --git a/lua/possession/utils.lua b/lua/possession/utils.lua index b905e0d..5572c18 100644 --- a/lua/possession/utils.lua +++ b/lua/possession/utils.lua @@ -214,12 +214,15 @@ local function lsp_get_clients(filter) end end +--- Stops all attached LSP clients +function M.stop_lsp_clients() + vim.lsp.stop_client(lsp_get_clients()) +end + --- Delete all open buffers, avoiding potential errors ---@param force? boolean delete buffers with unsaved changes function M.delete_all_buffers(force) -- Deleting the current buffer before deleting other buffers will cause autocmd "BufEnter" to be triggered. - -- Lspconfig will use the invalid buffer handler in vim.schedule. - -- So make sure the current buffer is the last loaded one to delete. local current_buffer = vim.api.nvim_get_current_buf() for _, buffer in ipairs(vim.api.nvim_list_bufs()) do if vim.api.nvim_buf_is_valid(buffer) and current_buffer ~= buffer then @@ -227,7 +230,6 @@ function M.delete_all_buffers(force) end end vim.api.nvim_buf_delete(current_buffer, { force = force }) - vim.lsp.stop_client(lsp_get_clients()) end ---@param mod string