Skip to content
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

chore: migrate to classic #2991

Merged
merged 38 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3501514
add classic, migrating nodes classes
alex-courtis Nov 4, 2024
359398d
add mixins to classic
alex-courtis Nov 4, 2024
ac302ae
typechecked optargs constructors for nodes
alex-courtis Nov 6, 2024
a7db5b2
typechecked optargs constructors for watcher and event
alex-courtis Nov 6, 2024
eab49e3
luacheck
alex-courtis Nov 6, 2024
b2f7b9a
typechecked optargs constructors for GitRunner
alex-courtis Nov 6, 2024
692fff7
typechecked optargs constructors for Sorter
alex-courtis Nov 6, 2024
4da6f4b
typechecked optargs constructors for decorators, WIP
alex-courtis Nov 6, 2024
b092915
typechecked optargs constructors for decorators, WIP
alex-courtis Nov 7, 2024
f6392cf
typechecked optargs constructors for decorators
alex-courtis Nov 7, 2024
5d7e543
remove class
alex-courtis Nov 8, 2024
9af0dc4
replace enums with named maps
alex-courtis Nov 8, 2024
5ef0616
Renderer and Builder use classic, tidy opts
alex-courtis Nov 8, 2024
2c172cf
LiveFilter uses classic, tidy opts
alex-courtis Nov 8, 2024
67cc06e
Filter uses classic, tidy opts
alex-courtis Nov 8, 2024
84d5f0a
add FilterTypes named map
alex-courtis Nov 8, 2024
db90f59
move toggles into filters
alex-courtis Nov 8, 2024
ef71841
Marks uses classic, tidy opts
alex-courtis Nov 8, 2024
1faa8a1
Sorter uses classic, tidy opts
alex-courtis Nov 8, 2024
92fa490
Clipboard uses classic, tidy opts
alex-courtis Nov 8, 2024
9fc7a86
use supers for node methods
alex-courtis Nov 8, 2024
82fc529
HighlightDisplay uses classic
alex-courtis Nov 8, 2024
412475e
protected :new
alex-courtis Nov 8, 2024
388439e
Watcher tidy
alex-courtis Nov 8, 2024
53fa471
Revert "use supers for node methods"
alex-courtis Nov 8, 2024
a219a19
Watcher tidy
alex-courtis Nov 8, 2024
f2dd8a4
format
alex-courtis Nov 8, 2024
ddd28ec
format
alex-courtis Nov 8, 2024
07a9fb1
Filters private methods
alex-courtis Nov 8, 2024
a08a54e
format
alex-courtis Nov 8, 2024
b70bb67
Sorter type safety
alex-courtis Nov 8, 2024
f06bd90
Sorter type safety
alex-courtis Nov 9, 2024
06b6326
Sorter type safety
alex-courtis Nov 9, 2024
f92db92
Sorter type safety
alex-courtis Nov 9, 2024
30f1aa3
Sorter type safety
alex-courtis Nov 9, 2024
bb0e0ec
Sorter type safety
alex-courtis Nov 9, 2024
7957922
tidy Runner
alex-courtis Nov 9, 2024
4f40875
tidy hi-test name
alex-courtis Nov 9, 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
45 changes: 21 additions & 24 deletions lua/nvim-tree/actions/fs/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,39 @@ local notify = require("nvim-tree.notify")

local find_file = require("nvim-tree.actions.finders.find-file").fn

local Class = require("nvim-tree.classic")
local DirectoryNode = require("nvim-tree.node.directory")

---@alias ClipboardAction "copy" | "cut"
---@alias ClipboardData table<ClipboardAction, Node[]>

---@alias ClipboardActionFn fun(source: string, dest: string): boolean, string?

---@class Clipboard to handle all actions.fs clipboard API
---@field config table hydrated user opts.filters
---@class (exact) Clipboard: Class
---@field private explorer Explorer
---@field private data ClipboardData
---@field private clipboard_name string
---@field private reg string
local Clipboard = {}

