Skip to content

Commit

Permalink
feat: remove autocmd BufReadPost on LspStop
Browse files Browse the repository at this point in the history
so that lsp won't be auto started on buf read after explicit stop with LspStop.
  • Loading branch information
brookhong committed Jan 27, 2024
1 parent 8917d2c commit 95f2cde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function configs.__newindex(t, config_name, config_def)

local get_root_dir = config.root_dir

local buf_read_post_autocmd_id = nil
function M.launch(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
if not api.nvim_buf_is_valid(bufnr) then
Expand All @@ -136,7 +137,7 @@ function configs.__newindex(t, config_name, config_def)
end

if root_dir then
api.nvim_create_autocmd('BufReadPost', {
buf_read_post_autocmd_id = api.nvim_create_autocmd('BufReadPost', {
pattern = fn.fnameescape(root_dir) .. '/*',
callback = function(arg)
M.manager:try_add_wrapper(arg.buf, root_dir)
Expand Down Expand Up @@ -172,6 +173,12 @@ function configs.__newindex(t, config_name, config_def)
end)
end

function M.shutdown()
if buf_read_post_autocmd_id then
api.nvim_del_autocmd(buf_read_post_autocmd_id)
end
end

-- Used by :LspInfo
M.get_root_dir = get_root_dir
M.filetypes = config.filetypes
Expand Down
4 changes: 4 additions & 0 deletions plugin/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ api.nvim_create_user_command('LspStop', function(info)
client.stop(force)
end
end
local matching_configs = require('lspconfig.util').get_config_by_ft(vim.bo.filetype)
for _, config in ipairs(matching_configs) do
config.shutdown()
end
end, {
desc = 'Manually stops the given language client(s)',
nargs = '?',
Expand Down

0 comments on commit 95f2cde

Please sign in to comment.