diff options
| -rw-r--r-- | doc/lspconfig.txt | 2 | ||||
| -rw-r--r-- | lua/lspconfig/configs.lua | 24 | ||||
| -rw-r--r-- | lua/lspconfig/util.lua | 3 |
3 files changed, 18 insertions, 11 deletions
diff --git a/doc/lspconfig.txt b/doc/lspconfig.txt index d43ca15e..8144b708 100644 --- a/doc/lspconfig.txt +++ b/doc/lspconfig.txt @@ -442,6 +442,8 @@ mode under which cross-file features may be degraded. `workspaceFolders` during initialization. - attaching subsequent files in the parent directory to the same server instance, depending on filetype. +- also supports unnamed buffer if filetype matches the server filetype + settings. Cross-file features (navigation, hover) may or may not work depending on the language server. For a full feature-set, consider moving your files to a diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index 512c76b3..76586b5e 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -1,5 +1,5 @@ local util = require 'lspconfig.util' -local api, validate, lsp = vim.api, vim.validate, vim.lsp +local api, validate, lsp, uv, fn = vim.api, vim.validate, vim.lsp, vim.loop, vim.fn local tbl_deep_extend = vim.tbl_deep_extend local configs = {} @@ -90,15 +90,19 @@ function configs.__newindex(t, config_name, config_def) if get_root_dir then local bufnr = api.nvim_get_current_buf() local bufname = api.nvim_buf_get_name(bufnr) - if not util.bufname_valid(bufname) then + if #bufname == 0 and not config.single_file_support then return + elseif #bufname ~= 0 then + if not util.bufname_valid(bufname) then + return + end + root_dir = get_root_dir(util.path.sanitize(bufname), bufnr) end - root_dir = get_root_dir(util.path.sanitize(bufname), bufnr) end if root_dir then api.nvim_create_autocmd('BufReadPost', { - pattern = vim.fn.fnameescape(root_dir) .. '/*', + pattern = fn.fnameescape(root_dir) .. '/*', callback = function() M.manager.try_add_wrapper() end, @@ -124,10 +128,10 @@ function configs.__newindex(t, config_name, config_def) -- 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 bufname = api.nvim_buf_get_name(0) - if not util.bufname_valid(bufname) then + if #bufname ~= 0 and not util.bufname_valid(bufname) then return end - local pseudo_root = util.path.dirname(util.path.sanitize(bufname)) + local pseudo_root = #bufname == 0 and uv.cwd() or util.path.dirname(util.path.sanitize(bufname)) local client_id = M.manager.add(pseudo_root, true) lsp.buf_attach_client(api.nvim_get_current_buf(), client_id) end @@ -235,8 +239,12 @@ function configs.__newindex(t, config_name, config_def) local root_dir local bufname = api.nvim_buf_get_name(bufnr) - if not util.bufname_valid(bufname) then + if #bufname == 0 and not config.single_file_support then return + elseif #bufname ~= 0 then + if not util.bufname_valid(bufname) then + return + end end local buf_path = util.path.sanitize(bufname) @@ -247,7 +255,7 @@ function configs.__newindex(t, config_name, config_def) if root_dir then id = manager.add(root_dir, false) elseif config.single_file_support then - local pseudo_root = util.path.dirname(buf_path) + local pseudo_root = #bufname == 0 and uv.cmd() or util.path.dirname(buf_path) id = manager.add(pseudo_root, true) end diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index f8a359f0..a1f04bec 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -20,9 +20,6 @@ M.default_config = { M.on_setup = nil function M.bufname_valid(bufname) - if not bufname then - return false - end if bufname:match '^/' or bufname:match '^[a-zA-Z]:' or bufname:match '^zipfile://' or bufname:match '^tarfile:' then return true end |
