feat/hack: Add builtin.builtin

This commit is contained in:
TJ DeVries
2020-09-01 22:27:50 -04:00
parent c11a661362
commit 39096492ab
4 changed files with 47 additions and 10 deletions

View File

@@ -152,7 +152,7 @@ builtin.oldfiles = function(opts)
finder = finders.new_table(vim.tbl_filter(function(val) finder = finders.new_table(vim.tbl_filter(function(val)
return 0 ~= vim.fn.filereadable(val) return 0 ~= vim.fn.filereadable(val)
end, vim.v.oldfiles)), end, vim.v.oldfiles)),
sorter = sorters.get_norcalli_sorter(), sorter = sorters.get_fuzzy_file(),
previewer = previewers.cat, previewer = previewers.cat,
}):find() }):find()
end end
@@ -178,4 +178,34 @@ builtin.command_history = function(opts)
}):find() }):find()
end end
-- TODO: What the heck should we do for accepting this.
-- vim.fn.setreg("+", "nnoremap $TODO :lua require('telescope.builtin').<whatever>()<CR>")
-- TODO: Can we just do the names instead?
builtin.builtin = function(opts)
local objs = {}
for k, v in pairs(builtin) do
local debug_info = debug.getinfo(v)
table.insert(objs, {
vimgrep_str = k,
filename = string.sub(debug_info.source, 2),
lnum = debug_info.linedefined,
col = 0,
start = debug_info.linedefined,
finish = debug_info.lastlinedefined,
})
end
local entries = utils.quickfix_items_to_entries(objs)
pickers.new(opts, {
prompt = 'Telescope Builtin',
finder = finders.new_table(entries),
previewer = previewers.qflist,
sorter = sorters.get_norcalli_sorter(),
}):find()
end
return builtin return builtin

View File

@@ -193,7 +193,7 @@ previewers.qflist = previewers.new {
setup = function() setup = function()
local command_string = "cat %s" local command_string = "cat %s"
if vim.fn.executable("bat") then if vim.fn.executable("bat") then
command_string = "bat %s --highlight-line %s -r %s:%s" command_string = "bat %s --highlight-line %s -r %s:%s" .. bat_options
end end
return { return {
@@ -209,9 +209,15 @@ previewers.qflist = previewers.new {
local filename = entry.value.filename local filename = entry.value.filename
local lnum = entry.value.lnum local lnum = entry.value.lnum
local context = math.floor(height / 2) local start, finish
local start = math.max(0, lnum - context) if entry.start and entry.finish then
local finish = lnum + context start = entry.start
finish = entry.finish
else
local context = math.floor(height / 2)
start = math.max(0, lnum - context)
finish = lnum + context
end
vim.api.nvim_win_set_buf(status.preview_win, bufnr) vim.api.nvim_win_set_buf(status.preview_win, bufnr)

View File

@@ -179,15 +179,13 @@ sorters.get_fuzzy_file = function(opts)
tail_modifier = 2 tail_modifier = 2
end end
-- TODO: Copied from ashkan.
local denominator = ( local denominator = (
(10 * match_count / #prompt_lower_ngrams) (10 * match_count / #prompt_lower_ngrams)
-- biases for shorter strings -- biases for shorter strings
-- TODO(ashkan): this can bias towards repeated finds of the same
-- subpattern with overlapping_ngrams
+ 3 * match_count * ngram_len / #line + 3 * match_count * ngram_len / #line
+ consecutive_matches + consecutive_matches
+ N / (contains_string or (2 * #line)) + N / (contains_string or (2 * #line))
-- + 30/(c1 or 2*N) -- + 30/(c1 or 2*N)
-- TODO: It might be possible that this too strongly correlates, -- TODO: It might be possible that this too strongly correlates,

View File

@@ -51,9 +51,9 @@ utils.quickfix_items_to_entries = function(locations)
local results = {} local results = {}
for _, entry in ipairs(locations) do for _, entry in ipairs(locations) do
local vimgrep_str = string.format( local vimgrep_str = entry.vimgrep_str or string.format(
"%s:%s:%s: %s", "%s:%s:%s: %s",
vim.fn.fnamemodify(entry.filename, ":."), vim.fn.fnamemodify(entry.display_filename or entry.filename, ":."),
entry.lnum, entry.lnum,
entry.col, entry.col,
entry.text entry.text
@@ -64,6 +64,9 @@ utils.quickfix_items_to_entries = function(locations)
value = entry, value = entry,
ordinal = vimgrep_str, ordinal = vimgrep_str,
display = vimgrep_str, display = vimgrep_str,
start = entry.start,
finish = entry.finish,
}) })
end end