chore/remove globals (#1279)

* remove renderer globals: nvim_tree_add_trailing nvim_tree_highlight_opened_files nvim_tree_root_folder_modifier nvim_tree_special_files

* remove renderer globals: nvim_tree_icon_padding

* remove renderer globals: nvim_tree_symlink_arrow

* remove renderer globals: nvim_tree_show_icons, nvim_tree_show_icons

* remove renderer globals: nvim_tree_git_hl

* remove renderer globals: nvim_tree_group_empty

* remove renderer globals: respect_buf_cwd

* remove renderer globals: nvim_tree_create_in_closed_folder

* remove globals: consistency in legacy checks

* remove renderer globals: nvim_tree_special_files

* renderer.icons.symbols -> glyphs
This commit is contained in:
Alexander Courtis
2022-05-28 11:08:40 +10:00
committed by GitHub
parent 6abc87b1d9
commit 3ba383d591
17 changed files with 404 additions and 344 deletions

View File

@@ -1,12 +1,10 @@
local _icons = require "nvim-tree.renderer.icon-config"
local utils = require "nvim-tree.utils"
local M = {
SIGN_GROUP = "NvimTreeGitSigns",
}
local function build_icons_table()
local i = M.icon_state.icons.git_icons
local function build_icons_table(i)
return {
["M "] = { { icon = i.staged, hl = "NvimTreeGitStaged" } },
[" M"] = { { icon = i.unstaged, hl = "NvimTreeGitDirty" } },
@@ -85,7 +83,7 @@ local function get_icons_(node)
local icons = M.git_icons[git_status]
if not icons then
if vim.g.nvim_tree_git_hl ~= 1 then
if not M.config.highlight_git then
warn_status(git_status)
end
return nil
@@ -126,8 +124,7 @@ local git_hl = {
[" A"] = "none",
}
function M.setup_signs()
local i = M.icon_state.icons.git_icons
function M.setup_signs(i)
vim.fn.sign_define("NvimTreeGitDirty", { text = i.unstaged, texthl = "NvimTreeGitDirty" })
vim.fn.sign_define("NvimTreeGitStaged", { text = i.staged, texthl = "NvimTreeGitStaged" })
vim.fn.sign_define("NvimTreeGitMerge", { text = i.unmerged, texthl = "NvimTreeGitMerge" })
@@ -146,22 +143,20 @@ local function get_highlight_(node)
return git_hl[git_status]
end
M.get_icons = nil_
M.get_highlight = nil_
function M.setup(opts)
M.config = opts.renderer
M.icon_state = _icons.get_config()
M.git_icons = build_icons_table()
M.git_icons = build_icons_table(opts.renderer.icons.glyphs.git)
function M.reload()
M.icon_state = _icons.get_config()
M.git_icons = build_icons_table()
M.setup_signs(opts.renderer.icons.glyphs.git)
if M.icon_state.show_git_icon then
if opts.renderer.icons.show.git then
M.get_icons = get_icons_
else
M.get_icons = nil_
end
if vim.g.nvim_tree_git_hl == 1 then
if opts.renderer.highlight_git then
M.get_highlight = get_highlight_
else
M.get_highlight = nil_

View File

@@ -1,10 +1,8 @@
local icon_config = require "nvim-tree.renderer.icon-config"
local M = { i = {} }
local function config_symlinks()
M.i.symlink = #M.icons.symlink > 0 and M.icons.symlink .. M.padding or ""
M.i.symlink_arrow = vim.g.nvim_tree_symlink_arrow or ""
M.i.symlink = #M.config.glyphs.symlink > 0 and M.config.glyphs.symlink .. M.config.padding or ""
M.i.symlink_arrow = M.config.symlink_arrow
end
local function empty()
@@ -14,30 +12,30 @@ end
local function get_folder_icon(open, is_symlink, has_children)
local n
if is_symlink and open then
n = M.icons.folder_icons.symlink_open
n = M.config.glyphs.folder.symlink_open
elseif is_symlink then
n = M.icons.folder_icons.symlink
n = M.config.glyphs.folder.symlink
elseif open then
if has_children then
n = M.icons.folder_icons.open
n = M.config.glyphs.folder.open
else
n = M.icons.folder_icons.empty_open
n = M.config.glyphs.folder.empty_open
end
else
if has_children then
n = M.icons.folder_icons.default
n = M.config.glyphs.folder.default
else
n = M.icons.folder_icons.empty
n = M.config.glyphs.folder.empty
end
end
return n .. M.padding
return n .. M.config.padding
end
local function get_file_icon_default()
local hl_group = "NvimTreeFileIcon"
local icon = M.icons.default
local icon = M.config.glyphs.default
if #icon > 0 then
return icon .. M.padding, hl_group
return icon .. M.config.padding, hl_group
else
return ""
end
@@ -45,11 +43,11 @@ end
local function get_file_icon_webdev(fname, extension)
local icon, hl_group = M.devicons.get_icon(fname, extension)
if not M.webdev_colors then
if not M.config.webdev_colors then
hl_group = "NvimTreeFileIcon"
end
if icon and hl_group ~= "DevIconDefault" then
return icon .. M.padding, hl_group
return icon .. M.config.padding, hl_group
elseif string.match(extension, "%.(.*)") then
-- If there are more extensions to the file, try to grab the icon for them recursively
return get_file_icon_webdev(fname, string.match(extension, "%.(.*)"))
@@ -59,7 +57,7 @@ local function get_file_icon_webdev(fname, extension)
end
local function config_file_icon()
if M.configs.show_file_icon then
if M.config.show.file then
if M.devicons then
M.get_file_icon = get_file_icon_webdev
else
@@ -71,23 +69,23 @@ local function config_file_icon()
end
local function config_folder_icon()
if M.configs.show_folder_icon then
if M.config.show.folder then
M.get_folder_icon = get_folder_icon
else
M.get_folder_icon = empty
end
end
function M.reset_config(webdev_colors)
M.configs = icon_config.get_config()
M.icons = M.configs.icons
M.padding = vim.g.nvim_tree_icon_padding or " "
M.devicons = M.configs.has_devicons and require "nvim-web-devicons" or nil
M.webdev_colors = webdev_colors
function M.reset_config()
config_symlinks()
config_file_icon()
config_folder_icon()
end
function M.setup(opts)
M.config = opts.renderer.icons
M.devicons = pcall(require, "nvim-web-devicons") and require "nvim-web-devicons"
end
return M

View File

@@ -4,10 +4,10 @@ function M.get_padding(depth)
return string.rep(" ", depth)
end
local function get_padding_arrows(icon_state)
local function get_padding_arrows()
return function(depth, _, _, node)
if node.nodes then
local icon = icon_state.icons.folder_icons[node.open and "arrow_open" or "arrow_closed"]
local icon = M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"]
return string.rep(" ", depth - 2) .. icon .. " "
end
return string.rep(" ", depth)
@@ -33,10 +33,8 @@ local function get_padding_indent_markers(depth, idx, nodes_number, _, markers)
end
function M.reload_padding_function()
local icon_state = require("nvim-tree.renderer.icon-config").get_config()
if icon_state.show_folder_icon and icon_state.show_folder_arrows then
M.get_padding = get_padding_arrows(icon_state)
if M.config.icons.show.folder and M.config.icons.show.folder_arrow then
M.get_padding = get_padding_arrows()
end
if M.config.indent_markers.enable then
@@ -45,9 +43,7 @@ function M.reload_padding_function()
end
function M.setup(opts)
M.config = {
indent_markers = opts.renderer.indent_markers,
}
M.config = opts.renderer
end
return M