Skip to content

Commit 6d5b323

Browse files
committed
WIP, breaking changes in filters config
1 parent 8ea8c33 commit 6d5b323

File tree

12 files changed

+149
-46
lines changed

12 files changed

+149
-46
lines changed

lua/neo-tree.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,27 @@ end
523523
M.setup = function(config, is_auto_config)
524524
local default_config = vim.deepcopy(defaults)
525525
config = vim.deepcopy(config or {})
526+
527+
local messages = require("neo-tree.deprecations").migrate(config)
528+
if #messages > 0 then
529+
for i, message in ipairs(messages) do
530+
messages[i] = " * " .. message
531+
end
532+
table.insert(messages, 1, "# Neo-tree configuration has been updated. Please review the changes below.")
533+
local buf = vim.api.nvim_create_buf(false, true)
534+
vim.api.nvim_buf_set_lines(buf, 0, -1, false, messages)
535+
vim.api.nvim_buf_set_option(buf, "buftype", "nofile")
536+
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
537+
vim.api.nvim_buf_set_option(buf, "buflisted", false)
538+
vim.api.nvim_buf_set_option(buf, "swapfile", false)
539+
vim.api.nvim_buf_set_option(buf, "modifiable", false)
540+
vim.api.nvim_buf_set_option(buf, "filetype", "markdown")
541+
vim.defer_fn(function ()
542+
vim.cmd("split")
543+
vim.api.nvim_win_set_buf(0, buf)
544+
end, 1000)
545+
end
546+
526547
if config.log_level ~= nil then
527548
M.set_log_level(config.log_level)
528549
end

