Skip to content

chore(#2787): minimum nvim version 0.9, replace 0.10 deprecated, enable deprecated warnings #2788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c5ad8b4
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
94b4aec
refactor(#2787): enable deprecated checks
alex-courtis Jun 1, 2024
a9e9b2d
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
619f29f
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
8e2f81f
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
459f733
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
a5f1b86
refactor(#2787): use inline deprecation disabling
alex-courtis Jun 1, 2024
7f047dd
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
698cdf7
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
24ea6da
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
dde476e
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
69f6804
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
8cf3e60
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
146a687
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
c7add15
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
b6b4c32
refactor(#2787): replace deprecated
alex-courtis Jun 1, 2024
44afa48
refactor(#2787): deprecated are now warnings
alex-courtis Jun 1, 2024
e56e2ac
refactor(#2787): 0.9 is the minimum supported version
alex-courtis Jun 1, 2024
5663202
Revert "refactor(#2787): replace deprecated"
alex-courtis Jun 1, 2024
e026466
refactor(#2787): suppress deprecated until 0.11
alex-courtis Jun 1, 2024
8563720
refactor(#2787): minimum nvim version 0.8 -> 0.9
alex-courtis Jun 1, 2024
7af14bf
refactor(#2787): reset globals
alex-courtis Jun 6, 2024
46c2fb6
refactor(#2787): explicitly check for vim.diagnostic.is_enabled funct…
alex-courtis Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
},
"diagnostics": {
"libraryFiles": "Disable",
"severity": {
"deprecated": "Hint"
},
"globals": [],
"neededFileStatus": {
"ambiguity-1": "Any",
"assign-type-mismatch": "Any",
Expand All @@ -23,7 +21,7 @@
"code-after-break": "Any",
"codestyle-check": "None",
"count-down-loop": "Any",
"deprecated": "None",
"deprecated": "Any",
"different-requires": "Any",
"discard-returns": "Any",
"doc-field-no-class": "Any",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ style-doc:
scripts/doc-comments.sh

luals:
scripts/luals-check.sh
@scripts/luals-check.sh

#
# fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Questions and general support: [Discussions](https://github.com/nvim-tree/nvim-t

## Requirements

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

[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"

Expand Down
3 changes: 1 addition & 2 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Git Integration

Requirements

This file explorer requires `neovim >= 0.8.0`
This file explorer requires `neovim >= 0.9.0`

==============================================================================
2. QUICKSTART *nvim-tree-quickstart*
Expand Down Expand Up @@ -832,7 +832,6 @@ Use nvim-tree in a floating window.

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

*nvim-tree.renderer.add_trailing*
Appends a trailing slash to folder names.
Expand Down
38 changes: 18 additions & 20 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ local core = require "nvim-tree.core"
local git = require "nvim-tree.git"
local filters = require "nvim-tree.explorer.filters"
local buffers = require "nvim-tree.buffers"
local events = require "nvim-tree.events"
local notify = require "nvim-tree.notify"

local _config = {}
Expand All @@ -26,7 +25,14 @@ local M = {
function M.change_root(path, bufnr)
-- skip if current file is in ignore_list
if type(bufnr) == "number" then
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or ""
local ft

if vim.fn.has "nvim-0.10" == 1 then
ft = vim.api.nvim_get_option_value("filetype", { buf = bufnr }) or ""
else
ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or "" ---@diagnostic disable-line: deprecated
end

for _, value in pairs(_config.update_focused_file.update_root.ignore_list) do
if utils.str_find(path, value) or utils.str_find(ft, value) then
return
Expand Down Expand Up @@ -78,7 +84,14 @@ end
function M.tab_enter()
if view.is_visible { any_tabpage = true } then
local bufname = vim.api.nvim_buf_get_name(0)
local ft = vim.api.nvim_buf_get_option(0, "ft")

local ft
if vim.fn.has "nvim-0.10" == 1 then
ft = vim.api.nvim_get_option_value("filetype", { buf = 0 }) or ""
else
ft = vim.api.nvim_buf_get_option(0, "ft") ---@diagnostic disable-line: deprecated
end

for _, filter in ipairs(M.config.tab.sync.ignore) do
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
return
Expand Down Expand Up @@ -324,21 +337,6 @@ local function setup_autocommands(opts)
end,
})
end

-- TODO #1545 remove similar check from view.resize
if vim.fn.has "nvim-0.9" == 1 then
create_nvim_tree_autocmd("WinResized", {
callback = function()
if vim.v.event and vim.v.event.windows then
for _, winid in ipairs(vim.v.event.windows) do
if vim.api.nvim_win_is_valid(winid) and utils.is_nvim_tree_buf(vim.api.nvim_win_get_buf(winid)) then
events._dispatch_on_tree_resize(vim.api.nvim_win_get_width(winid))
end
end
end
end,
})
end
end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
Expand Down Expand Up @@ -766,8 +764,8 @@ end

---@param conf table|nil
function M.setup(conf)
if vim.fn.has "nvim-0.8" == 0 then
notify.warn "nvim-tree.lua requires Neovim 0.8 or higher"
if vim.fn.has "nvim-0.9" == 0 then
notify.warn "nvim-tree.lua requires Neovim 0.9 or higher"
return
end

Expand Down
23 changes: 19 additions & 4 deletions lua/nvim-tree/actions/finders/search-node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,33 @@ function M.fn()

-- temporarily set &path
local bufnr = vim.api.nvim_get_current_buf()
local path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path")
vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**")

local path_existed, path_opt
if vim.fn.has "nvim-0.10" == 1 then
path_existed, path_opt = pcall(vim.api.nvim_get_option_value, "path", { buf = bufnr })
vim.api.nvim_set_option_value("path", core.get_cwd() .. "/**", { buf = bufnr })
else
path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path") ---@diagnostic disable-line: deprecated
vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**") ---@diagnostic disable-line: deprecated
end

vim.ui.input({ prompt = "Search: ", completion = "file_in_path" }, function(input_path)
if not input_path or input_path == "" then
return
end
-- reset &path
if path_existed then
vim.api.nvim_buf_set_option(bufnr, "path", path_opt)
if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value("path", path_opt, { buf = bufnr })
else
vim.api.nvim_buf_set_option(bufnr, "path", path_opt) ---@diagnostic disable-line: deprecated
end
else
vim.api.nvim_buf_set_option(bufnr, "path", nil)
if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value("path", nil, { buf = bufnr })
else
vim.api.nvim_buf_set_option(bufnr, "path", nil) ---@diagnostic disable-line: deprecated
end
end

-- strip trailing slash
Expand Down
67 changes: 56 additions & 11 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ local function usable_win_ids()
return vim.tbl_filter(function(id)
local bufid = vim.api.nvim_win_get_buf(id)
for option, v in pairs(M.window_picker.exclude) do
local ok, option_value = pcall(vim.api.nvim_buf_get_option, bufid, option)
local ok, option_value
if vim.fn.has "nvim-0.10" == 1 then
ok, option_value = pcall(vim.api.nvim_get_option_value, option, { buf = bufid })
else
ok, option_value = pcall(vim.api.nvim_buf_get_option, bufid, option) ---@diagnostic disable-line: deprecated
end

if ok and vim.tbl_contains(v, option_value) then
return false
end
Expand Down Expand Up @@ -83,33 +89,56 @@ local function pick_win_id()

if laststatus == 3 then
for _, win_id in ipairs(not_selectable) do
local ok_status, statusline = pcall(vim.api.nvim_win_get_option, win_id, "statusline")
local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, win_id, "winhl")
local ok_status, statusline, ok_hl, winhl

if vim.fn.has "nvim-0.10" == 1 then
ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = win_id })
ok_hl, winhl = pcall(vim.api.nvim_get_option_value, "winhl", { win = win_id })
else
ok_status, statusline = pcall(vim.api.nvim_win_get_option, win_id, "statusline") ---@diagnostic disable-line: deprecated
ok_hl, winhl = pcall(vim.api.nvim_win_get_option, win_id, "winhl") ---@diagnostic disable-line: deprecated
end

win_opts[win_id] = {
statusline = ok_status and statusline or "",
winhl = ok_hl and winhl or "",
}

-- Clear statusline for windows not selectable
vim.api.nvim_win_set_option(win_id, "statusline", " ")
if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value("statusline", " ", { win = win_id })
else
vim.api.nvim_win_set_option(win_id, "statusline", " ") ---@diagnostic disable-line: deprecated
end
end
end

-- Setup UI
for _, id in ipairs(selectable) do
local char = M.window_picker.chars:sub(i, i)
local ok_status, statusline = pcall(vim.api.nvim_win_get_option, id, "statusline")
local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, id, "winhl")

local ok_status, statusline, ok_hl, winhl
if vim.fn.has "nvim-0.10" == 1 then
ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = id })
ok_hl, winhl = pcall(vim.api.nvim_get_option_value, "winhl", { win = id })
else
ok_status, statusline = pcall(vim.api.nvim_win_get_option, id, "statusline") ---@diagnostic disable-line: deprecated
ok_hl, winhl = pcall(vim.api.nvim_win_get_option, id, "winhl") ---@diagnostic disable-line: deprecated
end

win_opts[id] = {
statusline = ok_status and statusline or "",
winhl = ok_hl and winhl or "",
}
win_map[char] = id

vim.api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=")
vim.api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker")
if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value("statusline", "%=" .. char .. "%=", { win = id })
vim.api.nvim_set_option_value("winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker", { win = id })
else
vim.api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=") ---@diagnostic disable-line: deprecated
vim.api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker") ---@diagnostic disable-line: deprecated
end

i = i + 1
if i > #M.window_picker.chars then
Expand All @@ -128,14 +157,22 @@ local function pick_win_id()
-- Restore window options
for _, id in ipairs(selectable) do
for opt, value in pairs(win_opts[id]) do
vim.api.nvim_win_set_option(id, opt, value)
if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value(opt, value, { win = id })
else
vim.api.nvim_win_set_option(id, opt, value) ---@diagnostic disable-line: deprecated
end
end
end

if laststatus == 3 then
for _, id in ipairs(not_selectable) do
for opt, value in pairs(win_opts[id]) do
vim.api.nvim_win_set_option(id, opt, value)
if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value(opt, value, { win = id })
else
vim.api.nvim_win_set_option(id, opt, value) ---@diagnostic disable-line: deprecated
end
end
end
end
Expand Down Expand Up @@ -258,7 +295,15 @@ local function open_in_new_window(filename, mode)
-- If `hidden` is not enabled, check if buffer in target window is
-- modified, and create new split if it is.
local target_bufid = vim.api.nvim_win_get_buf(target_winid)
if vim.api.nvim_buf_get_option(target_bufid, "modified") then

local modified
if vim.fn.has "nvim-0.10" == 1 then
modified = vim.api.nvim_get_option_value("modified", { buf = target_bufid })
else
modified = vim.api.nvim_buf_get_option(target_bufid, "modified") ---@diagnostic disable-line: deprecated
end

if modified then
if not mode:match "split$" then
mode = "vsplit"
end
Expand Down
7 changes: 6 additions & 1 deletion lua/nvim-tree/appearance/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ function M.hi_test()
render_displays("other, long", displays_long, bufnr, l)

-- finalise and focus the buffer
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
else
vim.api.nvim_buf_set_option(bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
end

vim.cmd.buffer(bufnr)
end

Expand Down
11 changes: 2 additions & 9 deletions lua/nvim-tree/appearance/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,8 @@ function M.setup()

-- hard link override when legacy only is present
for from, to in pairs(M.LEGACY_LINKS) do
local hl_from
local hl_to
if vim.fn.has "nvim-0.9" == 1 then
hl_from = vim.api.nvim_get_hl(0, { name = from })
hl_to = vim.api.nvim_get_hl(0, { name = to })
else
hl_from = vim.api.nvim__get_hl_defs(0)[from] or {}
hl_to = vim.api.nvim__get_hl_defs(0)[to] or {}
end
local hl_from = vim.api.nvim_get_hl(0, { name = from })
local hl_to = vim.api.nvim_get_hl(0, { name = to })
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
vim.api.nvim_command("hi link " .. from .. " " .. to)
end
Expand Down
11 changes: 7 additions & 4 deletions lua/nvim-tree/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ end
local function from_nvim_lsp()
local buffer_severity = {}

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

if not is_disabled then
if is_enabled then
for _, diagnostic in ipairs(vim.diagnostic.get(nil, { severity = M.severity })) do
if diagnostic.severity and diagnostic.bufnr and vim.api.nvim_buf_is_valid(diagnostic.bufnr) then
local bufname = uniformize_path(vim.api.nvim_buf_get_name(diagnostic.bufnr))
Expand Down
7 changes: 6 additions & 1 deletion lua/nvim-tree/help.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ local function open()

-- populate it
vim.api.nvim_buf_set_lines(M.bufnr, 0, -1, false, lines)
vim.api.nvim_buf_set_option(M.bufnr, "modifiable", false)

if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value("modifiable", false, { buf = M.bufnr })
else
vim.api.nvim_buf_set_option(M.bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
end

-- highlight it
for _, h in ipairs(hl) do
Expand Down
14 changes: 10 additions & 4 deletions lua/nvim-tree/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ function M.get_last_group_node(node)
node = node.group_next
end

---@diagnostic disable-next-line: return-type-mismatch -- it can't be nil
return node
return node ---@diagnostic disable-line: return-type-mismatch -- it can't be nil
end

---Group empty folders
Expand Down Expand Up @@ -199,8 +198,15 @@ end
local function should_hijack_current_buf()
local bufnr = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name(bufnr)
local bufmodified = vim.api.nvim_buf_get_option(bufnr, "modified")
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")

local bufmodified, ft
if vim.fn.has "nvim-0.10" == 1 then
bufmodified = vim.api.nvim_get_option_value("modified", { buf = bufnr })
ft = vim.api.nvim_get_option_value("ft", { buf = bufnr })
else
bufmodified = vim.api.nvim_buf_get_option(bufnr, "modified") ---@diagnostic disable-line: deprecated
ft = vim.api.nvim_buf_get_option(bufnr, "ft") ---@diagnostic disable-line: deprecated
end

local should_hijack_unnamed = M.hijack_unnamed_buffer_when_opening and bufname == "" and not bufmodified and ft == ""
local should_hijack_dir = bufname ~= "" and vim.fn.isdirectory(bufname) == 1 and M.hijack_directories.enable
Expand Down
8 changes: 7 additions & 1 deletion lua/nvim-tree/live-filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ local function create_overlay()
border = "none",
style = "minimal",
})
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true)

if vim.fn.has "nvim-0.10" == 1 then
vim.api.nvim_set_option_value("modifiable", true, { buf = overlay_bufnr })
else
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
end

vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { M.filter })
vim.cmd "startinsert"
vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #M.filter + 1 })
Expand Down
Loading
Loading