Skip to content

Commit 96fe07f

Browse files
authored
refactor(utils): Use vim.validate() form 1 for Neovim 0.11 compatibility (#506)
* refactor(utils): update deprecated Neovim 0.11 APIs - Replaced vim.validate() with Lua-style type checks - Future-proofed utility functions for Neovim 0.11+ * refactor(utils): switch to vim.validate() form 1 for Neovim 0.11+ Replaced custom assert() checks with official vim.validate() form 1, as recommended in Neovim 0.11+ to ensure better consistency with core APIs and forward compatibility. * refactor(utils): restore some deleted comments
1 parent 000448d commit 96fe07f

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lua/dashboard/utils.lua

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ function utils.element_align(tbl)
2626
end
2727

2828
function utils.get_max_len(contents)
29-
vim.validate({
30-
contents = { contents, 't' },
31-
})
29+
vim.validate('contents', contents, 'table')
3230
local cells = {}
3331
for _, v in pairs(contents) do
3432
table.insert(cells, vim.api.nvim_strwidth(v))
@@ -39,9 +37,7 @@ end
3937

4038
-- draw the graphics into the screen center
4139
function utils.center_align(tbl)
42-
vim.validate({
43-
tbl = { tbl, 'table' },
44-
})
40+
vim.validate('tbl', tbl, 'table')
4541
local function fill_sizes(lines)
4642
local fills = {}
4743
for _, line in pairs(lines) do
@@ -100,7 +96,7 @@ function utils.disable_move_key(bufnr)
10096
end, keys)
10197
end
10298

103-
--- return the most recently files list
99+
-- return the most recently files list
104100
function utils.get_mru_list()
105101
local mru = {}
106102
for _, file in pairs(vim.v.oldfiles or {}) do
@@ -122,9 +118,10 @@ function utils.get_package_manager_stats()
122118
local status, lazy = pcall(require, 'lazy')
123119
if status then
124120
package_manager_stats.name = 'lazy'
125-
package_manager_stats.loaded = lazy.stats().loaded
126-
package_manager_stats.count = lazy.stats().count
127-
package_manager_stats.time = lazy.stats().startuptime
121+
local stats = lazy.stats()
122+
package_manager_stats.loaded = stats.loaded
123+
package_manager_stats.count = stats.count
124+
package_manager_stats.time = stats.startuptime
128125
end
129126
return package_manager_stats
130127
end
@@ -135,7 +132,6 @@ function utils.generate_empty_table(length)
135132
if length == 0 then
136133
return empty_tbl
137134
end
138-
139135
for _ = 1, length do
140136
table.insert(empty_tbl, '')
141137
end
@@ -168,7 +164,7 @@ end
168164
function utils.buf_is_empty(bufnr)
169165
bufnr = bufnr or 0
170166
return vim.api.nvim_buf_line_count(0) == 1
171-
and vim.api.nvim_buf_get_lines(0, 0, -1, false)[1] == ''
167+
and vim.api.nvim_buf_get_lines(0, 0, -1, false)[1] == ''
172168
end
173169

174170
local last_footer_size = nil

0 commit comments

Comments
 (0)