lua/neo-tree/defaults.lua

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,28 @@ local config = {
155155
-- return args
156156
--end,
157157
search_limit = 50, -- max number of search results when using filters
158-
filters = {
159-
show_hidden = false,
160-
respect_gitignore = true,
161-
gitignore_source = "git status", -- or "git check-ignored", which may be faster in some repos
162-
exclude_items = {}, -- List of item names to skip, such as:
163-
-- { 'node-module', '.DS_Store' }
164-
show_filtered = { -- Instead of hiding them completely, show them with a different
165-
exclude = true, -- highlight group
166-
gitignore = true,
167-
hidden = true
168-
}
158+
--filters = {
159+
-- show_hidden = false,
160+
-- respect_gitignore = true,
161+
-- gitignore_source = "git status", -- or "git check-ignored", which may be faster in some repos
162+
-- exclude_items = {}, -- List of item names to skip, such as:
163+
-- -- { 'node-module', '.DS_Store' }
164+
-- show_filtered = { -- Instead of hiding them completely, show them with a different
165+
-- exclude = true, -- highlight group
166+
-- gitignore = true,
167+
-- hidden = true
168+
--},
169+
filtered_items = {
170+
visible = false, -- if true, they will just be displayed differently than normal items
171+
hide_dotfiles = true,
172+
hide_gitignored = true,
173+
hide_by_name = {
174+
"node_modules"
175+
},
176+
never_show = {
177+
".DS_Store",
178+
"thumbs.db"
179+
},
169180
},
170181
bind_to_cwd = true, -- true creates a 2-way binding between vim's cwd and neo-tree's root
171182
-- The renderer section provides the renderers that will be used to render the tree.

lua/neo-tree/deprecations.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local utils = require "neo-tree.utils"
2+
3+
local migrate = function (config)
4+
local messages = {}
5+
6+
local moved = function (old, new, converter)
7+
local exising = utils.get_value(config, old)
8+
if type(exising) ~= "nil" then
9+
if type(converter) == "function" then
10+
exising = converter(exising)
11+
end
12+
utils.set_value(config, new, exising)
13+
config[old] = nil
14+
messages[#messages + 1] = string.format("The `%s` option has been deprecated, please use `%s` instead.", old, new)
15+
end
16+
end
17+
18+
local opposite = function (value)
19+
return not value
20+
end
21+
22+
moved("filesystem.filters", "filesystem.filtered_items")
23+
moved("filesystem.filters.show_hidden", "filesystem.filtered_items.hide_dotfiles", opposite)
24+
moved("filesystem.filters.respect_gitignore", "filesystem.filtered_items.hide_gitignored")
25+
moved("filesystem.filters.gitignore_source", "filesystem.filtered_items.gitignore_source")
26+
27+
return messages
28+
end
29+
30+
return {
31+
migrate = migrate
32+
}

lua/neo-tree/setup/init.lua

Whitespace-only changes.

lua/neo-tree/sources/common/components.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ M.git_status = function(config, node, state)
7979
end
8080
local git_status = git_status_lookup[node.path]
8181
if not git_status then
82-
return {}
82+
if node.filtered_by and node.filtered_by.gitignored then
83+
git_status = "!!"
84+
else
85+
return {}
86+
end
8387
end
8488

8589
local highlight = highlights.FILE_NAME
@@ -93,6 +97,8 @@ M.git_status = function(config, node, state)
9397
highlight = highlights.GIT_MODIFIED
9498
elseif git_status:match("[ACRT]") then
9599
highlight = highlights.GIT_ADDED
100+
elseif git_status:match("!") then
101+
highlight = highlights.GIT_IGNORED
96102
end
97103

98104
return {
@@ -148,9 +154,15 @@ M.name = function(config, node, state)
148154
end
149155
end
150156

151-
if node.filtered_by and #node.filtered_by > 0 then
152-
text = text .. " (" .. node.filtered_by .. ")"
153-
highlight = highlights.DIM_TEXT
157+
if type(node.filtered_by) == "table" then
158+
local fby = node.filtered_by
159+
if fby.name then
160+
highlight = highlights.HIDDEN_BY_NAME
161+
elseif fby.dotfiles then
162+
highlight = highlights.DOTFILE
163+
elseif fby.gitignored then
164+
highlight = highlights.GIT_IGNORED
165+
end
154166
end
155167

156168
return {

lua/neo-tree/sources/common/file-items.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,21 @@ function create_item(context, path, _type)
5555
end
5656

5757
local state = context.state
58-
local filters = state.filters
59-
if filters then
60-
local exclude = filters.exclude_items or {}
61-
if exclude[name] then
58+
local f = state.filtered_items
59+
if f then
60+
if f.hide_by_name[name] then
6261
item.filtered_by = item.filtered_by or {}
63-
item.filtered_by.exclude = true
64-
elseif not filters.show_hidden and string.sub(item.name, 1, 1) == "." then
62+
item.filtered_by.name = true
63+
elseif f.never_show[name] then
6564
item.filtered_by = item.filtered_by or {}
66-
item.filtered_by.hidden = true
67-
elseif filters.respect_gitignore and utils.truthy(state.git_ignored) then
65+
item.filtered_by.never_show = true
66+
elseif f.hide_dotfiles and string.sub(item.name, 1, 1) == "." then
67+
item.filtered_by = item.filtered_by or {}
68+
item.filtered_by.dotfiles = true
69+
elseif f.hide_gitignored and utils.truthy(state.git_ignored) then
6870
if git.is_ignored(state.git_ignored, path, _type) then
6971
item.filtered_by = item.filtered_by or {}
70-
item.filtered_by.gitignore = true
72+
item.filtered_by.gitignored = true
7173
end
7274
end
7375
end

lua/neo-tree/sources/filesystem/commands.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local fs = require("neo-tree.sources.filesystem")
55
local utils = require("neo-tree.utils")
66
local filter = require("neo-tree.sources.filesystem.lib.filter")
77
local manager = require("neo-tree.sources.manager")
8+
local log = require("neo-tree.log")
89

910
local M = {}
1011
local refresh = utils.wrap(manager.refresh, "filesystem")
@@ -111,14 +112,15 @@ M.show_debug_info = cc.show_debug_info
111112

112113
---Toggles whether hidden files are shown or not.
113114
M.toggle_hidden = function(state)
114-
state.filters.show_hidden = not state.filters.show_hidden
115+
state.filtered_items.visible = not state.filtered_items.visible
116+
log.info("Toggling hidden files: " .. tostring(state.filtered_items.visible))
115117
refresh()
116118
end
117119

118120
---Toggles whether the tree is filtered by gitignore or not.
119121
M.toggle_gitignore = function(state)
120-
state.filters.respect_gitignore = not state.filters.respect_gitignore
121-
refresh()
122+
log.warn("`toggle_gitignore` has been removed, running toggle_hidden instead.")
123+
M.toggle_hidden(state)
122124
end
123125

124126
return M

lua/neo-tree/sources/filesystem/lib/filter_external.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ local get_find_command = function(state)
4444
end
4545

4646
M.find_files = function(opts)
47-
local filters = opts.filters
47+
local filters = opts.filtered_items
4848
local limit = opts.limit or 200
4949
local cmd = get_find_command(opts)
5050
local path = opts.path
@@ -73,10 +73,10 @@ M.find_files = function(opts)
7373
end
7474

7575
if cmd == "fd" or cmd == "fdfind" then
76-
if filters.show_hidden then
76+
if filters.visible or not filters.hide_dotfiles then
7777
append("--hidden")
7878
end
79-
if not filters.respect_gitignore then
79+
if filters.visible or not filters.hide_gitignored then
8080
append("--no-ignore")
8181
end
8282
if full_path_words then
@@ -92,7 +92,7 @@ M.find_files = function(opts)
9292
elseif cmd == "find" then
9393
append(path)
9494
append("-type", "f,d")
95-
if not filters.show_hidden then
95+
if not filters.visible and filters.hide_dotfiles then
9696
append("-not", "-path", "*/.*")
9797
end
9898
if full_path_words then

lua/neo-tree/sources/filesystem/lib/fs_scan.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ local function do_scan(context, path_to_scan)
1717
local state = context.state
1818
local paths_to_load = context.paths_to_load
1919
local folders = context.folders
20-
local filters = state.filters or {}
20+
local filters = state.filtered_items or {}
2121

2222
scan.scan_dir_async(path_to_scan, {
23-
hidden = filters.show_hidden or false,
2423
search_pattern = state.search_pattern or nil,
25-
respect_gitignore = filters.respect_gitignore and filters.gitignore_source == "plenary",
24+
hidden = true,
25+
respect_gitignore = false,
2626
add_dirs = true,
2727
depth = 1,
2828
on_insert = function(path, _type)
@@ -103,7 +103,7 @@ M.get_items_async = function(state, parent_id, path_to_reveal, callback)
103103
if state.search_pattern then
104104
-- Use the external command because the plenary search is slow
105105
filter_external.find_files({
106-
filters = state.filters,
106+
filtered_items = state.filtered_items,
107107
find_command = state.find_command,
108108
limit = state.search_limit or 50,
109109
path = root.path,
@@ -148,11 +148,12 @@ M.get_items_async = function(state, parent_id, path_to_reveal, callback)
148148
context.paths_to_load = utils.unique(context.paths_to_load)
149149
end
150150

151+
local f = state.filtered_items or {}
151152
local ignored = {}
152-
if state.filters.respect_gitignore then
153-
if state.filters.gitignore_source == "git status" then
153+
if f.hide_gitignored then
154+
if f.gitignore_source == "git status" then
154155
ignored = git.load_ignored(state.path)
155-
elseif state.filters.gitignore_source == "git check-ignore" then
156+
elseif f.gitignore_source == "git check-ignore" then
156157
ignored = git.load_ignored_per_directory(state.path)
157158
for _, p in ipairs(context.paths_to_load) do
158159
vim.list_extend(ignored, git.load_ignored_per_directory(p))
@@ -162,9 +163,8 @@ M.get_items_async = function(state, parent_id, path_to_reveal, callback)
162163
state.git_ignored = ignored
163164
else
164165
-- just update the ignored list for this dir if we are using the per dir 'check-ignore' option
165-
if
166-
state.filters.respect_gitignore and state.filters.gitignore_source == "git check-ignore"
167-
then
166+
local f = state.filtered_items or {}
167+
if f.hide_gitignored and f.gitignore_source == "git check-ignore" then
168168
state.git_ignored = state.git_ignored or {}
169169
vim.list_extend(state.git_ignored, git.load_ignored_per_directory(parent_id))
170170
end

lua/neo-tree/ui/highlights.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ M.GIT_ADDED = "NeoTreeGitAdded"
1616
M.GIT_CONFLICT = "NeoTreeGitConflict"
1717
M.GIT_MODIFIED = "NeoTreeGitModified"
1818
M.GIT_UNTRACKED = "NeoTreeGitUntracked"
19+
M.GIT_IGNORED = "NeoTreeGitIgnored"
1920
M.NORMAL = "NeoTreeNormal"
2021
M.NORMALNC = "NeoTreeNormalNC"
2122
M.ROOT_NAME = "NeoTreeRootName"
2223
M.TITLE_BAR = "NeoTreeTitleBar"
2324
M.INDENT_MARKER = "NeoTreeIndentMarker"
25+
M.DOTFILE = "NeoTreeDotfile"
26+
M.HIDDEN_BY_NAME = "NeoTreeHiddenByName"
2427

2528
local function dec_to_hex(n)
2629
local hex = string.format("%06x", n)
@@ -111,6 +114,9 @@ M.setup = function()
111114

112115
create_highlight_group(M.BUFFER_NUMBER, { "SpecialChar" })
113116
create_highlight_group(M.DIM_TEXT, {}, nil, "505050")
117+
create_highlight_group(M.DOTFILE, {}, nil, "626262")
118+
create_highlight_group(M.GIT_IGNORED, { M.DOTFILE }, nil, nil)
119+
create_highlight_group(M.HIDDEN_BY_NAME, { M.DOTFILE }, nil, nil)
114120
create_highlight_group(M.CURSOR_LINE, { "CursorLine" }, nil, nil, "bold")
115121
create_highlight_group(M.DIRECTORY_NAME, {}, "NONE", "NONE")
116122
create_highlight_group(M.DIRECTORY_ICON, {}, nil, "73cef4")

0 commit comments

Comments
 (0)