aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsim <simrats169169@gmail.com>2021-07-20 13:00:38 -0700
committerJustin M. Keyes <justinkz@gmail.com>2021-09-26 11:28:28 -0700
commit8ec5bc91262a73192cc63fe1ab25719cba139caa (patch)
tree581187765006830a312aec191014df988c9a47d6
parent959cf5e53c79e79794e09c5f6260094ff66f0ffa (diff)
downloadrneovim-8ec5bc91262a73192cc63fe1ab25719cba139caa.tar.gz
rneovim-8ec5bc91262a73192cc63fe1ab25719cba139caa.tar.bz2
rneovim-8ec5bc91262a73192cc63fe1ab25719cba139caa.zip
lsp(start_client): Allow passing custom workspaceFolders to the LSP (#15132)
Some language servers *cough*rust-analyzer*cough* need an empty/custom workspaceFolders for certain usecases. For example, rust-analyzer needs an empty workspaceFolders table for standalone file support (See https://github.com/rust-analyzer/rust-analyzer/pull/8955). This can also be useful for other languages that need to commonly open a certain directory (like flutter or lua), which would help prevent spinning up a new language server altogether. In case no workspaceFolders are passed, we fallback to what we had before.
-rw-r--r--runtime/lua/vim/lsp.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index d2371cb937..c9d7f6b59d 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -590,6 +590,10 @@ end
--- as `initializationOptions`. See `initialize` in the LSP spec.
---
--@param name (string, default=client-id) Name in log messages.
+--
+--@param workspace_folders (table) List of workspace folders passed to the
+--- language server. Defaults to root_dir if not set. See `workspaceFolders` in
+--- the LSP spec
---
--@param get_language_id function(bufnr, filetype) -> language ID as string.
--- Defaults to the filetype.
@@ -775,6 +779,14 @@ function lsp.start_client(config)
off = 'off'; messages = 'messages'; verbose = 'verbose';
}
local version = vim.version()
+
+ if not config.workspace_folders then
+ config.workspace_folders = {{
+ uri = vim.uri_from_fname(config.root_dir);
+ name = string.format("%s", config.root_dir);
+ }};
+ end
+
local initialize_params = {
-- The process Id of the parent process that started the server. Is null if
-- the process has not been started by another process. If the parent
@@ -815,10 +827,7 @@ function lsp.start_client(config)
-- -- workspace folder in the user interface.
-- name
-- }
- workspaceFolders = {{
- uri = vim.uri_from_fname(config.root_dir);
- name = string.format("%s", config.root_dir);
- }};
+ workspaceFolders = config.workspace_folders,
}
if config.before_init then
-- TODO(ashkan) handle errors here.