Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,14 @@ function M.setup(config_user)

manage_netrw()

require("nvim-tree.log").setup(config.g)
require("nvim-tree.log").start()

if log.enabled("config") then
log.line("config", "default config + user")
log.raw("config", "%s\n", vim.inspect(config.g))
end

require("nvim-tree.appearance").setup()
require("nvim-tree.renderer.components").setup(config.g)
require("nvim-tree.appearance").set_hl()

setup_autocommands()

Expand Down
4 changes: 0 additions & 4 deletions lua/nvim-tree/actions/fs/rename-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,4 @@ function M.rename_full(node)
prompt_to_rename(node, ":p")
end

function M.setup(opts)
config.g.filesystem_watchers = opts.filesystem_watchers
end

return M
3 changes: 2 additions & 1 deletion lua/nvim-tree/appearance/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ M.LEGACY_LINKS = {
NvimTreeDiagnosticHintFolderHL = "NvimTreeLspDiagnosticsHintFolderText",
}

function M.setup()
---Create all highlight groups and links. Idempotent.
function M.set_hl()
-- non-linked
for _, g in ipairs(M.HIGHLIGHT_GROUPS) do
if g.def then
Expand Down
15 changes: 15 additions & 0 deletions lua/nvim-tree/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,21 @@ local function process_config(g)
-- Open
--
g.actions.open_file.window_picker.chars = tostring(g.actions.open_file.window_picker.chars):upper()

--
-- Padding
--
if g.renderer.indent_width < 1 then
g.renderer.indent_width = 1
end
for k, v in pairs(g.renderer.indent_markers.icons) do
if #v == 0 then
g.renderer.indent_markers.icons[k] = " "
else
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
g.renderer.indent_markers.icons[k] = v:match("[%z\1-\127\194-\244][\128-\191]*")
end
end
end

---Validate user config and migrate legacy.
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function Explorer:create_autocmds()
vim.api.nvim_create_autocmd("ColorScheme", {
group = self.augroup_id,
callback = function()
appearance.setup()
appearance.set_hl()
view.reset_winhl()
self.renderer:draw()
end,
Expand Down
11 changes: 7 additions & 4 deletions lua/nvim-tree/log.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local config = require("nvim-tree.config")

---@alias LogTypes "all" | "config" | "copy_paste" | "dev" | "diagnostics" | "git" | "profile" | "watcher"

---@type table<LogTypes, boolean>
Expand Down Expand Up @@ -110,11 +112,12 @@ function M.enabled(typ)
return file_path ~= nil and (types[typ] or types.all)
end

function M.setup(opts)
if opts.log and opts.log.enable and opts.log.types then
types = opts.log.types
--- Create the log file and enable logging, if globally configured
function M.start()
if config.g.log and config.g.log.enable and config.g.log.types then
types = config.g.log.types
file_path = string.format("%s/nvim-tree.log", vim.fn.stdpath("log"), os.date("%H:%M:%S"), vim.env.USER)
if opts.log.truncate then
if config.g.log.truncate then
os.remove(file_path)
end
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path)
Expand Down
35 changes: 22 additions & 13 deletions lua/nvim-tree/renderer/components/devicons.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local config = require("nvim-tree.config")

---@alias devicons_get_icon fun(name: string, ext: string?, opts: table?): string?, string?
---@alias devicons_setup fun(opts: table?)

Expand All @@ -6,22 +8,14 @@
---@field get_icon devicons_get_icon
local devicons

local M = {}
--One shot lazy discovery and setup done
local initialized = false

---Wrapper around nvim-web-devicons, nils if devicons not available
---@type devicons_get_icon
function M.get_icon(name, ext, opts)
if devicons then
return devicons.get_icon(name, ext, opts)
else
return nil, nil
end
end
local M = {}

---Attempt to use nvim-web-devicons if present and enabled for file or folder
---@param opts table
function M.setup(opts)
if opts.renderer.icons.show.file or opts.renderer.icons.show.folder then
local function initialize()
if config.g.renderer.icons.show.file or config.g.renderer.icons.show.folder then
local ok, di = pcall(require, "nvim-web-devicons")
if ok then
devicons = di --[[@as DevIcons]]
Expand All @@ -30,6 +24,21 @@ function M.setup(opts)
devicons.setup()
end
end
initialized = true
end

---Wrapper around nvim-web-devicons, nils if devicons not available
---@type devicons_get_icon
function M.get_icon(name, ext, opts)
if not initialized then
initialize()
end

if devicons then
return devicons.get_icon(name, ext, opts)
else
return nil, nil
end
end

return M
11 changes: 0 additions & 11 deletions lua/nvim-tree/renderer/components/init.lua

This file was deleted.

55 changes: 18 additions & 37 deletions lua/nvim-tree/renderer/components/padding.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local config = require("nvim-tree.config")
local DirectoryNode = require("nvim-tree.node.directory")

local M = {}
Expand Down Expand Up @@ -27,21 +28,21 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit

if depth > 0 then
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
local indent = string.rep(" ", M.config.indent_width - 1)
local indent = string.rep(" ", config.g.renderer.indent_width - 1)
markers[depth] = idx ~= nodes_number
for i = 1, depth - early_stop do
local glyph
if idx == nodes_number and i == depth then
local bottom_width = M.config.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0)
glyph = M.config.indent_markers.icons.corner
.. string.rep(M.config.indent_markers.icons.bottom, bottom_width)
.. (M.config.indent_width > 1 and " " or "")
local bottom_width = config.g.renderer.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0)
glyph = config.g.renderer.indent_markers.icons.corner
.. string.rep(config.g.renderer.indent_markers.icons.bottom, bottom_width)
.. (config.g.renderer.indent_width > 1 and " " or "")
elseif markers[i] and i == depth then
glyph = M.config.indent_markers.icons.item .. indent
glyph = config.g.renderer.indent_markers.icons.item .. indent
elseif markers[i] then
glyph = M.config.indent_markers.icons.edge .. indent
glyph = config.g.renderer.indent_markers.icons.edge .. indent
else
glyph = M.config.indent_markers.icons.none .. indent
glyph = config.g.renderer.indent_markers.icons.none .. indent
end