---@param opts table user options
---@param explorer Explorer
---@return Clipboard
function Clipboard:new(opts, explorer)
---@type Clipboard
local o = {
explorer = explorer,
data = {
copy = {},
cut = {},
},
clipboard_name = opts.actions.use_system_clipboard and "system" or "neovim",
reg = opts.actions.use_system_clipboard and "+" or "1",
config = {
filesystem_watchers = opts.filesystem_watchers,
},
local Clipboard = Class:extend()

---@class Clipboard
---@overload fun(args: ClipboardArgs): Clipboard

---@class (exact) ClipboardArgs
---@field explorer Explorer

---@protected
---@param args ClipboardArgs
function Clipboard:new(args)
self.explorer = args.explorer

self.data = {
copy = {},
cut = {},
}

setmetatable(o, self)
self.__index = self
return o
self.clipboard_name = self.explorer.opts.actions.use_system_clipboard and "system" or "neovim"
self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1"
end

---@param source string
Expand Down Expand Up @@ -252,7 +249,7 @@ function Clipboard:do_paste(node, action, action_fn)
end

self.data[action] = {}
if not self.config.filesystem_watchers.enable then
if not self.explorer.opts.filesystem_watchers.enable then
self.explorer:reload_explorer()
end
end
Expand Down
1 change: 0 additions & 1 deletion lua/nvim-tree/actions/tree/modifiers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local M = {}

M.collapse_all = require("nvim-tree.actions.tree.modifiers.collapse-all")
M.expand_all = require("nvim-tree.actions.tree.modifiers.expand-all")
M.toggles = require("nvim-tree.actions.tree.modifiers.toggles")

function M.setup(opts)
M.expand_all.setup(opts)
Expand Down
73 changes: 0 additions & 73 deletions lua/nvim-tree/actions/tree/modifiers/toggles.lua

This file was deleted.

34 changes: 25 additions & 9 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local core = require("nvim-tree.core")
local view = require("nvim-tree.view")
local utils = require("nvim-tree.utils")
local actions = require("nvim-tree.actions")
local appearance_diagnostics = require("nvim-tree.appearance.diagnostics")
local appearance_hi_test = require("nvim-tree.appearance.hi-test")
local events = require("nvim-tree.events")
local help = require("nvim-tree.help")
local keymap = require("nvim-tree.keymap")
Expand Down Expand Up @@ -89,6 +89,22 @@ local function wrap_node_or_nil(fn)
end
end

---Invoke a member's method on the singleton explorer.
---Print error when setup not called.
---@param explorer_member string explorer member name
---@param member_method string method name to invoke on member
---@param ... any passed to method
---@return fun(...): any
local function wrap_explorer_member_args(explorer_member, member_method, ...)
local method_args = ...
return wrap(function(...)
local explorer = core.get_explorer()
if explorer then
return explorer[explorer_member][member_method](explorer[explorer_member], method_args, ...)
end
end)
end

---Invoke a member's method on the singleton explorer.
---Print error when setup not called.
---@param explorer_member string explorer member name
Expand Down Expand Up @@ -165,13 +181,13 @@ Api.tree.find_file = wrap(actions.tree.find_file.fn)
Api.tree.search_node = wrap(actions.finders.search_node.fn)
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse_all.fn)
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand_all.fn)
Api.tree.toggle_enable_filters = wrap(actions.tree.modifiers.toggles.enable)
Api.tree.toggle_gitignore_filter = wrap(actions.tree.modifiers.toggles.git_ignored)
Api.tree.toggle_git_clean_filter = wrap(actions.tree.modifiers.toggles.git_clean)
Api.tree.toggle_no_buffer_filter = wrap(actions.tree.modifiers.toggles.no_buffer)
Api.tree.toggle_custom_filter = wrap(actions.tree.modifiers.toggles.custom)
Api.tree.toggle_hidden_filter = wrap(actions.tree.modifiers.toggles.dotfiles)
Api.tree.toggle_no_bookmark_filter = wrap(actions.tree.modifiers.toggles.no_bookmark)
Api.tree.toggle_enable_filters = wrap_explorer_member("filters", "toggle")
Api.tree.toggle_gitignore_filter = wrap_explorer_member_args("filters", "toggle", "git_ignored")
Api.tree.toggle_git_clean_filter = wrap_explorer_member_args("filters", "toggle", "git_clean")
Api.tree.toggle_no_buffer_filter = wrap_explorer_member_args("filters", "toggle", "no_buffer")
Api.tree.toggle_custom_filter = wrap_explorer_member_args("filters", "toggle", "custom")
Api.tree.toggle_hidden_filter = wrap_explorer_member_args("filters", "toggle", "dotfiles")
Api.tree.toggle_no_bookmark_filter = wrap_explorer_member_args("filters", "toggle", "no_bookmark")
Api.tree.toggle_help = wrap(help.toggle)
Api.tree.is_tree_buf = wrap(utils.is_nvim_tree_buf)

