From 040001d85e9190a904d0e35ef5774633e14d8475 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 17 Dec 2024 12:11:31 +0100 Subject: [PATCH] refactor: fix luals warnings --- lua/lspconfig/util.lua | 31 +++++++++++++++++++------------ plugin/lspconfig.lua | 2 +- scripts/docgen.lua | 7 +++---- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 7de9e8b856..213e87f398 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -28,9 +28,9 @@ function M.bufname_valid(bufname) end function M.validate_bufnr(bufnr) - validate { - bufnr = { bufnr, 'n' }, - } + if nvim_eleven then + validate('bufnr', bufnr, 'number') + end return bufnr == 0 and api.nvim_get_current_buf() or bufnr end @@ -174,7 +174,9 @@ M.path = (function() end)() function M.search_ancestors(startpath, func) - validate { func = { func, 'f' } } + if nvim_eleven then + validate('func', func, 'function') + end if func(startpath) then return startpath end @@ -192,14 +194,6 @@ function M.search_ancestors(startpath, func) end end -function M.tbl_flatten(t) - return nvim_eleven and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t) -end - -function M.get_lsp_clients(filter) - return nvim_eleven and lsp.get_clients(filter) or lsp.get_active_clients(filter) -end - local function escape_wildcards(path) return path:gsub('([%[%]%?%*])', '\\%1') end @@ -245,6 +239,7 @@ function M.get_active_clients_list_by_ft(filetype) local clients = M.get_lsp_clients() local clients_list = {} for _, client in pairs(clients) do + --- @diagnostic disable-next-line:undefined-field local filetypes = client.config.filetypes or {} for _, ft in pairs(filetypes) do if ft == filetype then @@ -326,6 +321,18 @@ function M.strip_archive_subpath(path) return path end +--- Functions that can be removed once minimum required neovim version is high enough + +function M.tbl_flatten(t) + --- @diagnostic disable-next-line:deprecated + return nvim_eleven and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t) +end + +function M.get_lsp_clients(filter) + --- @diagnostic disable-next-line:deprecated + return nvim_eleven and lsp.get_clients(filter) or lsp.get_active_clients(filter) +end + --- Deprecated functions --- @deprecated use `vim.fn.isdirectory(path) == 1` instead diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index a852d967a6..0283d84732 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -45,7 +45,7 @@ local get_clients_from_cmd_args = function(arg) return '' end) for id in (arg or ''):gmatch '(%d+)' do - local client = lsp.get_client_by_id(tonumber(id)) + local client = lsp.get_client_by_id(assert(tonumber(id))) if client == nil then err_msg = err_msg .. ('client id "%s" not found\n'):format(id) end diff --git a/scripts/docgen.lua b/scripts/docgen.lua index 02c04dc824..6b73cba621 100644 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -278,10 +278,9 @@ local function make_implemented_servers_list() end local function generate_readme(template_file, params) - vim.validate { - lsp_server_details = { params.lsp_server_details, 's' }, - implemented_servers_list = { params.implemented_servers_list, 's' }, - } + vim.validate('lsp_server_details', params.lsp_server_details, 'string') + vim.validate('implemented_servers_list', params.implemented_servers_list, 'string') + local input_template = readfile(template_file) local readme_data = template(input_template, params)