diff options
| author | glepnir <glephunter@gmail.com> | 2024-05-17 14:06:45 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-17 14:06:45 +0800 |
| commit | 45015c6d1fc436e377ac6d349840eb09d3775f47 (patch) | |
| tree | f71aeae2c5ae5045450eeea221d66ec617054ee8 | |
| parent | refactor: remove usages of deprecated vim.tbl_add_reverse_lookup (#3156) (diff) | |
| download | nvim-lspconfig-45015c6d1fc436e377ac6d349840eb09d3775f47.tar nvim-lspconfig-45015c6d1fc436e377ac6d349840eb09d3775f47.tar.gz nvim-lspconfig-45015c6d1fc436e377ac6d349840eb09d3775f47.tar.bz2 nvim-lspconfig-45015c6d1fc436e377ac6d349840eb09d3775f47.tar.lz nvim-lspconfig-45015c6d1fc436e377ac6d349840eb09d3775f47.tar.xz nvim-lspconfig-45015c6d1fc436e377ac6d349840eb09d3775f47.tar.zst nvim-lspconfig-45015c6d1fc436e377ac6d349840eb09d3775f47.zip | |
refactor: add compatible tbl_flatten and lsp_get_clients for new version 0.10 (#3154)
| -rw-r--r-- | lua/lspconfig/server_configurations/vdmj.lua | 2 | ||||
| -rw-r--r-- | lua/lspconfig/util.lua | 18 | ||||
| -rw-r--r-- | scripts/docgen.lua | 18 |
3 files changed, 25 insertions, 13 deletions
diff --git a/lua/lspconfig/server_configurations/vdmj.lua b/lua/lspconfig/server_configurations/vdmj.lua index 90dca2d8..865e263f 100644 --- a/lua/lspconfig/server_configurations/vdmj.lua +++ b/lua/lspconfig/server_configurations/vdmj.lua @@ -129,6 +129,6 @@ by neovim. dap, } - config.cmd = vim.tbl_flatten { java_cmd, vdmj_cmd } + config.cmd = util.tbl_flatten { java_cmd, vdmj_cmd } end, } diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 073b0e12..9300ed6e 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -3,6 +3,7 @@ local validate = vim.validate local api = vim.api local lsp = vim.lsp local uv = vim.loop +local nvim_nine = vim.fn.has 'nvim-0.9' == 1 local is_windows = uv.os_uname().version:match 'Windows' @@ -170,7 +171,7 @@ M.path = (function() end local function path_join(...) - return table.concat(vim.tbl_flatten { ... }, '/') + return table.concat(M.tbl_flatten { ... }, '/') end -- Traverse the path calling cb along the way. @@ -261,8 +262,16 @@ function M.search_ancestors(startpath, func) end end +function M.tbl_flatten(t) + return nvim_nine and vim.tbl_flatten(t) or vim.iter(t):flatten(math.huge):totable() +end + +local function get_lsp_clients(filter) + return nvim_nine and lsp.get_active_clients(filter) or lsp.get_clients(filter) +end + function M.root_pattern(...) - local patterns = vim.tbl_flatten { ... } + local patterns = M.tbl_flatten { ... } return function(startpath) startpath = M.strip_archive_subpath(startpath) for _, pattern in ipairs(patterns) do @@ -333,7 +342,7 @@ function M.insert_package_json(config_files, field, fname) end function M.get_active_clients_list_by_ft(filetype) - local clients = vim.lsp.get_active_clients() + local clients = get_lsp_clients() local clients_list = {} for _, client in pairs(clients) do local filetypes = client.config.filetypes or {} @@ -378,7 +387,8 @@ function M.get_config_by_ft(filetype) end function M.get_active_client_by_name(bufnr, servername) - for _, client in pairs(vim.lsp.get_active_clients { bufnr = bufnr }) do + --TODO(glepnir): remove this for loop when we want only support 0.10+ + for _, client in pairs(get_lsp_clients { bufnr = bufnr }) do if client.name == servername then return client end diff --git a/scripts/docgen.lua b/scripts/docgen.lua index 9f6c1bc1..f8ddcdb9 100644 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -4,7 +4,6 @@ local util = require 'lspconfig.util' local inspect = vim.inspect local uv = vim.loop local fn = vim.fn -local tbl_flatten = vim.tbl_flatten local function template(s, params) return (s:gsub('{{([^{}]+)}}', params)) @@ -40,12 +39,15 @@ local function indent(n, s) end local function make_parts(fns) - return tbl_flatten(map_list(fns, function(v) - if type(v) == 'function' then - v = v() - end - return { v } - end)) + return vim + .iter(fns) + :map(function(v) + if type(v) == 'function' then + v = v() + end + return { v } + end) + :totable() end local function make_section(indentlvl, sep, parts) @@ -215,7 +217,7 @@ local function make_lsp_sections() return tick('enum ' .. inspect(v.enum)) end if v.type then - return tick(table.concat(tbl_flatten { v.type }, '|')) + return tick(table.concat(util.tbl_flatten { v.type }, '|')) end end, }), |
