mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
feat(lsp): workspace_required #31824
Problem: Some language servers do not work properly without a workspace folder. Solution: Add `workspace_required`, which skips starting the lsp client if no workspace folder is found. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
@@ -615,6 +615,17 @@ function lsp.start(config, opts)
|
||||
config.root_dir = vim.fs.root(bufnr, opts._root_markers)
|
||||
end
|
||||
|
||||
if
|
||||
not config.root_dir
|
||||
and (not config.workspace_folders or #config.workspace_folders == 0)
|
||||
and config.workspace_required
|
||||
then
|
||||
log.info(
|
||||
('skipping config "%s": workspace_required=true, no workspace found'):format(config.name)
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
for _, client in pairs(all_clients) do
|
||||
if reuse_client(client, config) then
|
||||
if opts.attach == false then
|
||||
|
||||
@@ -63,6 +63,9 @@ local validate = vim.validate
|
||||
--- folder in this list. See `workspaceFolders` in the LSP spec.
|
||||
--- @field workspace_folders? lsp.WorkspaceFolder[]
|
||||
---
|
||||
--- (default false) Server requires a workspace (no "single file" support).
|
||||
--- @field workspace_required? boolean
|
||||
---
|
||||
--- Map overriding the default capabilities defined by |vim.lsp.protocol.make_client_capabilities()|,
|
||||
--- passed to the language server on initialization. Hint: use make_client_capabilities() and modify
|
||||
--- its result.
|
||||
|
||||
Reference in New Issue
Block a user