diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-04-02 11:56:29 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-04-02 16:47:17 +0100 |
commit | d9235efa76229708586d3c9db3dcbac46127ca0a (patch) | |
tree | 64a527f38bcf91edbcb0c738fed5b375984437b9 /runtime/lua/vim/lsp.lua | |
parent | ffe3002568f849df1b155b90d6ea0e1f48d8c6d5 (diff) | |
download | rneovim-d9235efa76229708586d3c9db3dcbac46127ca0a.tar.gz rneovim-d9235efa76229708586d3c9db3dcbac46127ca0a.tar.bz2 rneovim-d9235efa76229708586d3c9db3dcbac46127ca0a.zip |
refactor(lsp): move workspace folder logic into the client
- Changed `reuse_client` to check workspace folders in addition to
root_dir.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 0c9de607fe..eb604caacd 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -164,6 +164,28 @@ local function once(fn) end end +--- @param client vim.lsp.Client +--- @param config vim.lsp.ClientConfig +--- @return boolean +local function reuse_client_default(client, config) + if client.name ~= config.name then + return false + end + + if config.root_dir then + for _, dir in ipairs(client.workspace_folders or {}) do + -- note: do not need to check client.root_dir since that should be client.workspace_folders[1] + if config.root_dir == dir.name then + return true + end + end + end + + -- TODO(lewis6991): also check config.workspace_folders + + return false +end + --- @class vim.lsp.start.Opts --- @inlinedoc --- @@ -216,11 +238,7 @@ end --- @return integer? client_id function lsp.start(config, opts) opts = opts or {} - local reuse_client = opts.reuse_client - or function(client, conf) - return client.root_dir == conf.root_dir and client.name == conf.name - end - + local reuse_client = opts.reuse_client or reuse_client_default local bufnr = resolve_bufnr(opts.bufnr) for _, client in pairs(all_clients) do |