summaryrefslogtreecommitdiff
path: root/lua/telescope
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-09-02 19:11:38 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-09-02 19:11:38 -0400
commitd48a2933d55a5aa2ca3c15e482a90bbffbb49b92 (patch)
tree7f44146ba314879c6cd6d7beb5aa026454f5d21c /lua/telescope
parent061307233cdff0a90504117dd48e4fec3a10443a (diff)
fix: clear last line
Diffstat (limited to 'lua/telescope')
-rw-r--r--lua/telescope/builtin.lua18
-rw-r--r--lua/telescope/finders.lua1
-rw-r--r--lua/telescope/pickers.lua16
3 files changed, 33 insertions, 2 deletions
diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua
index afc104c..d207b99 100644
--- a/lua/telescope/builtin.lua
+++ b/lua/telescope/builtin.lua
@@ -246,6 +246,8 @@ end
builtin.fd = function(opts)
+ opts = opts or {}
+
local fd_string = nil
if 1 == vim.fn.executable("fd") then
fd_string = "fd"
@@ -258,9 +260,23 @@ builtin.fd = function(opts)
return
end
+ -- TODO: CWD not 100% supported at this moment.
+ -- Previewers don't work. We'll have to try out something for that later
+ local cwd = opts.cwd
+ if cwd then
+ cwd = vim.fn.expand(cwd)
+ end
+
pickers.new(opts, {
prompt = 'Find Files',
- finder = finders.new_oneshot_job {fd_string},
+ finder = finders.new {
+ fn_command = function()
+ return {
+ command = fd_string,
+ cwd = cwd,
+ }
+ end,
+ },
previewer = previewers.cat,
sorter = sorters.get_fuzzy_file(),
}):find()
diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua
index 56b823b..b1a3819 100644
--- a/lua/telescope/finders.lua
+++ b/lua/telescope/finders.lua
@@ -125,6 +125,7 @@ function Finder:_find(prompt, process_result, process_complete)
self.job = Job:new {
command = opts.command,
args = opts.args,
+ cwd = opts.cwd,
maximum_results = self.maximum_results,
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 51b1162..db46e20 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -231,6 +231,10 @@ function Picker:find()
local selection_strategy = self.selection_strategy or 'reset'
local on_lines = function(_, _, _, first_line, last_line)
+ if not vim.api.nvim_buf_is_valid(prompt_bufnr) then
+ return
+ end
+
local prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, first_line, last_line, false)[1]
self.manager = pickers.entry_manager(
@@ -306,7 +310,7 @@ function Picker:find()
self:set_selection(self.max_results)
end
- local worst_line = self.max_results - self.manager.num_results()
+ local worst_line = self.max_results - self.manager.num_results() + 1
if worst_line <= 0 then
return
end
@@ -448,12 +452,22 @@ function Picker:reset_selection()
end
function Picker:set_selection(row)
+ -- TODO: Loop around behavior?
+ -- TODO: Scrolling past max results
if row > self.max_results then
row = self.max_results
elseif row < 1 then
row = 1
end
+ -- TODO: Move max results and row and entry management into an overridable funciton.
+ -- I have this same thing copied all over the place (and it's not good).
+ -- Particularly if we're going to do something like make it possible to sort
+ -- top to bottom, rather than bottom to top.
+ if row < (self.max_results - self.manager:num_results() + 1) then
+ return
+ end
+
local entry = self.manager:get_entry(self.max_results - row + 1)
local status = state.get_status(self.prompt_bufnr)
local results_bufnr = status.results_bufnr