Skip to content

Commit

Permalink
refactor: fix luals warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dundargoc committed Dec 19, 2024
1 parent 9f2c279 commit 040001d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
31 changes: 19 additions & 12 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions scripts/docgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 040001d

Please sign in to comment.