aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig
diff options
context:
space:
mode:
authorRaphael <glepnir@neovim.pro>2022-12-06 17:23:41 +0800
committerGitHub <noreply@github.com>2022-12-06 17:23:41 +0800
commit8faa599646f482d3ed04e645eb04af94bcd12feb (patch)
tree7a042df867a43b48aad6111e2f7683b0c90a0cd4 /lua/lspconfig
parentdocs: update server_configurations.md (diff)
downloadnvim-lspconfig-8faa599646f482d3ed04e645eb04af94bcd12feb.tar
nvim-lspconfig-8faa599646f482d3ed04e645eb04af94bcd12feb.tar.gz
nvim-lspconfig-8faa599646f482d3ed04e645eb04af94bcd12feb.tar.bz2
nvim-lspconfig-8faa599646f482d3ed04e645eb04af94bcd12feb.tar.lz
nvim-lspconfig-8faa599646f482d3ed04e645eb04af94bcd12feb.tar.xz
nvim-lspconfig-8faa599646f482d3ed04e645eb04af94bcd12feb.tar.zst
nvim-lspconfig-8faa599646f482d3ed04e645eb04af94bcd12feb.zip
feat: support unnamed buffer with single_file_support (#2226)
* feat: support unnamed buffer with single_file_support * fix: make some code simple clear * feat: update doc * fix: grammar * fix: grammar
Diffstat (limited to 'lua/lspconfig')
-rw-r--r--lua/lspconfig/configs.lua24
-rw-r--r--lua/lspconfig/util.lua3
2 files changed, 16 insertions, 11 deletions
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