aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/lspconfig.txt3
-rw-r--r--lua/lspconfig/configs.lua5
-rw-r--r--lua/lspconfig/manager.lua19
3 files changed, 18 insertions, 9 deletions
diff --git a/doc/lspconfig.txt b/doc/lspconfig.txt
index db94a710..f7221933 100644
--- a/doc/lspconfig.txt
+++ b/doc/lspconfig.txt
@@ -75,6 +75,9 @@ the following added keys:
- {single_file_support} (`bool`) (default: nil) Determines if a server is
started without a matching root directory. See |lspconfig-single-file-support|.
+- {silent} (`bool`) (default: false) Whether to suppress error reporting if the
+ LSP server fails to start.
+
- {on_new_config} (`function(new_config, new_root_dir)`) Function executed
after a root directory is detected. This is used to modify the server
configuration (including `cmd` itself). Most commonly, this is used to
diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua
index 77d07862..2a19991f 100644
--- a/lua/lspconfig/configs.lua
+++ b/lua/lspconfig/configs.lua
@@ -8,6 +8,7 @@ local configs = {}
--- @class lspconfig.Config : vim.lsp.ClientConfig
--- @field enabled? boolean
--- @field single_file_support? boolean
+--- @field silent? boolean
--- @field filetypes? string[]
--- @field filetype? string
--- @field on_new_config? fun(new_config: lspconfig.Config?, new_root_dir: string)
@@ -105,7 +106,7 @@ function configs.__newindex(t, config_name, config_def)
api.nvim_create_autocmd(event_conf.event, {
pattern = event_conf.pattern or '*',
callback = function(opt)
- M.manager:try_add(opt.buf)
+ M.manager:try_add(opt.buf, nil, config.silent)
end,
group = lsp_group,
desc = string.format(
@@ -176,7 +177,7 @@ function configs.__newindex(t, config_name, config_def)
return
end
local pseudo_root = #bufname == 0 and pwd or util.path.dirname(util.path.sanitize(bufname))
- M.manager:add(pseudo_root, true, bufnr)
+ M.manager:add(pseudo_root, true, bufnr, config.silent)
end
end)
end
diff --git a/lua/lspconfig/manager.lua b/lua/lspconfig/manager.lua
index 5a0c635c..d5db2833 100644
--- a/lua/lspconfig/manager.lua
+++ b/lua/lspconfig/manager.lua
@@ -85,7 +85,8 @@ end
--- @param new_config lspconfig.Config
--- @param root_dir string
--- @param single_file boolean
-function M:_start_client(bufnr, new_config, root_dir, single_file)
+--- @param silent boolean
+function M:_start_client(bufnr, new_config, root_dir, single_file, silent)
-- do nothing if the client is not enabled
if new_config.enabled == false then
return
@@ -129,6 +130,7 @@ function M:_start_client(bufnr, new_config, root_dir, single_file)
local client_id = lsp.start(new_config, {
bufnr = bufnr,
+ silent = silent,
reuse_client = function(existing_client)
if (self._clients[root_dir] or {})[existing_client.name] then
self:_notify_workspace_folder_added(root_dir, existing_client)
@@ -153,9 +155,11 @@ end
---@param root_dir string
---@param single_file boolean
---@param bufnr integer
+---@param silent boolean
+function M:add(root_dir, single_file, bufnr, silent)
root_dir = util.path.sanitize(root_dir)
local new_config = self.make_config(root_dir)
- self:_start_client(bufnr, new_config, root_dir, single_file)
+ self:_start_client(bufnr, new_config, root_dir, single_file, silent)
end
--- @return vim.lsp.Client[]
@@ -173,7 +177,8 @@ end
--- a new client if one doesn't already exist for `bufnr`.
--- @param bufnr integer
--- @param project_root? string
-function M:try_add(bufnr, project_root)
+--- @param silent boolean
+function M:try_add(bufnr, project_root, silent)
bufnr = bufnr or api.nvim_get_current_buf()
if vim.bo[bufnr].buftype == 'nofile' then
@@ -190,7 +195,7 @@ function M:try_add(bufnr, project_root)
end
if project_root then
- self:add(project_root, false, bufnr)
+ self:add(project_root, false, bufnr, silent)
return
end
@@ -213,10 +218,10 @@ function M:try_add(bufnr, project_root)
end
if root_dir then
- self:add(root_dir, false, bufnr)
+ self:add(root_dir, false, bufnr, silent)
elseif self.config.single_file_support then
local pseudo_root = #bufname == 0 and pwd or util.path.dirname(buf_path)
- self:add(pseudo_root, true, bufnr)
+ self:add(pseudo_root, true, bufnr, silent)
end
end)
end
@@ -229,7 +234,7 @@ function M:try_add_wrapper(bufnr, project_root)
local config = self.config
-- `config.filetypes = nil` means all filetypes are valid.
if not config.filetypes or vim.tbl_contains(config.filetypes, vim.bo[bufnr].filetype) then
- self:try_add(bufnr, project_root)
+ self:try_add(bufnr, project_root, config.silent)
end
end