Skip to content

Commit 1dd1698

Browse files
committed
fix(files): fixes #48, test for max-results support in fd before using it, schedule_wrap log statements to the console
1 parent 6832ed1 commit 1dd1698

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

doc/neo-tree.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,14 @@ require("neo-tree").setup({
241241
["p"] = "paste_from_clipboard",
242242
}
243243
},
244+
--find_command = "fd" -- if not specified, it will test for fd, fdfind, find, or where
244245
search_limit = 50, -- max number of search results when using filters
245246
filters = {
246247
show_hidden = false,
247248
respect_gitignore = true,
248249
},
249250
bind_to_cwd = true, -- true creates a 2-way binding between vim's cwd and neo-tree's root
251+
--
250252
-- The components section provides custom functions that may be called by
251253
-- the renderers below. Each componment is a function that takes the
252254
-- following arguments:

lua/neo-tree/log.lua

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
-- This library is free software; you can redistribute it and/or modify it
77
-- under the terms of the MIT license. See LICENSE for details.
88

9+
local vim = vim
910
-- User configuration section
1011
local default_config = {
1112
-- Name of the plugin. Prepended to log messages
@@ -66,7 +67,11 @@ log.new = function(config, standalone)
6667
end
6768
config.use_file = false
6869
else
69-
obj.outfile = file or outfile
70+
if type(file) == "string" then
71+
obj.outfile = file
72+
else
73+
obj.outfile = outfile
74+
end
7075
config.use_file = true
7176
if not quiet then
7277
obj.info("[neo-tree] Logging to file: " .. obj.outfile)
@@ -137,26 +142,28 @@ log.new = function(config, standalone)
137142

138143
-- Output to console
139144
if config.use_console and level > 2 then
140-
local console_string = string.format(
141-
"[%-6s%s] %s: %s",
142-
nameupper,
143-
os.date("%H:%M:%S"),
144-
lineinfo,
145-
msg
146-
)
147-
148-
if config.highlights and level_config.hl then
149-
vim.cmd(string.format("echohl %s", level_config.hl))
150-
end
145+
vim.schedule(function()
146+
local console_string = string.format(
147+
"[%-6s%s] %s: %s",
148+
nameupper,
149+
os.date("%H:%M:%S"),
150+
lineinfo,
151+
msg
152+
)
153+
154+
if config.highlights and level_config.hl then
155+
vim.cmd(string.format("echohl %s", level_config.hl))
156+
end
151157

152-
local split_console = vim.split(console_string, "\n")
153-
for _, v in ipairs(split_console) do
154-
vim.cmd(string.format([[echom "[%s] %s"]], config.plugin, vim.fn.escape(v, '"')))
155-
end
158+
local split_console = vim.split(console_string, "\n")
159+
for _, v in ipairs(split_console) do
160+
vim.cmd(string.format([[echom "[%s] %s"]], config.plugin, vim.fn.escape(v, '"')))
161+
end
156162

157-
if config.highlights and level_config.hl then
158-
vim.cmd("echohl NONE")
159-
end
163+
if config.highlights and level_config.hl then
164+
vim.cmd("echohl NONE")
165+
end
166+
end)
160167
end
161168
end
162169

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
local vim = vim
2+
local log = require("neo-tree.log")
23
local Job = require("plenary.job")
34

45
local M = {}
6+
local fd_supports_max_results = nil
7+
8+
local test_for_max_results = function(cmd)
9+
if fd_supports_max_results == nil then
10+
if cmd == "fd" or cmd == "fdfind" then
11+
--test if it supports the max-results option
12+
local test = vim.fn.system(cmd .. " this_is_only_a_test --max-depth=1 --max-results=1")
13+
if test:match("^error:") then
14+
fd_supports_max_results = false
15+
log.debug(cmd, "does NOT support max-results")
16+
else
17+
fd_supports_max_results = true
18+
log.debug(cmd, "supports max-results")
19+
end
20+
end
21+
end
22+
end
523

624
local get_find_command = function(state)
725
if state.find_command then
26+
test_for_max_results(state.find_command)
827
return state.find_command
928
end
1029

@@ -17,6 +36,8 @@ local get_find_command = function(state)
1736
elseif 1 == vim.fn.executable("where") then
1837
state.find_command = "where"
1938
end
39+
40+
test_for_max_results(state.find_command)
2041
return state.find_command
2142
end
2243

@@ -47,7 +68,9 @@ M.find_files = function(opts)
4768
end
4869
append("--glob", term, path)
4970
append("--color", "never")
50-
append("--max-results", limit)
71+
if fd_supports_max_results then
72+
append("--max-results", limit)
73+
end
5174
elseif cmd == "find" then
5275
append(path)
5376
append("-type", "f,d")

0 commit comments

Comments
 (0)