Expand Down Expand Up @@ -289,7 +305,7 @@ Api.config.mappings.get_keymap = wrap(keymap.get_keymap)
Api.config.mappings.get_keymap_default = wrap(keymap.get_keymap_default)
Api.config.mappings.default_on_attach = keymap.default_on_attach

Api.diagnostics.hi_test = wrap(appearance_diagnostics.hi_test)
Api.diagnostics.hi_test = wrap(appearance_hi_test)

Api.commands.get = wrap(function()
return require("nvim-tree.commands").get()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
local appearance = require("nvim-tree.appearance")

local Class = require("nvim-tree.classic")

-- others with name and links less than this arbitrary value are short
local SHORT_LEN = 50

local M = {}

---@class HighlightDisplay for :NvimTreeHiTest
---@class (exact) HighlightDisplay: Class for :NvimTreeHiTest
---@field group string nvim-tree highlight group name
---@field links string link chain to a concretely defined group
---@field def string :hi concrete definition after following any links
local HighlightDisplay = {}
local HighlightDisplay = Class:extend()

---@param group string nvim-tree highlight group name
---@return HighlightDisplay
function HighlightDisplay:new(group)
local o = {}
setmetatable(o, self)
self.__index = self
---@class HighlightDisplay
---@overload fun(args: HighlightDisplayArgs): HighlightDisplay

---@class (exact) HighlightDisplayArgs
---@field group string nvim-tree highlight group name

o.group = group
local concrete = o.group
---@protected
---@param args HighlightDisplayArgs
function HighlightDisplay:new(args)
self.group = args.group

local concrete = self.group

-- maybe follow links
local links = {}
local link = vim.api.nvim_get_hl(0, { name = o.group }).link
local link = vim.api.nvim_get_hl(0, { name = self.group }).link
while link do
table.insert(links, link)
concrete = link
link = vim.api.nvim_get_hl(0, { name = link }).link
end
o.links = table.concat(links, " ")
self.links = table.concat(links, " ")

-- concrete definition
local ok, res = pcall(vim.api.nvim_cmd, { cmd = "highlight", args = { concrete } }, { output = true })
if ok and type(res) == "string" then
o.def = res:gsub(".*xxx *", "")
self.def = res:gsub(".*xxx *", "")
else
o.def = ""
self.def = ""
end

return o
end

---Render one group.
Expand Down Expand Up @@ -87,7 +88,7 @@ end

---Run a test similar to :so $VIMRUNTIME/syntax/hitest.vim
---Display all nvim-tree and neovim highlight groups, their link chain and actual definition
function M.hi_test()
return function()
-- create a buffer
local bufnr = vim.api.nvim_create_buf(false, true)

Expand All @@ -96,7 +97,7 @@ function M.hi_test()
-- nvim-tree groups, ordered
local displays = {}
for _, highlight_group in ipairs(appearance.HIGHLIGHT_GROUPS) do
local display = HighlightDisplay:new(highlight_group.group)
local display = HighlightDisplay({ group = highlight_group.group })
table.insert(displays, display)
end
l = render_displays("nvim-tree", displays, bufnr, l)
Expand All @@ -110,7 +111,7 @@ function M.hi_test()
if ok then
for group in string.gmatch(out, "(%w*)%s+xxx") do
if group:find("NvimTree", 1, true) ~= 1 then
local display = HighlightDisplay:new(group)
local display = HighlightDisplay({ group = group })
if #display.group + #display.links > SHORT_LEN then
table.insert(displays_long, display)
else
Expand All @@ -137,5 +138,3 @@ function M.hi_test()

vim.cmd.buffer(bufnr)
end

return M
47 changes: 0 additions & 47 deletions lua/nvim-tree/class.lua

This file was deleted.

Loading
Loading