diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/configs.lua | 25 | ||||
| -rw-r--r-- | lua/lspconfig/util.lua | 8 |
2 files changed, 21 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) diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 05d844ae..11586d50 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -19,6 +19,14 @@ M.default_config = { -- global on_setup hook M.on_setup = nil +function M.bufname_valid(bufname) + if bufname and bufname ~= '' and (bufname:match '^([a-zA-Z]:).*' or bufname:match '^/') then + return true + else + return false + end +end + function M.validate_bufnr(bufnr) validate { bufnr = { bufnr, 'n' }, |