if not with_arrows or (inline_arrows and (depth ~= i or not node.nodes)) then
Expand All @@ -68,10 +69,10 @@ end
function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop)
local str = ""

local show_arrows = M.config.icons.show.folder_arrow
local show_markers = M.config.indent_markers.enable
local inline_arrows = M.config.indent_markers.inline_arrows
local indent_width = M.config.indent_width
local show_arrows = config.g.renderer.icons.show.folder_arrow
local show_markers = config.g.renderer.indent_markers.enable
local inline_arrows = config.g.renderer.indent_markers.inline_arrows
local indent_width = config.g.renderer.indent_width

if show_markers then
str = str .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node, early_stop or 0)
Expand All @@ -85,7 +86,7 @@ end
---@param node Node
---@return nvim_tree.api.highlighted_string[]?
function M.get_arrows(node)
if not M.config.icons.show.folder_arrow then
if not config.g.renderer.icons.show.folder_arrow then
return
end

Expand All @@ -95,38 +96,18 @@ function M.get_arrows(node)
local dir = node:as(DirectoryNode)
if dir then
if dir.open then
str = M.config.icons.glyphs.folder["arrow_open"] .. M.config.icons.padding.folder_arrow
str = config.g.renderer.icons.glyphs.folder["arrow_open"] .. config.g.renderer.icons.padding.folder_arrow
hl = "NvimTreeFolderArrowOpen"
else
str = M.config.icons.glyphs.folder["arrow_closed"] .. M.config.icons.padding.folder_arrow
str = config.g.renderer.icons.glyphs.folder["arrow_closed"] .. config.g.renderer.icons.padding.folder_arrow
end
elseif M.config.indent_markers.enable then
elseif config.g.renderer.indent_markers.enable then
str = ""
else
str = " " .. string.rep(" ", #M.config.icons.padding.folder_arrow)
str = " " .. string.rep(" ", #config.g.renderer.icons.padding.folder_arrow)
end

return { str = str, hl = { hl } }
end

function M.setup(opts)
M.config = opts.renderer

if M.config.indent_width < 1 then
M.config.indent_width = 1
end

local function check_marker(symbol)
if #symbol == 0 then
return " "
end
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
return symbol:match("[%z\1-\127\194-\244][\128-\191]*")
end

for k, v in pairs(M.config.indent_markers.icons) do
M.config.indent_markers.icons[k] = check_marker(v)
end
end

return M
Loading