feat(lsp): workspace_required (#33608)

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: Michael Strobel <71396679+Kibadda@users.noreply.github.com>
This commit is contained in:
Justin M. Keyes
2025-04-24 07:06:30 -07:00
committed by GitHub
parent 448c2cec9d
commit 66953b16a2
5 changed files with 173 additions and 118 deletions

View File

@@ -633,6 +633,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