diff options
| author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-11-11 01:00:24 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-11 01:00:24 -0800 |
| commit | 0d1ce78d231773046320caa45fe1a18dfa366761 (patch) | |
| tree | fde488c8490f93b6ad88ef8a32e77ff9b4e49d34 /lua/lspconfig/util.lua | |
| parent | docs: make CONTRIBUTING more visible via move (#1396) (diff) | |
| download | nvim-lspconfig-0d1ce78d231773046320caa45fe1a18dfa366761.tar nvim-lspconfig-0d1ce78d231773046320caa45fe1a18dfa366761.tar.gz nvim-lspconfig-0d1ce78d231773046320caa45fe1a18dfa366761.tar.bz2 nvim-lspconfig-0d1ce78d231773046320caa45fe1a18dfa366761.tar.lz nvim-lspconfig-0d1ce78d231773046320caa45fe1a18dfa366761.tar.xz nvim-lspconfig-0d1ce78d231773046320caa45fe1a18dfa366761.tar.zst nvim-lspconfig-0d1ce78d231773046320caa45fe1a18dfa366761.zip | |
feat: add single file mode (#1385)
* This adds a "single file mode" option for each language server
* Currently, if a root is not detected, a new language server is started
for each file opened.
* Root directory is set to `nil` in start_client. Some servers will
refuse to start, or otherwise panic. This is opt-in per server.
* Some servers, such as rust-analyzer, explicitly have a "single file
mode", we will not support that until it is officially part of the LSP
specification
Co-authored-by: Peter Lithammer <peter.lithammer@gmail.com>
Diffstat (limited to 'lua/lspconfig/util.lua')
| -rw-r--r-- | lua/lspconfig/util.lua | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 3691da68..dbac70fd 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -233,18 +233,24 @@ end)() -- seen before, will call make_config(root_dir) and start a new client. function M.server_per_root_dir_manager(_make_config) local clients = {} + local single_file_clients = {} local manager = {} - function manager.add(root_dir) - if not root_dir then - return - end - if not M.path.is_dir(root_dir) then - return + function manager.add(root_dir, single_file_mode) + local client_id + if single_file_mode then + client_id = single_file_clients[root_dir] + else + if not root_dir then + return + end + if not M.path.is_dir(root_dir) then + return + end + client_id = clients[root_dir] end -- Check if we have a client already or start and store it. - local client_id = clients[root_dir] if not client_id then local new_config = _make_config(root_dir) -- do nothing if the client is not enabled @@ -265,9 +271,20 @@ function M.server_per_root_dir_manager(_make_config) end new_config.on_exit = M.add_hook_before(new_config.on_exit, function() clients[root_dir] = nil + single_file_clients[root_dir] = nil end) + -- Sending rootDirectory and workspaceFolders as null is not explicitly + -- codified in the spec. Certain servers crash if initialized with a NULL + -- root directory. + if single_file_mode then + new_config.root_dir = nil + end client_id = lsp.start_client(new_config) - clients[root_dir] = client_id + if single_file_mode then + single_file_clients[root_dir] = client_id + else + clients[root_dir] = client_id + end end return client_id end |
