From 90d15227c55c9ae6e4d52884817db75e4329792b Mon Sep 17 00:00:00 2001 From: Michael Strobel <71396679+Kibadda@users.noreply.github.com> Date: Sun, 30 Mar 2025 20:07:53 +0200 Subject: 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 --- runtime/lua/vim/lsp.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'runtime/lua/vim/lsp.lua') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 8c590ab6c8..3dcf692d24 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -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 -- cgit