Skip to content

Commit 26632f4

Browse files
authored
chore(nvim-tree#2731): neovim luadoc 0.10 compliance (nvim-tree#2786)
* refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings, type gymnastics * refactor(nvim-tree#2731): resolve warnings, type gymnastics * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): handle cwd unavailable when opening * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings, type gymnastics * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): style * refactor(nvim-tree#2731): add _meta library, explicit check disables * refactor(nvim-tree#2731): add lua-language-server manual install instructions * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): explicitly set all diagnostics, reduce deprecated to hint * Revert "refactor(nvim-tree#2731): resolve warnings" This reverts commit 9c0526b. * Revert "refactor(nvim-tree#2731): resolve warnings" This reverts commit f534fbc. * refactor(nvim-tree#2731): handle directory unavailable when deleting * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): handle directory unavailable when creating explorer * refactor(nvim-tree#2731): add all nvim lua libraries * refactor(nvim-tree#2731): resolve warnings * refactor(nvim-tree#2731): remove vim global * refactor(nvim-tree#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)

0 commit comments

Comments
 (0)