aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorMichael Strobel <71396679+Kibadda@users.noreply.github.com>2025-03-30 20:07:53 +0200
committerGitHub <noreply@github.com>2025-03-30 11:07:53 -0700
commit90d15227c55c9ae6e4d52884817db75e4329792b (patch)
tree495e6455629eb5dafd880409bc3e58ee076d319c /runtime/lua/vim
parentde96063bda43273f94478af2b02b5f5487b4f3f2 (diff)
downloadrneovim-90d15227c55c9ae6e4d52884817db75e4329792b.tar.gz
rneovim-90d15227c55c9ae6e4d52884817db75e4329792b.tar.bz2
rneovim-90d15227c55c9ae6e4d52884817db75e4329792b.zip
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>
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp.lua11
-rw-r--r--runtime/lua/vim/lsp/client.lua3
2 files changed, 14 insertions, 0 deletions
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
diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua
index 8c75ee321d..b256eab1a6 100644
--- a/runtime/lua/vim/lsp/client.lua
+++ b/runtime/lua/vim/lsp/client.lua
@@ -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.