summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-09-11 00:14:37 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-09-11 00:14:40 -0400
commit382c491380719e4667a74c7ccc58222b290f7e67 (patch)
tree5cb9fcfc49f0821a1d8273233ade930efbfe6084 /lua
parentfe387d10db66dc9b33388f05fadabbdc9b31c28b (diff)
feat: Add some more layout options
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/config.lua3
-rw-r--r--lua/telescope/finders.lua26
-rw-r--r--lua/telescope/init.lua34
-rw-r--r--lua/telescope/make_entry.lua12
-rw-r--r--lua/telescope/pickers.lua25
-rw-r--r--lua/telescope/pickers/layout_strategies.lua1
-rw-r--r--lua/tests/manual/large_search.lua37
7 files changed, 115 insertions, 23 deletions
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua
index 8704fe2..efd2ea6 100644
--- a/lua/telescope/config.lua
+++ b/lua/telescope/config.lua
@@ -30,12 +30,13 @@ function config.set_defaults(defaults)
config.values[name] = get(name, default_val)
end
+ set("sorting_strategy", "descending")
set("selection_strategy", "reset")
set("layout_strategy", "horizontal")
set("width", 0.75)
set("winblend", 0)
- set("prompt_position", "top")
+ set("prompt_position", "bottom")
set("preview_cutoff", 120)
set("border", {})
diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua
index d3e2f61..07a013c 100644
--- a/lua/telescope/finders.lua
+++ b/lua/telescope/finders.lua
@@ -2,7 +2,6 @@ local Job = require('plenary.job')
local make_entry = require('telescope.make_entry')
local log = require('telescope.log')
-local utils = require('telescope.utils')
local finders = {}
@@ -64,7 +63,12 @@ function JobFinder:new(opts)
end
function JobFinder:_find(prompt, process_result, process_complete)
+ START = vim.loop.hrtime()
+ PERF()
+ PERF('starting...')
+
if self.job and not self.job.is_shutdown then
+ PERF('...had to shutdown')
self.job:shutdown()
end
@@ -76,25 +80,22 @@ function JobFinder:_find(prompt, process_result, process_complete)
end
process_complete()
- return
- end
+ PERF('Num Lines: ', self._cached_lines)
+ PERF('...finished static')
- if self.static then
- self._cached_lines = {}
+ COMPLETED = true
+ return
end
self.done = false
+ self._cached_lines = {}
- -- TODO: Should consider ways to allow "transformers" to be run here.
- -- So that a finder can choose to "transform" the text into something much more easily usable.
local on_output = function(_, line, _)
if not line then
return
end
- if vim.trim(line) ~= "" then
- line = line:gsub("\n", "")
-
+ if line ~= "" then
if self.entry_maker then
line = self.entry_maker(line)
end
@@ -129,6 +130,8 @@ function JobFinder:_find(prompt, process_result, process_complete)
self.done = true
process_complete()
+
+ PERF('done')
end,
}
@@ -228,9 +231,10 @@ finders.new_oneshot_job = function(command_list, opts)
return JobFinder:new {
static = true,
- entry_maker = opts.entry_maker or make_entry.gen_from_string,
+ entry_maker = opts.entry_maker or make_entry.gen_from_string(),
cwd = opts.cwd,
+ maximum_results = opts.maximum_results,
fn_command = function()
return {
diff --git a/lua/telescope/init.lua b/lua/telescope/init.lua
index 38c27ff..c0a4e37 100644
--- a/lua/telescope/init.lua
+++ b/lua/telescope/init.lua
@@ -47,4 +47,38 @@ function telescope.setup(opts)
require('telescope.config').set_defaults(opts.defaults)
end
+-- Until I have better profiling stuff, this will have to do.
+PERF = function(...) end
+PERF_DEBUG = PERF_DEBUG or nil
+START = nil
+
+if PERF_DEBUG then
+ PERF = function(...)
+ local new_time = (vim.loop.hrtime() - START) / 1E9
+ if select('#', ...) == 0 then
+ vim.schedule(function()
+ vim.api.nvim_buf_set_lines(PERF_DEBUG, -1, -1, false, { '' })
+ end)
+ return
+ end
+
+ local to_insert = ''
+ if START then
+ to_insert = tostring(new_time) .. ' | '
+ end
+
+ for _, v in ipairs({...}) do
+ if type(v) == 'table' then
+ to_insert = to_insert .. tostring(#v) .. ' | '
+ else
+ to_insert = to_insert .. tostring(v) .. ' | '
+ end
+ end
+
+ vim.schedule(function()
+ vim.api.nvim_buf_set_lines(PERF_DEBUG, -1, -1, false, { to_insert })
+ end)
+ end
+end
+
return telescope
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index 1b7354f..b595ffc 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -11,12 +11,22 @@ make_entry.types = {
local transform_devicons
if has_devicons then
+ _DeviconStore = _DeviconStore or {}
+
transform_devicons = function(filename, display, opts)
if opts.disable_devicons then
return display
end
- return (devicons.get_icon(filename, string.match(filename, '%a+$')) or ' ') .. ' ' .. display
+ if _DeviconStore[filename] then
+ return _DeviconStore[filename]
+ end
+
+ local icon_display = (devicons.get_icon(filename, string.match(filename, '%a+$')) or ' ') .. ' ' .. display
+
+ _DeviconStore[filename] = icon_display
+
+ return icon_display
end
else
transform_devicons = function(_, display, _)
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 15910d3..146cfa7 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -100,7 +100,7 @@ function Picker:new(opts)
-- mappings = get_default(opts.mappings, default_mappings),
attach_mappings = opts.attach_mappings,
- sorting_strategy = 'ascending',
+ sorting_strategy = get_default(opts.sorting_strategy, config.values.sorting_strategy),
selection_strategy = get_default(opts.selection_strategy, config.values.selection_strategy),
layout_strategy = get_default(opts.layout_strategy, config.values.layout_strategy),
@@ -198,7 +198,6 @@ end
function Picker:get_reset_row()
if self.sorting_strategy == 'ascending' then
- log.info("Setting reset row:", 1)
return 1
else
return self.max_results
@@ -214,7 +213,6 @@ function Picker:clear_extra_rows(results_bufnr)
return
end
- log.info("start", num_results + 1, "end", self.max_results)
vim.api.nvim_buf_set_lines(results_bufnr, num_results + 1, self.max_results, false, {})
else
local worst_line = self:get_row(self.manager:num_results())
@@ -233,7 +231,7 @@ function Picker:can_select_row(row)
if self.sorting_strategy == 'ascending' then
return row <= self.manager:num_results()
else
- return row >= self.manager:num_results()
+ return row <= self.max_results and row >= self.max_results - self.manager:num_results()
end
end
@@ -303,6 +301,10 @@ function Picker:find()
local prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, first_line, last_line, false)[1]
+ local filtered_amount = 0
+ local displayed_amount = 0
+ local displayed_fn_amount = 0
+
self.manager = pickers.entry_manager(
self.max_results,
vim.schedule_wrap(function(index, entry)
@@ -316,6 +318,7 @@ function Picker:find()
local display
if type(entry.display) == 'function' then
+ displayed_fn_amount = displayed_fn_amount + 1
display = entry:display()
elseif type(entry.display) == 'string' then
display = entry.display
@@ -329,6 +332,8 @@ function Picker:find()
-- until then, insert two spaces
display = ' ' .. display
+ displayed_amount = displayed_amount + 1
+
-- log.info("Setting row", row, "with value", entry)
local set_ok = pcall(vim.api.nvim_buf_set_lines, results_bufnr, row, row + 1, false, {display})
@@ -361,6 +366,7 @@ function Picker:find()
end
if sort_score == -1 then
+ filtered_amount = filtered_amount + 1
log.trace("Filtering out result: ", entry)
return
end
@@ -390,6 +396,10 @@ function Picker:find()
end
self:clear_extra_rows(results_bufnr)
+
+ PERF("Filtered Amount ", filtered_amount)
+ PERF("Displayed Amount ", displayed_amount)
+ PERF("Displayed FN Amount", displayed_fn_amount)
end)
local ok, msg = pcall(function()
@@ -535,13 +545,8 @@ function Picker:set_selection(row)
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.
-
- -- TODO: Is this the right logic here?
if not self:can_select_row(row) then
+ log.info("Cannot select row:", row, self.manager:num_results(), self.max_results)
return
end
diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua
index 77cb3ab..6397254 100644
--- a/lua/telescope/pickers/layout_strategies.lua
+++ b/lua/telescope/pickers/layout_strategies.lua
@@ -148,6 +148,7 @@ layout_strategies.vertical = function(self, max_columns, max_lines, prompt_title
end
layout_strategies.flex = function(self, max_columns, max_lines, prompt_title)
+ -- TODO: Make a config option for this that makes sense.
if max_columns < 100 and max_lines > 20 then
return layout_strategies.vertical(self, max_columns, max_lines, prompt_title)
else
diff --git a/lua/tests/manual/large_search.lua b/lua/tests/manual/large_search.lua
new file mode 100644
index 0000000..3ad6b5a
--- /dev/null
+++ b/lua/tests/manual/large_search.lua
@@ -0,0 +1,37 @@
+RELOAD('plenary')
+RELOAD('telescope')
+
+local finders = require('telescope.finders')
+local make_entry = require('telescope.make_entry')
+local previewers = require('telescope.previewers')
+local pickers = require('telescope.pickers')
+local sorters = require('telescope.sorters')
+
+PERF_DEBUG = 182
+vim.api.nvim_buf_set_lines(PERF_DEBUG, 0, -1, false, {})
+
+local cwd = vim.fn.expand("~/build/neovim")
+
+pickers.new {
+ prompt = 'Large search',
+ finder = finders.new_oneshot_job(
+ {"fdfind"},
+ {
+ cwd = cwd,
+ entry_maker = make_entry.gen_from_file {cwd = cwd},
+ -- disable_devicons = true,
+ -- maximum_results = 1000,
+ }
+ ),
+ sorter = sorters.get_fuzzy_file(),
+ previewer = previewers.cat.new{cwd = cwd},
+}:find()
+
+
+COMPLETED = false
+-- vim.wait(3000, function()
+-- vim.cmd [[redraw!]]
+-- return COMPLETED
+-- end, 100)
+-- vim.cmd [[bd!]]
+-- vim.cmd [[stopinsert]]