Skip to content

Commit 8704b6f

Browse files
authored
chore(#2787): minimum nvim version 0.9, replace 0.10 deprecated, enable deprecated warnings (#2788)
* refactor(#2787): replace deprecated * refactor(#2787): enable deprecated checks * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): use inline deprecation disabling * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): replace deprecated * refactor(#2787): deprecated are now warnings * refactor(#2787): 0.9 is the minimum supported version * Revert "refactor(#2787): replace deprecated" This reverts commit b6b4c32. * refactor(#2787): suppress deprecated until 0.11 * refactor(#2787): minimum nvim version 0.8 -> 0.9 * refactor(#2787): reset globals * refactor(#2787): explicitly check for vim.diagnostic.is_enabled function presence
1 parent 26632f4 commit 8704b6f

17 files changed

+162
-83
lines changed

.luarc.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
},
1010
"diagnostics": {
1111
"libraryFiles": "Disable",
12-
"severity": {
13-
"deprecated": "Hint"
14-
},
12+
"globals": [],
1513
"neededFileStatus": {
1614
"ambiguity-1": "Any",
1715
"assign-type-mismatch": "Any",
@@ -23,7 +21,7 @@
2321
"code-after-break": "Any",
2422
"codestyle-check": "None",
2523
"count-down-loop": "Any",
26-
"deprecated": "None",
24+
"deprecated": "Any",
2725
"different-requires": "Any",
2826
"discard-returns": "Any",
2927
"doc-field-no-class": "Any",

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ style-doc:
2222
scripts/doc-comments.sh
2323

2424
luals:
25-
scripts/luals-check.sh
25+
@scripts/luals-check.sh
2626

2727
#
2828
# fixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Questions and general support: [Discussions](https://github.com/nvim-tree/nvim-t
2828

2929
## Requirements
3030

31-
[neovim >=0.8.0](https://github.com/neovim/neovim/wiki/Installing-Neovim)
31+
[neovim >=0.9.0](https://github.com/neovim/neovim/wiki/Installing-Neovim)
3232

3333
[nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) is optional and used to display file icons. It requires a [patched font](https://www.nerdfonts.com/). Your terminal emulator must be configured to use that font, usually "Hack Nerd Font"
3434

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Git Integration
103103

104104
Requirements
105105

106-
This file explorer requires `neovim >= 0.8.0`
106+
This file explorer requires `neovim >= 0.9.0`
107107

108108
==============================================================================
109109
2. QUICKSTART *nvim-tree-quickstart*
@@ -832,7 +832,6 @@ Use nvim-tree in a floating window.
832832

833833
Highlight precedence, additive:
834834
git < opened < modified < bookmarked < diagnostics < copied < cut
835-
Neovim <= 0.8 will only show the highest.
836835

837836
*nvim-tree.renderer.add_trailing*
838837
Appends a trailing slash to folder names.

lua/nvim-tree.lua

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ local core = require "nvim-tree.core"
1111
local git = require "nvim-tree.git"
1212
local filters = require "nvim-tree.explorer.filters"
1313
local buffers = require "nvim-tree.buffers"
14-
local events = require "nvim-tree.events"
1514
local notify = require "nvim-tree.notify"
1615

1716
local _config = {}
@@ -26,7 +25,14 @@ local M = {
2625
function M.change_root(path, bufnr)
2726
-- skip if current file is in ignore_list
2827
if type(bufnr) == "number" then
29-
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or ""
28+
local ft
29+
30+
if vim.fn.has "nvim-0.10" == 1 then
31+
ft = vim.api.nvim_get_option_value("filetype", { buf = bufnr }) or ""
32+
else
33+
ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or "" ---@diagnostic disable-line: deprecated
34+
end
35+
3036
for _, value in pairs(_config.update_focused_file.update_root.ignore_list) do
3137
if utils.str_find(path, value) or utils.str_find(ft, value) then
3238
return
@@ -78,7 +84,14 @@ end
7884
function M.tab_enter()
7985
if view.is_visible { any_tabpage = true } then
8086
local bufname = vim.api.nvim_buf_get_name(0)
81-
local ft = vim.api.nvim_buf_get_option(0, "ft")
87+
88+
local ft
89+
if vim.fn.has "nvim-0.10" == 1 then
90+
ft = vim.api.nvim_get_option_value("filetype", { buf = 0 }) or ""
91+
else
92+
ft = vim.api.nvim_buf_get_option(0, "ft") ---@diagnostic disable-line: deprecated
93+
end
94+
8295
for _, filter in ipairs(M.config.tab.sync.ignore) do
8396
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
8497
return
@@ -324,21 +337,6 @@ local function setup_autocommands(opts)
324337
end,
325338
})
326339
end
327-
328-
-- TODO #1545 remove similar check from view.resize
329-
if vim.fn.has "nvim-0.9" == 1 then
330-
create_nvim_tree_autocmd("WinResized", {
331-
callback = function()
332-
if vim.v.event and vim.v.event.windows then
333-
for _, winid in ipairs(vim.v.event.windows) do
334-
if vim.api.nvim_win_is_valid(winid) and utils.is_nvim_tree_buf(vim.api.nvim_win_get_buf(winid)) then
335-
events._dispatch_on_tree_resize(vim.api.nvim_win_get_width(winid))
336-
end
337-
end
338-
end
339-
end,
340-
})
341-
end
342340
end
343341

344342
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
@@ -766,8 +764,8 @@ end
766764

767765
---@param conf table|nil
768766
function M.setup(conf)
769-
if vim.fn.has "nvim-0.8" == 0 then
770-
notify.warn "nvim-tree.lua requires Neovim 0.8 or higher"
767+
if vim.fn.has "nvim-0.9" == 0 then
768+
notify.warn "nvim-tree.lua requires Neovim 0.9 or higher"
771769
return
772770
end
773771

lua/nvim-tree/actions/finders/search-node.lua

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,33 @@ function M.fn()
6969

7070
-- temporarily set &path
7171
local bufnr = vim.api.nvim_get_current_buf()
72-
local path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path")
73-
vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**")
72+
73+
local path_existed, path_opt
74+
if vim.fn.has "nvim-0.10" == 1 then
75+
path_existed, path_opt = pcall(vim.api.nvim_get_option_value, "path", { buf = bufnr })
76+
vim.api.nvim_set_option_value("path", core.get_cwd() .. "/**", { buf = bufnr })
77+
else
78+
path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path") ---@diagnostic disable-line: deprecated
79+
vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**") ---@diagnostic disable-line: deprecated
80+
end
7481

7582
vim.ui.input({ prompt = "Search: ", completion = "file_in_path" }, function(input_path)
7683
if not input_path or input_path == "" then
7784
return
7885
end
7986
-- reset &path
8087
if path_existed then
81-
vim.api.nvim_buf_set_option(bufnr, "path", path_opt)
88+
if vim.fn.has "nvim-0.10" == 1 then
89+
vim.api.nvim_set_option_value("path", path_opt, { buf = bufnr })
90+
else
91+
vim.api.nvim_buf_set_option(bufnr, "path", path_opt) ---@diagnostic disable-line: deprecated
92+
end
8293
else
83-
vim.api.nvim_buf_set_option(bufnr, "path", nil)
94+
if vim.fn.has "nvim-0.10" == 1 then
95+
vim.api.nvim_set_option_value("path", nil, { buf = bufnr })
96+
else
97+
vim.api.nvim_buf_set_option(bufnr, "path", nil) ---@diagnostic disable-line: deprecated
98+
end
8499
end
85100

86101
-- strip trailing slash

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

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ local function usable_win_ids()
2626
return vim.tbl_filter(function(id)
2727
local bufid = vim.api.nvim_win_get_buf(id)
2828
for option, v in pairs(M.window_picker.exclude) do
29-
local ok, option_value = pcall(vim.api.nvim_buf_get_option, bufid, option)
29+
local ok, option_value
30+
if vim.fn.has "nvim-0.10" == 1 then
31+
ok, option_value = pcall(vim.api.nvim_get_option_value, option, { buf = bufid })
32+
else
33+
ok, option_value = pcall(vim.api.nvim_buf_get_option, bufid, option) ---@diagnostic disable-line: deprecated
34+
end
35+
3036
if ok and vim.tbl_contains(v, option_value) then
3137
return false
3238
end
@@ -83,33 +89,56 @@ local function pick_win_id()
8389

8490
if laststatus == 3 then
8591
for _, win_id in ipairs(not_selectable) do
86-
local ok_status, statusline = pcall(vim.api.nvim_win_get_option, win_id, "statusline")
87-
local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, win_id, "winhl")
92+
local ok_status, statusline, ok_hl, winhl
93+
94+
if vim.fn.has "nvim-0.10" == 1 then
95+
ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = win_id })
96+
ok_hl, winhl = pcall(vim.api.nvim_get_option_value, "winhl", { win = win_id })
97+
else
98+
ok_status, statusline = pcall(vim.api.nvim_win_get_option, win_id, "statusline") ---@diagnostic disable-line: deprecated
99+
ok_hl, winhl = pcall(vim.api.nvim_win_get_option, win_id, "winhl") ---@diagnostic disable-line: deprecated
100+
end
88101

89102
win_opts[win_id] = {
90103
statusline = ok_status and statusline or "",
91104
winhl = ok_hl and winhl or "",
92105
}
93106

94107
-- Clear statusline for windows not selectable
95-
vim.api.nvim_win_set_option(win_id, "statusline", " ")
108+
if vim.fn.has "nvim-0.10" == 1 then
109+
vim.api.nvim_set_option_value("statusline", " ", { win = win_id })
110+
else
111+
vim.api.nvim_win_set_option(win_id, "statusline", " ") ---@diagnostic disable-line: deprecated
112+
end
96113
end
97114
end
98115

99116
-- Setup UI
100117
for _, id in ipairs(selectable) do
101118
local char = M.window_picker.chars:sub(i, i)
102-
local ok_status, statusline = pcall(vim.api.nvim_win_get_option, id, "statusline")
103-
local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, id, "winhl")
119+
120+
local ok_status, statusline, ok_hl, winhl
121+
if vim.fn.has "nvim-0.10" == 1 then
122+
ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = id })
123+
ok_hl, winhl = pcall(vim.api.nvim_get_option_value, "winhl", { win = id })
124+
else
125+
ok_status, statusline = pcall(vim.api.nvim_win_get_option, id, "statusline") ---@diagnostic disable-line: deprecated
126+
ok_hl, winhl = pcall(vim.api.nvim_win_get_option, id, "winhl") ---@diagnostic disable-line: deprecated
127+
end
104128

105129
win_opts[id] = {
106130
statusline = ok_status and statusline or "",
107131
winhl = ok_hl and winhl or "",
108132
}
109133
win_map[char] = id
110134

111-
vim.api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=")
112-
vim.api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker")
135+
if vim.fn.has "nvim-0.10" == 1 then
136+
vim.api.nvim_set_option_value("statusline", "%=" .. char .. "%=", { win = id })
137+
vim.api.nvim_set_option_value("winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker", { win = id })
138+
else
139+
vim.api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=") ---@diagnostic disable-line: deprecated
140+
vim.api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker") ---@diagnostic disable-line: deprecated
141+
end
113142

114143
i = i + 1
115144
if i > #M.window_picker.chars then
@@ -128,14 +157,22 @@ local function pick_win_id()
128157
-- Restore window options
129158
for _, id in ipairs(selectable) do
130159
for opt, value in pairs(win_opts[id]) do
131-
vim.api.nvim_win_set_option(id, opt, value)
160+
if vim.fn.has "nvim-0.10" == 1 then
161+
vim.api.nvim_set_option_value(opt, value, { win = id })
162+
else
163+
vim.api.nvim_win_set_option(id, opt, value) ---@diagnostic disable-line: deprecated
164+
end
132165
end
133166
end
134167

135168
if laststatus == 3 then
136169
for _, id in ipairs(not_selectable) do
137170
for opt, value in pairs(win_opts[id]) do
138-
vim.api.nvim_win_set_option(id, opt, value)
171+
if vim.fn.has "nvim-0.10" == 1 then
172+
vim.api.nvim_set_option_value(opt, value, { win = id })
173+
else
174+
vim.api.nvim_win_set_option(id, opt, value) ---@diagnostic disable-line: deprecated
175+
end
139176
end
140177
end
141178
end
@@ -258,7 +295,15 @@ local function open_in_new_window(filename, mode)
258295
-- If `hidden` is not enabled, check if buffer in target window is
259296
-- modified, and create new split if it is.
260297
local target_bufid = vim.api.nvim_win_get_buf(target_winid)
261-
if vim.api.nvim_buf_get_option(target_bufid, "modified") then
298+
299+
local modified
300+
if vim.fn.has "nvim-0.10" == 1 then
301+
modified = vim.api.nvim_get_option_value("modified", { buf = target_bufid })
302+
else
303+
modified = vim.api.nvim_buf_get_option(target_bufid, "modified") ---@diagnostic disable-line: deprecated
304+
end
305+
306+
if modified then
262307
if not mode:match "split$" then
263308
mode = "vsplit"
264309
end

lua/nvim-tree/appearance/diagnostics.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ function M.hi_test()
129129
render_displays("other, long", displays_long, bufnr, l)
130130

131131
-- finalise and focus the buffer
132-
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
132+
if vim.fn.has "nvim-0.10" == 1 then
133+
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
134+
else
135+
vim.api.nvim_buf_set_option(bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
136+
end
137+
133138
vim.cmd.buffer(bufnr)
134139
end
135140

lua/nvim-tree/appearance/init.lua

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,8 @@ function M.setup()
183183

184184
-- hard link override when legacy only is present
185185
for from, to in pairs(M.LEGACY_LINKS) do
186-
local hl_from
187-
local hl_to
188-
if vim.fn.has "nvim-0.9" == 1 then
189-
hl_from = vim.api.nvim_get_hl(0, { name = from })
190-
hl_to = vim.api.nvim_get_hl(0, { name = to })
191-
else
192-
hl_from = vim.api.nvim__get_hl_defs(0)[from] or {}
193-
hl_to = vim.api.nvim__get_hl_defs(0)[to] or {}
194-
end
186+
local hl_from = vim.api.nvim_get_hl(0, { name = from })
187+
local hl_to = vim.api.nvim_get_hl(0, { name = to })
195188
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
196189
vim.api.nvim_command("hi link " .. from .. " " .. to)
197190
end

lua/nvim-tree/diagnostics.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ end
3939
local function from_nvim_lsp()
4040
local buffer_severity = {}
4141

42-
local is_disabled = false
43-
if vim.fn.has "nvim-0.9" == 1 then
44-
is_disabled = vim.diagnostic.is_disabled()
42+
-- is_enabled is not present in all 0.10 builds/releases, see #2781
43+
local is_enabled = false
44+
if vim.fn.has "nvim-0.10" == 1 and type(vim.diagnostic.is_enabled) == "function" then
45+
is_enabled = vim.diagnostic.is_enabled()
46+
elseif type(vim.diagnostic.is_disabled) == "function" then ---@diagnostic disable-line: deprecated
47+
is_enabled = not vim.diagnostic.is_disabled() ---@diagnostic disable-line: deprecated
4548
end
4649

47-
if not is_disabled then
50+
if is_enabled then
4851
for _, diagnostic in ipairs(vim.diagnostic.get(nil, { severity = M.severity })) do
4952
if diagnostic.severity and diagnostic.bufnr and vim.api.nvim_buf_is_valid(diagnostic.bufnr) then
5053
local bufname = uniformize_path(vim.api.nvim_buf_get_name(diagnostic.bufnr))

lua/nvim-tree/help.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ local function open()
173173

174174
-- populate it
175175
vim.api.nvim_buf_set_lines(M.bufnr, 0, -1, false, lines)
176-
vim.api.nvim_buf_set_option(M.bufnr, "modifiable", false)
176+
177+
if vim.fn.has "nvim-0.10" == 1 then
178+
vim.api.nvim_set_option_value("modifiable", false, { buf = M.bufnr })
179+
else
180+
vim.api.nvim_buf_set_option(M.bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
181+
end
177182

178183
-- highlight it
179184
for _, h in ipairs(hl) do

lua/nvim-tree/lib.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ function M.get_last_group_node(node)
8585
node = node.group_next
8686
end
8787

88-
---@diagnostic disable-next-line: return-type-mismatch -- it can't be nil
89-
return node
88+
return node ---@diagnostic disable-line: return-type-mismatch -- it can't be nil
9089
end
9190

9291
---Group empty folders
@@ -199,8 +198,15 @@ end
199198
local function should_hijack_current_buf()
200199
local bufnr = vim.api.nvim_get_current_buf()
201200
local bufname = vim.api.nvim_buf_get_name(bufnr)
202-
local bufmodified = vim.api.nvim_buf_get_option(bufnr, "modified")
203-
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
201+
202+
local bufmodified, ft
203+
if vim.fn.has "nvim-0.10" == 1 then
204+
bufmodified = vim.api.nvim_get_option_value("modified", { buf = bufnr })
205+
ft = vim.api.nvim_get_option_value("ft", { buf = bufnr })
206+
else
207+
bufmodified = vim.api.nvim_buf_get_option(bufnr, "modified") ---@diagnostic disable-line: deprecated
208+
ft = vim.api.nvim_buf_get_option(bufnr, "ft") ---@diagnostic disable-line: deprecated
209+
end
204210

205211
local should_hijack_unnamed = M.hijack_unnamed_buffer_when_opening and bufname == "" and not bufmodified and ft == ""
206212
local should_hijack_dir = bufname ~= "" and vim.fn.isdirectory(bufname) == 1 and M.hijack_directories.enable

lua/nvim-tree/live-filter.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ local function create_overlay()
150150
border = "none",
151151
style = "minimal",
152152
})
153-
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true)
153+
154+
if vim.fn.has "nvim-0.10" == 1 then
155+
vim.api.nvim_set_option_value("modifiable", true, { buf = overlay_bufnr })
156+
else
157+
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
158+
end
159+
154160
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { M.filter })
155161
vim.cmd "startinsert"
156162
vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #M.filter + 1 })

0 commit comments

Comments
 (0)