diff options
| author | Raphael <glepnir@neovim.pro> | 2022-12-11 19:25:44 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-11 19:25:44 +0800 |
| commit | 6eb24ef9175d1fa3c7a23e115854b1a2d923d386 (patch) | |
| tree | d62431dbb0e480ef8fa0caac0d57f1cdacf321cf /lua/lspconfig/ui | |
| parent | fix: check client is available and get client id from cache (#2303) (diff) | |
| download | nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.gz nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.bz2 nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.lz nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.xz nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.zst nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.zip | |
feat: support multiple workspaceFolders and show correct root in Lspinfo (#2304)
* feat: support multiple workspaceFolders and show correct root in Lspinfo
* fix: add return branch
* fix: convert path before compare
* fix: improve find root dir in LspInfo
* fix: check logic
* fix: remove unnecessary code
Diffstat (limited to 'lua/lspconfig/ui')
| -rw-r--r-- | lua/lspconfig/ui/lspinfo.lua | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/lua/lspconfig/ui/lspinfo.lua b/lua/lspconfig/ui/lspinfo.lua index d7f37b7b..40481221 100644 --- a/lua/lspconfig/ui/lspinfo.lua +++ b/lua/lspconfig/ui/lspinfo.lua @@ -1,4 +1,4 @@ -local api, fn = vim.api, vim.fn +local api, fn, lsp = vim.api, vim.fn, vim.lsp local windows = require 'lspconfig.ui.windows' local util = require 'lspconfig.util' @@ -103,14 +103,37 @@ local function make_config_info(config, bufnr) return lines end -local function make_client_info(client) +local function make_client_info(client, fname) local client_info = {} client_info.cmd = cmd_type[type(client.config.cmd)](client.config) local workspace_folders = fn.has 'nvim-0.9' == 1 and client.workspace_folders or client.workspaceFolders + local uv = vim.loop + local is_windows = uv.os_uname().version:match 'Windows' + fname = uv.fs_realpath(fname) + local sep = is_windows and '\\' or '/' + local fname_parts = vim.split(fname, sep, { trimempty = true }) if workspace_folders then - client_info.root_dir = workspace_folders[1].name - else + for _, schema in pairs(workspace_folders) do + local matched = true + local root = uv.fs_realpath(schema.name) + local root_parts = vim.split(root, sep, { trimempty = true }) + + for i = 1, #root_parts do + if root_parts[i] ~= fname_parts[i] then + matched = false + break + end + end + + if matched then + client_info.root_dir = schema.name + break + end + end + end + + if not client_info.root_dir then client_info.root_dir = 'Running in single file mode.' end client_info.filetypes = table.concat(client.config.filetypes or {}, ', ') @@ -123,8 +146,6 @@ local function make_client_info(client) .. client.name .. ' (id: ' .. tostring(client.id) - .. ', pid: ' - .. tostring(client.rpc.pid) .. ', bufnr: [' .. client_info.attached_buffers_list .. '])', @@ -150,10 +171,11 @@ end return function() -- These options need to be cached before switching to the floating -- buffer. - local buf_clients = vim.lsp.buf_get_clients() - local clients = vim.lsp.get_active_clients() - local buffer_filetype = vim.bo.filetype local original_bufnr = api.nvim_get_current_buf() + local buf_clients = lsp.get_active_clients { bufnr = original_bufnr } + local clients = lsp.get_active_clients() + local buffer_filetype = vim.bo.filetype + local fname = api.nvim_buf_get_name(original_bufnr) windows.default_options.wrap = true windows.default_options.breakindent = true @@ -194,7 +216,7 @@ return function() vim.list_extend(buf_lines, buffer_clients_header) for _, client in pairs(buf_clients) do - local client_info = make_client_info(client) + local client_info = make_client_info(client, fname) vim.list_extend(buf_lines, client_info) end @@ -206,7 +228,7 @@ return function() vim.list_extend(buf_lines, other_active_section_header) end for _, client in pairs(other_active_clients) do - local client_info = make_client_info(client) + local client_info = make_client_info(client, fname) vim.list_extend(buf_lines, client_info) end |
