feat/hack: Add builtin.builtin
This commit is contained in:
@@ -152,7 +152,7 @@ builtin.oldfiles = function(opts)
|
||||
finder = finders.new_table(vim.tbl_filter(function(val)
|
||||
return 0 ~= vim.fn.filereadable(val)
|
||||
end, vim.v.oldfiles)),
|
||||
sorter = sorters.get_norcalli_sorter(),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
previewer = previewers.cat,
|
||||
}):find()
|
||||
end
|
||||
@@ -178,4 +178,34 @@ builtin.command_history = function(opts)
|
||||
}):find()
|
||||
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
|
||||
|
||||
@@ -193,7 +193,7 @@ previewers.qflist = previewers.new {
|
||||
setup = function()
|
||||
local command_string = "cat %s"
|
||||
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
|
||||
|
||||
return {
|
||||
@@ -209,9 +209,15 @@ previewers.qflist = previewers.new {
|
||||
local filename = entry.value.filename
|
||||
local lnum = entry.value.lnum
|
||||
|
||||
local context = math.floor(height / 2)
|
||||
local start = math.max(0, lnum - context)
|
||||
local finish = lnum + context
|
||||
local start, finish
|
||||
if entry.start and entry.finish then
|
||||
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)
|
||||
|
||||
|
||||
@@ -179,15 +179,13 @@ sorters.get_fuzzy_file = function(opts)
|
||||
tail_modifier = 2
|
||||
end
|
||||
|
||||
-- TODO: Copied from ashkan.
|
||||
local denominator = (
|
||||
(10 * match_count / #prompt_lower_ngrams)
|
||||
-- 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
|
||||
+ consecutive_matches
|
||||
+ N / (contains_string or (2 * #line))
|
||||
|
||||
-- + 30/(c1 or 2*N)
|
||||
|
||||
-- TODO: It might be possible that this too strongly correlates,
|
||||
|
||||
@@ -51,9 +51,9 @@ utils.quickfix_items_to_entries = function(locations)
|
||||
local results = {}
|
||||
|
||||
for _, entry in ipairs(locations) do
|
||||
local vimgrep_str = string.format(
|
||||
local vimgrep_str = entry.vimgrep_str or string.format(
|
||||
"%s:%s:%s: %s",
|
||||
vim.fn.fnamemodify(entry.filename, ":."),
|
||||
vim.fn.fnamemodify(entry.display_filename or entry.filename, ":."),
|
||||
entry.lnum,
|
||||
entry.col,
|
||||
entry.text
|
||||
@@ -64,6 +64,9 @@ utils.quickfix_items_to_entries = function(locations)
|
||||
value = entry,
|
||||
ordinal = vimgrep_str,
|
||||
display = vimgrep_str,
|
||||
|
||||
start = entry.start,
|
||||
finish = entry.finish,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user