From bbba0ccbf8aef4dd36d4ed7fa49518387285534d Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Thu, 23 Dec 2021 11:58:13 -0500 Subject: fix: do not attach server to buffers with nil or missing name (#1597) --- lua/lspconfig/configs.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index 3723df1f..025d94bd 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -79,7 +79,11 @@ function configs.__newindex(t, config_name, config_def) function M.launch() local root_dir if get_root_dir then - root_dir = get_root_dir(util.path.sanitize(api.nvim_buf_get_name(0)), api.nvim_get_current_buf()) + local buf_name = api.nvim_buf_get_name(0) + if buf_name == '' or not buf_name then + return + end + root_dir = get_root_dir(util.path.sanitize(buf_name), api.nvim_get_current_buf()) end if root_dir then @@ -91,7 +95,11 @@ function configs.__newindex(t, config_name, config_def) ) ) for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do - local buf_dir = util.path.sanitize(api.nvim_buf_get_name(bufnr)) + local buf_name = api.nvim_buf_get_name(bufnr) + if buf_name == '' or not buf_name then + return + end + local buf_dir = util.path.sanitize(buf_name) if buf_dir:sub(1, root_dir:len()) == root_dir then M.manager.try_add_wrapper(bufnr) end @@ -101,7 +109,11 @@ function configs.__newindex(t, config_name, config_def) -- Effectively this is the root from lspconfig's perspective, as we use -- this to attach additional files in the same parent folder to the same server. -- We just no longer send rootDirectory or workspaceFolders during initialization. - local pseudo_root = util.path.dirname(util.path.sanitize(api.nvim_buf_get_name(0))) + local buf_name = api.nvim_buf_get_name(0) + if buf_name == '' or not buf_name then + return + end + local pseudo_root = util.path.dirname(util.path.sanitize(buf_name)) M.manager.add(pseudo_root, true) else vim.notify( @@ -209,7 +221,11 @@ function configs.__newindex(t, config_name, config_def) local id local root_dir - local buf_path = util.path.sanitize(api.nvim_buf_get_name(bufnr)) + local buf_name = api.nvim_buf_get_name(bufnr) + if buf_name == '' or not buf_name then + return + end + local buf_path = util.path.sanitize(buf_name) if get_root_dir then root_dir = get_root_dir(buf_path, bufnr) -- cgit v1.2.3-70-g09d2