fix: replace vim.* "requires" with explicit calls to vim functions (#1701)
This commit is contained in:
committed by
GitHub
parent
6d6a44626d
commit
8cc369695b
@@ -1,30 +1,28 @@
|
||||
local M = {}
|
||||
|
||||
local api = vim.api
|
||||
local fn = vim.fn
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local function hide(win)
|
||||
if win then
|
||||
if api.nvim_win_is_valid(win) then
|
||||
api.nvim_win_close(win, true)
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- reduce signcolumn/foldcolumn from window width
|
||||
local function effective_win_width()
|
||||
local win_width = fn.winwidth(0)
|
||||
local win_width = vim.fn.winwidth(0)
|
||||
|
||||
-- return zero if the window cannot be found
|
||||
local win_id = fn.win_getid()
|
||||
local win_id = vim.fn.win_getid()
|
||||
|
||||
if win_id == 0 then
|
||||
return win_width
|
||||
end
|
||||
|
||||
-- if the window does not exist the result is an empty list
|
||||
local win_info = fn.getwininfo(win_id)
|
||||
local win_info = vim.fn.getwininfo(win_id)
|
||||
|
||||
-- check if result table is empty
|
||||
if next(win_info) == nil then
|
||||
@@ -35,7 +33,7 @@ local function effective_win_width()
|
||||
end
|
||||
|
||||
local function show()
|
||||
local line_nr = api.nvim_win_get_cursor(0)[1]
|
||||
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
|
||||
if line_nr == 1 and require("nvim-tree.view").is_root_folder_visible() then
|
||||
return
|
||||
end
|
||||
@@ -47,36 +45,36 @@ local function show()
|
||||
return
|
||||
end
|
||||
|
||||
local line = fn.getline "."
|
||||
local leftcol = fn.winsaveview().leftcol
|
||||
local line = vim.fn.getline "."
|
||||
local leftcol = vim.fn.winsaveview().leftcol
|
||||
-- hide full name if left column of node in nvim-tree win is not zero
|
||||
if leftcol ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local text_width = fn.strdisplaywidth(fn.substitute(line, "[^[:print:]]*$", "", "g"))
|
||||
local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g"))
|
||||
local win_width = effective_win_width()
|
||||
|
||||
if text_width < win_width then
|
||||
return
|
||||
end
|
||||
|
||||
M.popup_win = api.nvim_open_win(api.nvim_create_buf(false, false), false, {
|
||||
M.popup_win = vim.api.nvim_open_win(vim.api.nvim_create_buf(false, false), false, {
|
||||
relative = "win",
|
||||
bufpos = { fn.line "." - 2, 0 },
|
||||
bufpos = { vim.fn.line "." - 2, 0 },
|
||||
width = math.min(text_width, vim.o.columns - 2),
|
||||
height = 1,
|
||||
noautocmd = true,
|
||||
style = "minimal",
|
||||
})
|
||||
|
||||
local ns_id = api.nvim_get_namespaces()["NvimTreeHighlights"]
|
||||
local extmarks = api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = 1 })
|
||||
api.nvim_win_call(M.popup_win, function()
|
||||
fn.setbufline("%", 1, line)
|
||||
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]
|
||||
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = 1 })
|
||||
vim.api.nvim_win_call(M.popup_win, function()
|
||||
vim.fn.setbufline("%", 1, line)
|
||||
for _, extmark in ipairs(extmarks) do
|
||||
local hl = extmark[4]
|
||||
api.nvim_buf_add_highlight(0, ns_id, hl.hl_group, 0, extmark[3], hl.end_col)
|
||||
vim.api.nvim_buf_add_highlight(0, ns_id, hl.hl_group, 0, extmark[3], hl.end_col)
|
||||
end
|
||||
vim.cmd [[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=hide ]]
|
||||
end)
|
||||
@@ -88,8 +86,8 @@ M.setup = function(opts)
|
||||
return
|
||||
end
|
||||
|
||||
local group = api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
|
||||
api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
|
||||
local group = vim.api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
@@ -99,7 +97,7 @@ M.setup = function(opts)
|
||||
end,
|
||||
})
|
||||
|
||||
api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
|
||||
@@ -12,19 +12,17 @@ local Builder = require "nvim-tree.renderer.builder"
|
||||
local live_filter = require "nvim-tree.live-filter"
|
||||
local marks = require "nvim-tree.marks"
|
||||
|
||||
local api = vim.api
|
||||
|
||||
local M = {
|
||||
last_highlights = {},
|
||||
}
|
||||
|
||||
local namespace_id = api.nvim_create_namespace "NvimTreeHighlights"
|
||||
local namespace_id = vim.api.nvim_create_namespace "NvimTreeHighlights"
|
||||
|
||||
local function _draw(bufnr, lines, hl, signs)
|
||||
api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
M.render_hl(bufnr, hl)
|
||||
api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
vim.fn.sign_unplace(git.SIGN_GROUP)
|
||||
for _, sign in pairs(signs) do
|
||||
vim.fn.sign_place(0, git.SIGN_GROUP, sign.sign, bufnr, { lnum = sign.lnum, priority = 1 })
|
||||
@@ -32,12 +30,12 @@ local function _draw(bufnr, lines, hl, signs)
|
||||
end
|
||||
|
||||
function M.render_hl(bufnr, hl)
|
||||
if not bufnr or not api.nvim_buf_is_loaded(bufnr) then
|
||||
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
end
|
||||
api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
|
||||
for _, data in ipairs(hl or M.last_highlights) do
|
||||
api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])
|
||||
vim.api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,13 +48,13 @@ local picture_map = {
|
||||
|
||||
function M.draw()
|
||||
local bufnr = view.get_bufnr()
|
||||
if not core.get_explorer() or not bufnr or not api.nvim_buf_is_loaded(bufnr) then
|
||||
if not core.get_explorer() or not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
end
|
||||
|
||||
local ps = log.profile_start "draw"
|
||||
|
||||
local cursor = api.nvim_win_get_cursor(view.get_winnr())
|
||||
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr())
|
||||
icon_component.reset_config()
|
||||
|
||||
local lines, hl
|
||||
@@ -84,7 +82,7 @@ function M.draw()
|
||||
M.last_highlights = hl
|
||||
|
||||
if cursor and #lines >= cursor[1] then
|
||||
api.nvim_win_set_cursor(view.get_winnr(), cursor)
|
||||
vim.api.nvim_win_set_cursor(view.get_winnr(), cursor)
|
||||
end
|
||||
|
||||
if view.is_help_ui() then
|
||||
|
||||
Reference in New Issue
Block a user