diff options
| author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-12-23 15:20:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-23 15:20:28 -0500 |
| commit | abb3706974ca0b5086110d8f1b0e90daebff758f (patch) | |
| tree | 0bb5bf5e582800f3736b8c39eef5bd0f6eab361c /lua/lspconfig/configs.lua | |
| parent | fix: do not attach server to buffers with nil or missing name (#1597) (diff) | |
| download | nvim-lspconfig-abb3706974ca0b5086110d8f1b0e90daebff758f.tar nvim-lspconfig-abb3706974ca0b5086110d8f1b0e90daebff758f.tar.gz nvim-lspconfig-abb3706974ca0b5086110d8f1b0e90daebff758f.tar.bz2 nvim-lspconfig-abb3706974ca0b5086110d8f1b0e90daebff758f.tar.lz nvim-lspconfig-abb3706974ca0b5086110d8f1b0e90daebff758f.tar.xz nvim-lspconfig-abb3706974ca0b5086110d8f1b0e90daebff758f.tar.zst nvim-lspconfig-abb3706974ca0b5086110d8f1b0e90daebff758f.zip | |
fix: only attempt to attach to valid bufnames (#1598)
* Check that a bufname begins with a filesystem root specifier such as a drive letter (Windows) or "/" (Unix)
* Unify with check that buf name is not "" or nil
Diffstat (limited to 'lua/lspconfig/configs.lua')
| -rw-r--r-- | lua/lspconfig/configs.lua | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index 025d94bd..9820775c 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -79,11 +79,12 @@ function configs.__newindex(t, config_name, config_def) function M.launch() local root_dir if get_root_dir then - local buf_name = api.nvim_buf_get_name(0) - if buf_name == '' or not buf_name then + local bufnr = api.nvim_get_current_buf() + local bufname = api.nvim_buf_get_name(bufnr) + if not util.bufname_valid(bufname) then return end - root_dir = get_root_dir(util.path.sanitize(buf_name), api.nvim_get_current_buf()) + root_dir = get_root_dir(util.path.sanitize(bufname), bufnr) end if root_dir then @@ -95,11 +96,11 @@ function configs.__newindex(t, config_name, config_def) ) ) for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do - local buf_name = api.nvim_buf_get_name(bufnr) - if buf_name == '' or not buf_name then + local bufname = api.nvim_buf_get_name(bufnr) + if util.bufname_valid(bufname) then return end - local buf_dir = util.path.sanitize(buf_name) + local buf_dir = util.path.sanitize(bufname) if buf_dir:sub(1, root_dir:len()) == root_dir then M.manager.try_add_wrapper(bufnr) end @@ -109,11 +110,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 buf_name = api.nvim_buf_get_name(0) - if buf_name == '' or not buf_name then + local bufname = api.nvim_buf_get_name(0) + if not util.bufname_valid(bufname) then return end - local pseudo_root = util.path.dirname(util.path.sanitize(buf_name)) + local pseudo_root = util.path.dirname(util.path.sanitize(bufname)) M.manager.add(pseudo_root, true) else vim.notify( @@ -221,11 +222,11 @@ function configs.__newindex(t, config_name, config_def) local id local root_dir - local buf_name = api.nvim_buf_get_name(bufnr) - if buf_name == '' or not buf_name then + local bufname = api.nvim_buf_get_name(bufnr) + if not util.bufname_valid(bufname) then return end - local buf_path = util.path.sanitize(buf_name) + local buf_path = util.path.sanitize(bufname) if get_root_dir then root_dir = get_root_dir(buf_path, bufnr) |
