Skip to content

Commit 040001d

Browse files
committed
refactor: fix luals warnings
1 parent 9f2c279 commit 040001d

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

lua/lspconfig/util.lua

+19-12
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function M.bufname_valid(bufname)
2828
end
2929

3030
function M.validate_bufnr(bufnr)
31-
validate {
32-
bufnr = { bufnr, 'n' },
33-
}
31+
if nvim_eleven then
32+
validate('bufnr', bufnr, 'number')
33+
end
3434
return bufnr == 0 and api.nvim_get_current_buf() or bufnr
3535
end
3636

@@ -174,7 +174,9 @@ M.path = (function()
174174
end)()
175175

176176
function M.search_ancestors(startpath, func)
177-
validate { func = { func, 'f' } }
177+
if nvim_eleven then
178+
validate('func', func, 'function')
179+
end
178180
if func(startpath) then
179181
return startpath
180182
end
@@ -192,14 +194,6 @@ function M.search_ancestors(startpath, func)
192194
end
193195
end
194196

195-
function M.tbl_flatten(t)
196-
return nvim_eleven and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t)
197-
end
198-
199-
function M.get_lsp_clients(filter)
200-
return nvim_eleven and lsp.get_clients(filter) or lsp.get_active_clients(filter)
201-
end
202-
203197
local function escape_wildcards(path)
204198
return path:gsub('([%[%]%?%*])', '\\%1')
205199
end
@@ -245,6 +239,7 @@ function M.get_active_clients_list_by_ft(filetype)
245239
local clients = M.get_lsp_clients()
246240
local clients_list = {}
247241
for _, client in pairs(clients) do
242+
--- @diagnostic disable-next-line:undefined-field
248243
local filetypes = client.config.filetypes or {}
249244
for _, ft in pairs(filetypes) do
250245
if ft == filetype then
@@ -326,6 +321,18 @@ function M.strip_archive_subpath(path)
326321
return path
327322
end
328323

324+
--- Functions that can be removed once minimum required neovim version is high enough
325+
326+
function M.tbl_flatten(t)
327+
--- @diagnostic disable-next-line:deprecated
328+
return nvim_eleven and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t)
329+
end
330+
331+
function M.get_lsp_clients(filter)
332+
--- @diagnostic disable-next-line:deprecated
333+
return nvim_eleven and lsp.get_clients(filter) or lsp.get_active_clients(filter)
334+
end
335+
329336
--- Deprecated functions
330337

331338
--- @deprecated use `vim.fn.isdirectory(path) == 1` instead

plugin/lspconfig.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local get_clients_from_cmd_args = function(arg)
4545
return ''
4646
end)
4747
for id in (arg or ''):gmatch '(%d+)' do
48-
local client = lsp.get_client_by_id(tonumber(id))
48+
local client = lsp.get_client_by_id(assert(tonumber(id)))
4949
if client == nil then
5050
err_msg = err_msg .. ('client id "%s" not found\n'):format(id)
5151
end

scripts/docgen.lua

+3-4
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,9 @@ local function make_implemented_servers_list()
278278
end
279279

280280
local function generate_readme(template_file, params)
281-
vim.validate {
282-
lsp_server_details = { params.lsp_server_details, 's' },
283-
implemented_servers_list = { params.implemented_servers_list, 's' },
284-
}
281+
vim.validate('lsp_server_details', params.lsp_server_details, 'string')
282+
vim.validate('implemented_servers_list', params.implemented_servers_list, 'string')
283+
285284
local input_template = readfile(template_file)
286285
local readme_data = template(input_template, params)
287286

0 commit comments

Comments
 (0)