Skip to content

Commit 26632f4

Browse files
authored
chore(#2731): neovim luadoc 0.10 compliance (#2786)
* refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings, type gymnastics * refactor(#2731): resolve warnings, type gymnastics * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): handle cwd unavailable when opening * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings, type gymnastics * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): style * refactor(#2731): add _meta library, explicit check disables * refactor(#2731): add lua-language-server manual install instructions * refactor(#2731): resolve warnings * refactor(#2731): explicitly set all diagnostics, reduce deprecated to hint * Revert "refactor(#2731): resolve warnings" This reverts commit 9c0526b. * Revert "refactor(#2731): resolve warnings" This reverts commit f534fbc. * refactor(#2731): handle directory unavailable when deleting * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): resolve warnings * refactor(#2731): handle directory unavailable when creating explorer * refactor(#2731): add all nvim lua libraries * refactor(#2731): resolve warnings * refactor(#2731): remove vim global * refactor(#2731): disable deprecated until we have a 0.9->0.10 story
1 parent 5a87ffe commit 26632f4

19 files changed

+113
-61
lines changed

.luarc.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
3-
"runtime.version" : "Lua 5.1",
3+
"runtime.version": "Lua 5.1",
44
"workspace": {
55
"library": [
6-
"$VIMRUNTIME/lua/vim/lsp",
6+
"$VIMRUNTIME/lua/vim",
77
"${3rd}/luv/library"
88
]
99
},
1010
"diagnostics": {
1111
"libraryFiles": "Disable",
12-
"globals": [
13-
"vim"
14-
],
12+
"severity": {
13+
"deprecated": "Hint"
14+
},
1515
"neededFileStatus": {
1616
"ambiguity-1": "Any",
1717
"assign-type-mismatch": "Any",
@@ -23,7 +23,7 @@
2323
"code-after-break": "Any",
2424
"codestyle-check": "None",
2525
"count-down-loop": "Any",
26-
"deprecated": "Any",
26+
"deprecated": "None",
2727
"different-requires": "Any",
2828
"discard-returns": "Any",
2929
"doc-field-no-class": "Any",
@@ -33,11 +33,19 @@
3333
"duplicate-index": "Any",
3434
"duplicate-set-field": "Any",
3535
"empty-block": "Any",
36+
"global-element": "Any",
3637
"global-in-nil-env": "Any",
38+
"incomplete-signature-doc": "None",
39+
"inject-field": "Any",
40+
"invisible": "Any",
3741
"lowercase-global": "Any",
42+
"missing-fields": "Any",
43+
"missing-global-doc": "Any",
44+
"missing-local-export-doc": "None",
3845
"missing-parameter": "Any",
3946
"missing-return": "Any",
4047
"missing-return-value": "Any",
48+
"name-style-check": "None",
4149
"need-check-nil": "Any",
4250
"newfield-call": "Any",
4351
"newline-call": "Any",
@@ -70,4 +78,3 @@
7078
}
7179
}
7280
}
73-

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ Assumes `$VIMRUNTIME` is `/usr/share/nvim/runtime`. Adjust as necessary e.g.
6161
VIMRUNTIME="/my/path/to/runtime" make check
6262
```
6363

64+
If `lua-language-server` is not available or `--check` doesn't function (e.g. Arch Linux 3.9.1-1) you can manually install it as per `ci.yml` e.g.
65+
66+
```sh
67+
mkdir luals
68+
curl -L "https://github.com/LuaLS/lua-language-server/releases/download/3.9.1/lua-language-server-3.9.1-linux-x64.tar.gz" | tar zx --directory luals
69+
70+
PATH="luals/bin:${PATH}" make check
71+
```
72+
6473
# Adding New Actions
6574

6675
To add a new action, add a file in `actions/name-of-the-action.lua`. You should export a `setup` function if some configuration is needed.

lua/nvim-tree/actions/fs/create-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local M = {}
1212
local function create_and_notify(file)
1313
events._dispatch_will_create_file(file)
1414
local ok, fd = pcall(vim.loop.fs_open, file, "w", 420)
15-
if not ok then
15+
if not ok or type(fd) ~= "number" then
1616
notify.error("Couldn't create file " .. notify.render_path(file))
1717
return
1818
end

lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ end
4949
---@param cwd string
5050
---@return boolean|nil
5151
local function remove_dir(cwd)
52-
local handle = vim.loop.fs_scandir(cwd)
53-
if type(handle) == "string" then
54-
notify.error(handle)
52+
local handle, err = vim.loop.fs_scandir(cwd)
53+
if not handle then
54+
notify.error(err)
5555
return
5656
end
5757

lua/nvim-tree/actions/node/file-popup.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ end
5656

5757
function M.close_popup()
5858
if current_popup ~= nil then
59-
vim.api.nvim_win_close(current_popup.winnr, { force = true })
59+
vim.api.nvim_win_close(current_popup.winnr, true)
6060
vim.cmd "augroup NvimTreeRemoveFilePopup | au! CursorMoved | augroup END"
6161

6262
current_popup = nil

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ local function usable_win_ids()
3333
end
3434

3535
local win_config = vim.api.nvim_win_get_config(id)
36-
return id ~= tree_winid and win_config.focusable and not win_config.external
36+
return id ~= tree_winid and win_config.focusable and not win_config.external or false
3737
end, win_ids)
3838
end
3939

@@ -265,8 +265,7 @@ local function open_in_new_window(filename, mode)
265265
end
266266
end
267267

268-
local fname = vim.fn.fnameescape(filename)
269-
fname = utils.escape_special_chars(fname)
268+
local fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
270269

271270
local command
272271
if create_new_window then
@@ -287,7 +286,7 @@ local function open_in_new_window(filename, mode)
287286
set_current_win_no_autocmd(target_winid, { "BufEnter" })
288287
end
289288

290-
pcall(vim.cmd, command)
289+
pcall(vim.api.nvim_cmd, command, { output = false })
291290
lib.set_target_win()
292291
end
293292

lua/nvim-tree/actions/tree/find-file.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ function M.fn(opts)
2424
local bufnr, path
2525

2626
-- (optional) buffer number and path
27-
if type(opts.buf) == "nil" then
27+
local opts_buf = opts.buf
28+
if type(opts_buf) == "nil" then
2829
bufnr = vim.api.nvim_get_current_buf()
2930
path = vim.api.nvim_buf_get_name(bufnr)
30-
elseif type(opts.buf) == "number" then
31-
if not vim.api.nvim_buf_is_valid(opts.buf) then
31+
elseif type(opts_buf) == "number" then
32+
if not vim.api.nvim_buf_is_valid(opts_buf) then
3233
return
3334
end
34-
bufnr = tonumber(opts.buf)
35+
bufnr = opts_buf
3536
path = vim.api.nvim_buf_get_name(bufnr)
36-
elseif type(opts.buf) == "string" then
37+
elseif type(opts_buf) == "string" then
3738
bufnr = nil
38-
path = tostring(opts.buf)
39+
path = tostring(opts_buf)
3940
else
4041
return
4142
end

lua/nvim-tree/buffers.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ M._modified = {}
66
---refresh M._modified
77
function M.reload_modified()
88
M._modified = {}
9-
local bufs = vim.fn.getbufinfo { bufmodified = true, buflisted = true }
9+
local bufs = vim.fn.getbufinfo { bufmodified = 1, buflisted = 1 }
1010
for _, buf in pairs(bufs) do
1111
local path = buf.name
1212
if path ~= "" then -- not a [No Name] buffer

lua/nvim-tree/diagnostics.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ local function from_nvim_lsp()
4646

4747
if not is_disabled then
4848
for _, diagnostic in ipairs(vim.diagnostic.get(nil, { severity = M.severity })) do
49-
local buf = diagnostic.bufnr
50-
if vim.api.nvim_buf_is_valid(buf) then
51-
local bufname = uniformize_path(vim.api.nvim_buf_get_name(buf))
52-
local severity = diagnostic.severity
53-
local highest_severity = buffer_severity[bufname] or severity
54-
buffer_severity[bufname] = math.min(highest_severity, severity)
49+
if diagnostic.severity and diagnostic.bufnr and vim.api.nvim_buf_is_valid(diagnostic.bufnr) then
50+
local bufname = uniformize_path(vim.api.nvim_buf_get_name(diagnostic.bufnr))
51+
if not buffer_severity[bufname] or diagnostic.severity < buffer_severity[bufname] then
52+
buffer_severity[bufname] = diagnostic.severity
53+
end
5554
end
5655
end
5756
end

lua/nvim-tree/explorer/init.lua

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local git = require "nvim-tree.git"
2+
local notify = require "nvim-tree.notify"
23
local watch = require "nvim-tree.explorer.watch"
34
local explorer_node = require "nvim-tree.explorer.node"
45

@@ -15,14 +16,24 @@ M.reload = require("nvim-tree.explorer.reload").reload
1516
local Explorer = {}
1617
Explorer.__index = Explorer
1718

18-
---@param cwd string|nil
19-
---@return Explorer
20-
function Explorer.new(cwd)
21-
cwd = vim.loop.fs_realpath(cwd or vim.loop.cwd())
19+
---@param path string|nil
20+
---@return Explorer|nil
21+
function Explorer.new(path)
22+
local err
23+
24+
if path then
25+
path, err = vim.loop.fs_realpath(path)
26+
else
27+
path, err = vim.loop.cwd()
28+
end
29+
if not path then
30+
notify.error(err)
31+
return
32+
end
2233

2334
---@class Explorer
2435
local explorer = setmetatable({
25-
absolute_path = cwd,
36+
absolute_path = path,
2637
nodes = {},
2738
open = true,
2839
}, Explorer)

lua/nvim-tree/explorer/node-builders.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function M.link(parent, absolute_path, name, fs_stat)
7777

7878
local is_dir_link = (link_to ~= nil) and vim.loop.fs_stat(link_to).type == "directory"
7979

80-
if is_dir_link then
80+
if is_dir_link and link_to then
8181
local handle = vim.loop.fs_scandir(link_to)
8282
has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil
8383
open = false

lua/nvim-tree/explorer/reload.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function M.reload(node, git_status)
9191
---@type table<string, Node>
9292
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
9393
while true do
94-
local name, t = vim.loop.fs_scandir_next(handle, cwd)
94+
local name, t = vim.loop.fs_scandir_next(handle)
9595
if not name then
9696
break
9797
end

lua/nvim-tree/lib.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local view = require "nvim-tree.view"
33
local core = require "nvim-tree.core"
44
local utils = require "nvim-tree.utils"
55
local events = require "nvim-tree.events"
6+
local notify = require "nvim-tree.notify"
67
local explorer_node = require "nvim-tree.explorer.node"
78

89
---@class LibOpenOpts
@@ -243,7 +244,16 @@ function M.open(opts)
243244

244245
M.set_target_win()
245246
if not core.get_explorer() or opts.path then
246-
core.init(opts.path or vim.loop.cwd())
247+
if opts.path then
248+
core.init(opts.path)
249+
else
250+
local cwd, err = vim.loop.cwd()
251+
if not cwd then
252+
notify.error(string.format("current working directory unavailable: %s", err))
253+
return
254+
end
255+
core.init(cwd)
256+
end
247257
end
248258
if should_hijack_current_buf() then
249259
view.close_this_tab_only()

lua/nvim-tree/live-filter.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ local function reset_filter(node_)
2727
:iterate()
2828
end
2929

30-
local overlay_bufnr = nil
31-
local overlay_winnr = nil
30+
local overlay_bufnr = 0
31+
local overlay_winnr = 0
3232

3333
local function remove_overlay()
3434
if view.View.float.enable and view.View.float.quit_on_focus_loss then
@@ -46,8 +46,8 @@ local function remove_overlay()
4646

4747
vim.api.nvim_win_close(overlay_winnr, true)
4848
vim.api.nvim_buf_delete(overlay_bufnr, { force = true })
49-
overlay_bufnr = nil
50-
overlay_winnr = nil
49+
overlay_bufnr = 0
50+
overlay_winnr = 0
5151

5252
if M.filter == "" then
5353
M.clear_filter()

lua/nvim-tree/renderer/builder.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ function Builder:format_root_name(root_label)
396396
local label = root_label(self.root_cwd)
397397
if type(label) == "string" then
398398
return label
399-
else
400-
return "???"
401399
end
400+
elseif type(root_label) == "string" then
401+
return utils.path_remove_trailing(vim.fn.fnamemodify(self.root_cwd, root_label))
402402
end
403-
return utils.path_remove_trailing(vim.fn.fnamemodify(self.root_cwd, root_label))
403+
return "???"
404404
end
405405

406406
---@private

lua/nvim-tree/renderer/components/full-name.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,19 @@ local function show()
6767
})
6868

6969
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]
70-
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = 1 })
70+
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true })
7171
vim.api.nvim_win_call(M.popup_win, function()
7272
vim.api.nvim_buf_set_lines(0, 0, -1, true, { line })
7373
for _, extmark in ipairs(extmarks) do
74-
local hl = extmark[4]
75-
vim.api.nvim_buf_add_highlight(0, ns_id, hl.hl_group, 0, extmark[3], hl.end_col)
74+
-- nvim 0.10 luadoc is incorrect: vim.api.keyset.get_extmark_item is missing the extmark_id at the start
75+
76+
---@cast extmark table
77+
---@type integer
78+
local col = extmark[3]
79+
---@type vim.api.keyset.extmark_details
80+
local details = extmark[4]
81+
82+
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col)
7683
end
7784
vim.cmd [[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=hide ]]
7885
end)

lua/nvim-tree/renderer/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ function M.draw()
5151

5252
local profile = log.profile_start "draw"
5353

54-
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr())
54+
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr() or 0)
5555
icon_component.reset_config()
5656

5757
local builder = Builder:new():build()
5858

5959
_draw(bufnr, builder.lines, builder.hl_args, builder.signs)
6060

6161
if cursor and #builder.lines >= cursor[1] then
62-
vim.api.nvim_win_set_cursor(view.get_winnr(), cursor)
62+
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
6363
end
6464

6565
view.grow_from_content()

lua/nvim-tree/utils.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ function M.debounce(context, timeout, callback)
406406
end
407407

408408
local timer = vim.loop.new_timer()
409+
if not timer then
410+
return
411+
end
409412
debouncer.timer = timer
410413
timer:start(timeout, 0, function()
411414
timer_stop_close(timer)

0 commit comments

Comments
 (0)