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

@@ -34,8 +34,8 @@ function Builder:configure_trailing_slash(with_trailing)
return self
end
function Builder:configure_special_map(special_map)
self.special_map = special_map
function Builder:configure_special_files(special_files)
self.special_files = special_files
return self
end
@@ -50,14 +50,8 @@ function Builder:configure_filter(filter, prefix)
return self
end
function Builder:configure_opened_file_highlighting(level)
if level == 1 then
self.open_file_highlight = "icon"
elseif level == 2 then
self.open_file_highlight = "name"
elseif level == 3 then
self.open_file_highlight = "all"
end
function Builder:configure_opened_file_highlighting(highlight_opened_files)
self.highlight_opened_files = highlight_opened_files
return self
end
@@ -128,7 +122,7 @@ function Builder:_build_folder(node, padding, git_hl, git_icons_tbl)
end
local foldername_hl = "NvimTreeFolderName"
if self.special_map[node.absolute_path] then
if vim.tbl_contains(self.special_files, node.absolute_path) or vim.tbl_contains(self.special_files, node.name) then
foldername_hl = "NvimTreeSpecialFolderName"
elseif node.open then
foldername_hl = "NvimTreeOpenedFolderName"
@@ -183,12 +177,12 @@ function Builder:_highlight_opened_files(node, offset, icon_length, git_icons_le
local from = offset
local to = offset
if self.open_file_highlight == "icon" then
if self.highlight_opened_files == "icon" then
to = from + icon_length
elseif self.open_file_highlight == "name" then
elseif self.highlight_opened_files == "name" then
from = offset + icon_length + git_icons_length
to = from + #node.name
elseif self.open_file_highlight == "all" then
elseif self.highlight_opened_files == "all" then
to = from + icon_length + git_icons_length + #node.name
end
@@ -209,7 +203,7 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
local col_start = offset + #icon + git_icons_length
local col_end = col_start + #node.name
if self.special_map[node.absolute_path] or self.special_map[node.name] then
if vim.tbl_contains(self.special_files, node.absolute_path) or vim.tbl_contains(self.special_files, node.name) then
self:_insert_highlight("NvimTreeSpecialFile", col_start, col_end)
elseif node.executable then
self:_insert_highlight("NvimTreeExecFile", col_start, col_end)
@@ -217,7 +211,7 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
self:_insert_highlight("NvimTreeImageFile", col_start, col_end)
end
local should_highlight_opened_files = self.open_file_highlight and vim.fn.bufloaded(node.absolute_path) > 0
local should_highlight_opened_files = self.highlight_opened_files and vim.fn.bufloaded(node.absolute_path) > 0
if should_highlight_opened_files then
self:_highlight_opened_files(node, offset, #icon, git_icons_length)
end

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

View File

@@ -1,61 +0,0 @@
local M = {}
function M.get_config()
local show_icons = vim.g.nvim_tree_show_icons or { git = 1, folders = 1, files = 1, folder_arrows = 1 }
local icons = {
default = "",
symlink = "",
git_icons = {
unstaged = "",
staged = "",
unmerged = "",
renamed = "",
untracked = "",
deleted = "",
ignored = "",
},
folder_icons = {
arrow_closed = "",
arrow_open = "",
default = "",
open = "",
empty = "",
empty_open = "",
symlink = "",
symlink_open = "",
},
}
local user_icons = vim.g.nvim_tree_icons
if user_icons then
if user_icons.default then
icons.default = user_icons.default
icons.symlink = user_icons.default
end
if user_icons.symlink then
icons.symlink = user_icons.symlink
end
for key, val in pairs(user_icons.git or {}) do
if icons.git_icons[key] then
icons.git_icons[key] = val
end
end
for key, val in pairs(user_icons.folder or {}) do
if icons.folder_icons[key] then
icons.folder_icons[key] = val
end
end
end
local has_devicons = pcall(require, "nvim-web-devicons")
return {
show_file_icon = show_icons.files == 1,
show_folder_icon = show_icons.folders == 1,
show_git_icon = show_icons.git == 1,
show_folder_arrows = show_icons.folder_arrows == 1,
has_devicons = has_devicons,
icons = icons,
}
end
return M

View File

@@ -39,9 +39,7 @@ function M.render_hl(bufnr, hl)
end
local function should_show_arrows()
return not M.config.indent_markers.enable
and icon_component.configs.show_folder_icon
and icon_component.configs.show_folder_arrows
return not M.config.indent_markers.enable and M.config.icons.show.folder and M.config.icons.show.folder_arrow
end
local picture_map = {
@@ -51,16 +49,6 @@ local picture_map = {
gif = true,
}
local function get_special_files_map()
return vim.g.nvim_tree_special_files
or {
["Cargo.toml"] = true,
Makefile = true,
["README.md"] = true,
["readme.md"] = true,
}
end
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
@@ -71,8 +59,7 @@ function M.draw()
local cursor = api.nvim_win_get_cursor(view.get_winnr())
_padding.reload_padding_function()
icon_component.reset_config(M.config.icons.webdev_colors)
git.reload()
icon_component.reset_config()
local lines, hl
local signs = {}
@@ -81,12 +68,12 @@ function M.draw()
else
lines, hl, signs = Builder.new(core.get_cwd())
:configure_initial_depth(should_show_arrows())
:configure_root_modifier(vim.g.nvim_tree_root_folder_modifier)
:configure_trailing_slash(vim.g.nvim_tree_add_trailing == 1)
:configure_special_map(get_special_files_map())
:configure_root_modifier(M.config.root_folder_modifier)
:configure_trailing_slash(M.config.add_trailing)
:configure_special_files(M.config.special_files)
:configure_picture_map(picture_map)
:configure_opened_file_highlighting(vim.g.nvim_tree_highlight_opened_files)
:configure_git_icons_padding(vim.g.nvim_tree_icon_padding)
:configure_opened_file_highlighting(M.config.highlight_opened_files)
:configure_git_icons_padding(M.config.icons.padding)
:configure_git_icons_placement(M.config.icons.git_placement)
:configure_filter(live_filter.filter, live_filter.prefix)
:build_header(view.is_root_folder_visible(core.get_cwd()))
@@ -112,13 +99,11 @@ function M.draw()
end
function M.setup(opts)
M.config = {
indent_markers = opts.renderer.indent_markers,
icons = opts.renderer.icons,
}
M.config = opts.renderer
_padding.setup(opts)
git.setup_signs()
git.setup(opts)
icon_component.setup(opts)
end
return M