summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2020-12-09 21:46:41 +0100
committerGitHub <noreply@github.com>2020-12-09 15:46:41 -0500
commit141dc6d55e4f53ee9527adc164a0d39725394bfd (patch)
tree335457a78d554327a7c9e550118c84a7c283a059 /lua
parentc276db06e2981416995450a4198cef4b87170f6f (diff)
ci: Add luacheck ci job (#317)
* Add luacheck ci job * Fix most of the linting issues * fixup: lint Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/_compat.lua15
-rw-r--r--lua/telescope/_private/NGRam.lua109
-rw-r--r--lua/telescope/actions/init.lua2
-rw-r--r--lua/telescope/actions/mt.lua3
-rw-r--r--lua/telescope/builtin/files.lua3
-rw-r--r--lua/telescope/builtin/internal.lua23
-rw-r--r--lua/telescope/builtin/lsp.lua1
-rw-r--r--lua/telescope/config.lua8
-rw-r--r--lua/telescope/debounce.lua4
-rw-r--r--lua/telescope/entry_manager.lua2
-rw-r--r--lua/telescope/finders.lua4
-rw-r--r--lua/telescope/make_entry.lua48
-rw-r--r--lua/telescope/path.lua17
-rw-r--r--lua/telescope/pickers.lua31
-rw-r--r--lua/telescope/pickers/entry_display.lua48
-rw-r--r--lua/telescope/pickers/layout_strategies.lua2
-rw-r--r--lua/telescope/previewers.lua37
-rw-r--r--lua/telescope/themes.lua2
-rw-r--r--lua/telescope/utils.lua6
-rw-r--r--lua/tests/automated/telescope_spec.lua89
20 files changed, 99 insertions, 355 deletions
diff --git a/lua/telescope/_compat.lua b/lua/telescope/_compat.lua
index 3d280ef..6253074 100644
--- a/lua/telescope/_compat.lua
+++ b/lua/telescope/_compat.lua
@@ -1,4 +1,3 @@
-
vim.deepcopy = (function()
local function _id(v)
return v
@@ -55,17 +54,3 @@ vim.deepcopy = (function()
end
end
end)()
-
-
-
-table.clear = table.clear or function(t)
- for k in pairs (t) do
- t[k] = nil
- end
-end
-
-table.pop = table.pop or function(t, k)
- local val = t[k]
- t[k] = nil
- return val
-end
diff --git a/lua/telescope/_private/NGRam.lua b/lua/telescope/_private/NGRam.lua
deleted file mode 100644
index 15006c6..0000000
--- a/lua/telescope/_private/NGRam.lua
+++ /dev/null
@@ -1,109 +0,0 @@
-local NGram = {}
-NGram.__index = NGram
-
-function NGram:new(opts)
- -- TODO: Add padding
- opts = opts or {}
- return setmetatable({
- N = opts.N or 2,
- split = opts.split or "/",
- _depth = 5,
- _grams = setmetatable({}, utils.default_table_mt)
- }, self)
-end
-
-local min = math.min
-
-function NGram:_split(word)
- local word_len = #word
-
- local result = {}
- for i = 1, word_len - 1 do
- -- for j = i + (self.N - 1), min(i + self._depth - 1, word_len) do
- -- table.insert(result, string.sub(word, i, j))
- -- end
- table.insert(result, string.sub(word, i, i + self.N - 1))
- end
-
- return result
-end
-
--- local function pairsByKeys (t, f)
--- local a = {}
--- for n in pairs(t) do table.insert(a, n) end
--- table.sort(a, f)
--- local i = 0 -- iterator variable
--- local iter = function () -- iterator function
--- i = i + 1
--- if a[i] == nil then return nil
--- else return a[i], t[a[i]]
--- end
--- end
--- return iter
--- end
-
-function NGram:add(word)
- local split_word = self:_split(word)
-
- for _, k in ipairs(split_word) do
- local counts = self._grams[k]
- if counts[word] == nil then
- counts[word] = 0
- end
-
- counts[word] = counts[word] + 1
- end
-end
-
-function NGram:_items_sharing_ngrams(query)
- local split_query = self:_split(query)
-
- -- Matched string to number of N-grams shared with the query string.
- local shared = {}
-
- local remaining = {}
-
- for _, ngram in ipairs(split_query) do
- remaining = {}
- for match, count in pairs(self._grams[ngram] or {}) do
- remaining[match] = remaining[match] or count
-
- if remaining[match] > 0 then
- remaining[match] = remaining[match] - 1
- shared[match] = (shared[match] or 0) + 1
- end
- end
- end
-
- return shared
-end
-
-function NGram:search(query, show_values)
- local sharing_ngrams = self:_items_sharing_ngrams(query)
-
- local results = {}
- for name, count in pairs(sharing_ngrams) do
- local allgrams = #query + #name - (2 * self.N) - count + 2
- table.insert(results, {name, count / allgrams})
- end
-
- table.sort(results, function(left, right)
- return left[2] > right[2]
- end)
-
- if not show_values then
- for k, v in ipairs(results) do
- results[k] = v[1]
- end
- end
-
- return results
-end
-
-function NGram:find(query)
- return self:search(query)[1]
-end
-
-function NGram:score(query)
- return (self:search(query, true)[1] or {})[2] or 0
-end
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index e479d1b..aaeffab 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -198,7 +198,7 @@ actions.edit_register = function(prompt_bufnr)
-- update entry in results table
-- TODO: find way to redraw finder content
- for k, v in pairs(picker.finder.results) do
+ for _, v in pairs(picker.finder.results) do
if v == entry then
v.content = updated_value
end
diff --git a/lua/telescope/actions/mt.lua b/lua/telescope/actions/mt.lua
index 909e7bb..5ad14a1 100644
--- a/lua/telescope/actions/mt.lua
+++ b/lua/telescope/actions/mt.lua
@@ -1,5 +1,4 @@
-
-local action_mt = {}
+local action_mt = {}
action_mt.create = function(mod)
local mt = {
diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua
index 15d657a..c1c947f 100644
--- a/lua/telescope/builtin/files.lua
+++ b/lua/telescope/builtin/files.lua
@@ -71,7 +71,8 @@ files.find_files = function(opts)
end
if not find_command then
- print("You need to install either find, fd, or rg. You can also submit a PR to add support for another file finder :)")
+ print("You need to install either find, fd, or rg. " ..
+ "You can also submit a PR to add support for another file finder :)")
return
end
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua
index 42f1893..0b2b626 100644
--- a/lua/telescope/builtin/internal.lua
+++ b/lua/telescope/builtin/internal.lua
@@ -54,8 +54,7 @@ internal.planets = function(opts)
local globbed_files = vim.fn.globpath(base_directory .. '/data/memes/planets/', '*', true, true)
local acceptable_files = {}
for _, v in ipairs(globbed_files) do
- if not show_pluto and v:find("pluto") then
- else
+ if show_pluto or not v:find("pluto") then
table.insert(acceptable_files,vim.fn.fnamemodify(v, ':t'))
end
end
@@ -212,7 +211,8 @@ end
internal.vim_options = function(opts)
-- Load vim options.
- local vim_opts = loadfile(utils.data_directory() .. path.separator .. 'options' .. path.separator .. 'options.lua')().options
+ local vim_opts = loadfile(utils.data_directory() .. path.separator .. 'options' ..
+ path.separator .. 'options.lua')().options
pickers.new(opts, {
prompt = 'options',
@@ -250,12 +250,13 @@ internal.vim_options = function(opts)
-- float_opts.anchor = "sw"
-- float_opts.focusable = false
-- float_opts.style = "minimal"
- -- float_opts.row = vim.api.nvim_get_option("lines") - 2 -- TODO: include `cmdheight` and `laststatus` in this calculation
+ -- float_opts.row = vim.api.nvim_get_option("lines") - 2 -- TODO: inc `cmdheight` and `laststatus` in this calc
-- float_opts.col = 2
-- float_opts.height = 10
-- float_opts.width = string.len(selection.last_set_from)+15
-- local buf = vim.fn.nvim_create_buf(false, true)
- -- vim.fn.nvim_buf_set_lines(buf, 0, 0, false, {"default value: abcdef", "last set from: " .. selection.last_set_from})
+ -- vim.fn.nvim_buf_set_lines(buf, 0, 0, false,
+ -- {"default value: abcdef", "last set from: " .. selection.last_set_from})
-- local status_win = vim.fn.nvim_open_win(buf, false, float_opts)
-- -- vim.api.nvim_win_set_option(status_win, "winblend", 100)
-- vim.api.nvim_win_set_option(status_win, "winhl", "Normal:PmenuSel")
@@ -308,9 +309,7 @@ internal.help_tags = function(opts)
end
internal.man_pages = function(opts)
- local cmd = opts.man_cmd or "apropos --sections=1 ''"
-
- local pages = utils.get_os_command_output(cmd)
+ local pages = utils.get_os_command_output(opts.man_cmd or "apropos --sections=1 ''")
local lines = {}
for s in pages:gmatch("[^\r\n]+") do
@@ -350,7 +349,9 @@ internal.reloader = function(opts)
-- filter out packages we don't want and track the longest package name
opts.column_len = 0
for index, module_name in pairs(package_list) do
- if type(require(module_name)) ~= 'table' or module_name:sub(1,1) == "_" or package.searchpath(module_name, package.path) == nil then
+ if type(require(module_name)) ~= 'table' or
+ module_name:sub(1,1) == "_" or
+ package.searchpath(module_name, package.path) == nil then
table.remove(package_list, index)
elseif #module_name > opts.column_len then
opts.column_len = #module_name
@@ -649,10 +650,10 @@ internal.autocommands = function(opts)
previewer = previewers.autocommands.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
- actions._goto_file_selection:replace(function(_, cmd)
+ actions._goto_file_selection:replace(function(_, vim_cmd)
local selection = actions.get_selected_entry()
actions.close(prompt_bufnr)
- vim.cmd(cmd .. ' ' .. selection.value)
+ vim.cmd(vim_cmd .. ' ' .. selection.value)
end)
return true
diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua
index 4505101..d90052d 100644
--- a/lua/telescope/builtin/lsp.lua
+++ b/lua/telescope/builtin/lsp.lua
@@ -2,7 +2,6 @@ local actions = require('telescope.actions')
local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local pickers = require('telescope.pickers')
-local previewers = require('telescope.previewers')
local utils = require('telescope.utils')
local conf = require('telescope.config').values
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua
index 1f793b8..de01fbd 100644
--- a/lua/telescope/config.lua
+++ b/lua/telescope/config.lua
@@ -52,13 +52,17 @@ function config.set_defaults(defaults)
set("border", {})
set("borderchars", { '─', '│', '─', '│', '╭', '╮', '╯', '╰'})
- set("get_status_text", function(self) return string.format("%s / %s", self.stats.processed - self.stats.filtered, self.stats.processed) end)
+ set("get_status_text", function(self)
+ return string.format("%s / %s", self.stats.processed - self.stats.filtered, self.stats.processed)
+ end)
-- Builtin configuration
-- List that will be executed.
-- Last argument will be the search term (passed in during execution)
- set("vimgrep_arguments", {'rg', '--color=never', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case'})
+ set("vimgrep_arguments",
+ {'rg', '--color=never', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case'}
+ )
set("use_less", true)
set("color_devicons", true)
diff --git a/lua/telescope/debounce.lua b/lua/telescope/debounce.lua
index 329cdc5..d223e41 100644
--- a/lua/telescope/debounce.lua
+++ b/lua/telescope/debounce.lua
@@ -9,8 +9,8 @@ local function td_validate(fn, ms)
fn = { fn, 'f' },
ms = {
ms,
- function(ms)
- return type(ms) == 'number' and ms > 0
+ function(v)
+ return type(v) == 'number' and v > 0
end,
"number > 0",
},
diff --git a/lua/telescope/entry_manager.lua b/lua/telescope/entry_manager.lua
index fea0b7a..ec1ec2b 100644
--- a/lua/telescope/entry_manager.lua
+++ b/lua/telescope/entry_manager.lua
@@ -32,7 +32,7 @@ function EntryManager:new(max_results, set_entry, info)
return #entry_state
end,
- get_ordinal = function(self, index)
+ get_ordinal = function(_, index)
return self:get_entry(index).ordinal
end,
diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua
index 3943a51..f968ad3 100644
--- a/lua/telescope/finders.lua
+++ b/lua/telescope/finders.lua
@@ -133,9 +133,9 @@ function OneshotJobFinder:new(opts)
end
})
- local job_opts = finder:fn_command(prompt)
+ local job_opts = finder:fn_command(_)
if not job_opts then
- error(debug.trackeback("expected `job_opts` from fn_command"))
+ error(debug.traceback("expected `job_opts` from fn_command"))
end
local writer = nil
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index 66cbcd1..aee7f86 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -77,7 +77,7 @@ do
mt_file_entry.cwd = cwd
mt_file_entry.display = function(entry)
- local display, hl_group = entry.value, nil
+ local display, hl_group = entry.value
if shorten_path then
display = utils.path_shorten(display)
end
@@ -168,8 +168,6 @@ do
mt_vimgrep_entry.cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
mt_vimgrep_entry.display = function(entry)
- local display, hl_group = entry.value, nil
-
local display_filename
if shorten_path then
display_filename = utils.path_shorten(entry.filename)
@@ -182,7 +180,7 @@ do
coordinates = string.format("%s:%s:", entry.lnum, entry.col)
end
- display, hl_group = transform_devicons(
+ local display, hl_group = transform_devicons(
entry.filename,
string.format(display_string, display_filename, coordinates, entry.text),
disable_devicons
@@ -215,9 +213,7 @@ do
end
end
-function make_entry.gen_from_git_commits(opts)
- opts = opts or {}
-
+function make_entry.gen_from_git_commits()
return function(entry)
if entry == "" then
return nil
@@ -361,7 +357,7 @@ function make_entry.gen_from_treesitter(opts)
return function(entry)
local ts_utils = require('nvim-treesitter.ts_utils')
- local start_row, start_col, end_row, end_col = ts_utils.get_node_range(entry.node)
+ local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node)
local node_text = ts_utils.get_node_text(entry.node)[1]
return {
valid = true,
@@ -420,9 +416,7 @@ function make_entry.gen_from_packages(opts)
end
end
-function make_entry.gen_from_apropos(opts)
- opts = opts or {}
-
+function make_entry.gen_from_apropos()
return function(line)
local cmd, _, desc = line:match("^(.*)%s+%((.*)%)%s+%-%s(.*)$")
@@ -481,21 +475,21 @@ function make_entry.gen_from_registers(_)
end
function make_entry.gen_from_highlights()
- return function(entry)
- local make_display = function(entry)
- local display = entry.value
- return display, { { { 0, #display }, display } }
- end
+ local make_display = function(entry)
+ local display = entry.value
+ return display, { { { 0, #display }, display } }
+ end
- local preview_command = function(entry, bufnr)
- local hl = entry.value
- vim.api.nvim_buf_set_option(bufnr, 'filetype', 'vim')
- local output = vim.split(vim.fn.execute('hi ' .. hl), '\n')
- local start = string.find(output[2], 'xxx', 1, true)
- vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, output)
- vim.api.nvim_buf_add_highlight(bufnr, -1, hl, 1, start - 1, start + 2)
- end
+ local preview_command = function(entry, bufnr)
+ local hl = entry.value
+ vim.api.nvim_buf_set_option(bufnr, 'filetype', 'vim')
+ local output = vim.split(vim.fn.execute('hi ' .. hl), '\n')
+ local start = string.find(output[2], 'xxx', 1, true)
+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, output)
+ vim.api.nvim_buf_add_highlight(bufnr, -1, hl, 1, start - 1, start + 2)
+ end
+ return function(entry)
return {
value = entry,
display = make_display,
@@ -508,12 +502,6 @@ function make_entry.gen_from_highlights()
end
function make_entry.gen_from_vimoptions()
-
- -- TODO: Can we just remove this from `options.lua`?
- function N_(s)
- return s
- end
-
local process_one_opt = function(o)
local ok, value_origin
diff --git a/lua/telescope/path.lua b/lua/telescope/path.lua
index cdfbc48..0a47a83 100644
--- a/lua/telescope/path.lua
+++ b/lua/telescope/path.lua
@@ -4,7 +4,6 @@ local path = {}
path.separator = package.config:sub(1, 1)
path.home = vim.fn.expand("~")
-
path.make_relative = function(filepath, cwd)
if not cwd or not filepath then return filepath end
@@ -83,14 +82,14 @@ path.read_file = function(filepath)
end
path.read_file_async = function(filepath, callback)
- vim.loop.fs_open(filepath, "r", 438, function(err, fd)
- assert(not err, err)
- vim.loop.fs_fstat(fd, function(err, stat)
- assert(not err, err)
- vim.loop.fs_read(fd, stat.size, 0, function(err, data)
- assert(not err, err)
- vim.loop.fs_close(fd, function(err)
- assert(not err, err)
+ vim.loop.fs_open(filepath, "r", 438, function(err_open, fd)
+ assert(not err_open, err_open)
+ vim.loop.fs_fstat(fd, function(err_fstat, stat)
+ assert(not err_fstat, err_fstat)
+ vim.loop.fs_read(fd, stat.size, 0, function(err_read, data)
+ assert(not err_read, err_read)
+ vim.loop.fs_close(fd, function(err_close)
+ assert(not err_close, err_close)
return callback(data)
end)
end)
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index bf35aa2..77d183b 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -328,7 +328,9 @@ function Picker:find()
a.nvim_win_set_option(results_win, 'winhl', 'Normal:TelescopeNormal')
a.nvim_win_set_option(results_win, 'winblend', self.window.winblend)
local results_border_win = results_opts.border and results_opts.border.win_id
- if results_border_win then vim.api.nvim_win_set_option(results_border_win, 'winhl', 'Normal:TelescopeResultsBorder') end
+ if results_border_win then
+ vim.api.nvim_win_set_option(results_border_win, 'winhl', 'Normal:TelescopeResultsBorder')
+ end
local preview_win, preview_opts, preview_bufnr
@@ -339,8 +341,9 @@ function Picker:find()
a.nvim_win_set_option(preview_win, 'winhl', 'Normal:TelescopeNormal')
a.nvim_win_set_option(preview_win, 'winblend', self.window.winblend)
local preview_border_win = preview_opts and preview_opts.border and preview_opts.border.win_id
- if preview_border_win then vim.api.nvim_win_set_option(preview_border_win, 'winhl', 'Normal:TelescopePreviewBorder') end
-
+ if preview_border_win then
+ vim.api.nvim_win_set_option(preview_border_win, 'winhl', 'Normal:TelescopePreviewBorder')
+ end
end
-- TODO: We need to center this and make it prettier...
@@ -407,7 +410,9 @@ function Picker:find()
return
end
- local prompt = vim.trim(vim.api.nvim_buf_get_lines(prompt_bufnr, first_line, last_line, false)[1]:sub(#prompt_prefix))
+ local prompt = vim.trim(
+ vim.api.nvim_buf_get_lines(prompt_bufnr, first_line, last_line, false)[1]:sub(#prompt_prefix)
+ )
if self.sorter then
self.sorter:_start(prompt)
@@ -448,7 +453,8 @@ function Picker:find()
end
end
- local sort_ok, sort_score = nil, 0
+ local sort_ok
+ local sort_score = 0
if self.sorter then
sort_ok, sort_score = self:_track("_sort_time", pcall, self.sorter.score, self.sorter, prompt, entry)
@@ -472,7 +478,7 @@ function Picker:find()
local process_complete = function()
if self:is_done() then return end
- -- TODO: We should either: always leave one result or make sure we actually clean up the results when nothing matches
+ -- TODO: Either: always leave one result or make sure we actually clean up the results when nothing matches
if selection_strategy == 'row' then
if self._selection_row == nil and self.default_selection_index ~= nil then
self:set_selection(self:get_row(self.default_selection_index))
@@ -758,7 +764,9 @@ function Picker:set_selection(row)
end
local caret = '>'
- local display = string.format('%s %s', caret, (a.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1] or ''):sub(3))
+ local display = string.format('%s %s', caret,
+ (a.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1] or ''):sub(3)
+ )
-- TODO: You should go back and redraw the highlights for this line from the sorter.
-- That's the only smart thing to do.
@@ -835,7 +843,7 @@ function Picker:entry_adder(index, entry, score)
-- This is the two spaces to manage the '> ' stuff.
-- Maybe someday we can use extmarks or floaty text or something to draw this and not insert here.
-- until then, insert two spaces
- local prefix = TELESCOPE_DEBUG and (' ' .. score) or ' '
+ local prefix = ' '
display = prefix .. display
self:_increment("displayed")
@@ -851,7 +859,12 @@ function Picker:entry_adder(index, entry, score)
if set_ok and display_highlights then
-- TODO: This should actually be done during the cursor moving stuff annoyingly.... didn't see this bug yesterday.
for _, hl_block in ipairs(display_highlights) do
- a.nvim_buf_add_highlight(self.results_bufnr, ns_telescope_entry, hl_block[2], row, #prefix + hl_block[1][1], #prefix + hl_block[1][2])
+ a.nvim_buf_add_highlight(self.results_bufnr,
+ ns_telescope_entry,
+ hl_block[2],
+ row,
+ #prefix + hl_block[1][1],
+ #prefix + hl_block[1][2])
end
end
diff --git a/lua/telescope/pickers/entry_display.lua b/lua/telescope/pickers/entry_display.lua
index 2a156b6..a6bf8f9 100644
--- a/lua/telescope/pickers/entry_display.lua
+++ b/lua/telescope/pickers/entry_display.lua
@@ -1,46 +1,5 @@
-local log = require('telescope.log')
-
local entry_display = {}
--- index are used to determine the correct order
--- elements = {
--- [1] = { element, max width }, -- max width should be greater than 0
--- [2] = { a, 0 } -- Use 0 to disable max width
--- [3] = { b, 0 } -- If b is nil, skip this column, should skip column for all rows
--- },
--- separator = " " -- either arbitrary string, when you wanna use the same separator between all elements
--- separator = { " ", ":" } -- or table, where [1] is separator between elements[1] and elements[2], etc
-
--- TODO: Remove this and move ONLY to create method.
-
-local table_format = function(picker, elements, separator)
- -- TODO: Truncate...
- local win_width = vim.api.nvim_win_get_width(picker.results_win)
-
- local output = ""
- for k, v in ipairs(elements) do
- local text = v[1]
- local width = v[2]
- if text ~= nil then
- if k > 1 then
- output = output .. (type(separator) == "table" and separator[k - 1] or separator)
- end
- if width then
- if width == 0 then
- output = output .. string.format("%s", text)
- elseif width < 1 then
- output = output .. string.format("%-" .. math.floor(width * win_width) .. "s", text)
- else
- output = output .. string.format("%-" .. width .."s", text)
- end
- else
- output = output .. text
- end
- end
- end
- return output
-end
-
local function truncate(str, len)
-- TODO: This doesn't handle multi byte chars...
if vim.fn.strdisplaywidth(str) > len then
@@ -94,9 +53,10 @@ entry_display.create = function(configuration)
if configuration.separator_hl then
local width = #configuration.separator or 1
- local hl_start, hl_end = 0, 0
+
+ local hl_start, hl_end
for _, v in ipairs(results) do
- hl_start = hl_end + #tostring(v)
+ hl_start = (hl_end or 0) + #tostring(v)
hl_end = hl_start + width
table.insert(highlights, { { hl_start, hl_end }, configuration.separator_hl })
end
@@ -122,8 +82,6 @@ entry_display.resolve = function(self, entry)
if type(display) == 'string' then
return display, display_highlights
- elseif type(display) == 'table' then
- return table_format(self, display, "│"), display_highlights
end
end
diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua
index adf22ca..334ac2f 100644
--- a/lua/telescope/pickers/layout_strategies.lua
+++ b/lua/telescope/pickers/layout_strategies.lua
@@ -240,7 +240,7 @@ layout_strategies.vertical = function(self, max_columns, max_lines)
-- Height
local height_padding = math.max(
- 1,
+ 1,
resolve.resolve_height(layout_config.height_padding or 3)(self, max_columns, max_lines)
)
local picker_height = max_lines - 2 * height_padding
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua
index a2877e0..d12211f 100644
--- a/lua/telescope/previewers.lua
+++ b/lua/telescope/previewers.lua
@@ -3,7 +3,6 @@ local context_manager = require('plenary.context_manager')
local conf = require('telescope.config').values
local debounce = require('telescope.debounce')
local from_entry = require('telescope.from_entry')
-local log = require('telescope.log')
local utils = require('telescope.utils')
local path = require('telescope.path')
@@ -332,7 +331,7 @@ previewers.new_buffer_previewer = function(opts)
self.state.bufnr = get_bufnr_by_bufname(self, self.state.bufname)
vim.api.nvim_win_set_buf(status.preview_win, self.state.bufnr)
else
- bufnr = vim.api.nvim_create_buf(false, true)
+ local bufnr = vim.api.nvim_create_buf(false, true)
set_bufnr(self, bufnr)
vim.api.nvim_win_set_buf(status.preview_win, bufnr)
@@ -454,16 +453,16 @@ previewers.new_termopen_previewer = function(opts)
}
-- TODO(conni2461): Workaround for neovim/neovim#11751.
- local get_cmd = function(status)
+ local get_cmd = function(st)
local shell = vim.o.shell
if string.find(shell, 'powershell.exe') or string.find(shell, 'cmd.exe') then
- return opts.get_command(entry, status)
+ return opts.get_command(entry, st)
else
local env = {}
for k, v in pairs(termopen_env) do
table.insert(env, k .. '=' .. v)
end
- return table.concat(env, ' ') .. ' ' .. table.concat(opts.get_command(entry, status), ' ')
+ return table.concat(env, ' ') .. ' ' .. table.concat(opts.get_command(entry, st), ' ')
end
end
@@ -514,7 +513,8 @@ previewers.git_branch_log = defaulter(function(_)
return previewers.new_termopen_previewer {
get_command = function(entry)
return { 'git', '-p', 'log', '--graph',
- "--pretty=format:" .. add_quotes .. "%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset" .. add_quotes,
+ "--pretty=format:" .. add_quotes .. "%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset"
+ .. add_quotes,
'--abbrev-commit', '--date=relative', entry.value }
end
}
@@ -533,10 +533,10 @@ previewers.cat = defaulter(function(opts)
return previewers.new_termopen_previewer {
get_command = function(entry)
- local path = from_entry.path(entry, true)
- if path == nil or path == '' then return end
+ local p = from_entry.path(entry, true)
+ if p == nil or p == '' then return end
- return maker(path)
+ return maker(p)
end
}
end, {})
@@ -569,9 +569,9 @@ previewers.vim_buffer_cat = defaulter(function(_)
define_preview = function(self, entry, status)
with_preview_window(status, nil, function()
- local path = from_entry.path(entry, true)
- if path == nil or path == '' then return end
- file_maker_async(path, self.state.bufnr, self.state.bufname)
+ local p = from_entry.path(entry, true)
+ if p == nil or p == '' then return end
+ file_maker_async(p, self.state.bufnr, self.state.bufname)
end)
end
}
@@ -598,10 +598,10 @@ previewers.vim_buffer_vimgrep = defaulter(function(_)
define_preview = function(self, entry, status)
with_preview_window(status, nil, function()
local lnum = entry.lnum or 0
- local path = from_entry.path(entry, true)
- if path == nil or path == '' then return end
+ local p = from_entry.path(entry, true)
+ if p == nil or p == '' then return end
- file_maker_sync(path, self.state.bufnr, self.state.bufname)
+ file_maker_sync(p, self.state.bufnr, self.state.bufname)
if lnum ~= 0 then
if self.state.last_set_bufnr then
@@ -739,15 +739,14 @@ previewers.help = defaulter(function(_)
local escaped = vim.fn.escape(entry.value, special_chars)
local tags = {}
- local find_rtp_file = function(path, count)
- return vim.fn.findfile(path, vim.o.runtimepath, count)
+ local find_rtp_file = function(p, count)
+ return vim.fn.findfile(p, vim.o.runtimepath, count)
end
- local matches = {}
for _,file in pairs(find_rtp_file('doc/tags', -1)) do
local f = assert(io.open(file, "rb"))
for line in f:lines() do
- matches = {}
+ local matches = {}
for match in (line..delim):gmatch("(.-)" .. delim) do
table.insert(matches, match)
diff --git a/lua/telescope/themes.lua b/lua/telescope/themes.lua
index 809b853..eba3d11 100644
--- a/lua/telescope/themes.lua
+++ b/lua/telescope/themes.lua
@@ -17,7 +17,7 @@ function themes.get_dropdown(opts)
layout_strategy = "center",
results_title = false,
preview_title = "Preview",
- preview_cutoff = 1, -- Preview should always show (unless previewer = false)
+ preview_cutoff = 1, -- Preview should always show (unless previewer = false)
width = 80,
results_height = 15,
borderchars = {
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua
index 81f4408..e1ef7f3 100644
--- a/lua/telescope/utils.lua
+++ b/lua/telescope/utils.lua
@@ -79,10 +79,6 @@ utils.quickfix_items_to_entries = function(locations)
return results
end
-utils.new_ngram = function()
- return require("telescope._private.NGram"):new()
-end
-
-- TODO: Figure out how to do this... could include in plenary :)
-- NOTE: Don't use this yet. It will segfault sometimes.
--
@@ -142,7 +138,7 @@ function utils.buf_delete(bufnr)
if bufnr == nil then return end
-- Suppress the buffer deleted message for those with &report<2
- start_report = vim.o.report
+ local start_report = vim.o.report
if start_report < 2 then vim.o.report = 2 end
if vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr) then
diff --git a/lua/tests/automated/telescope_spec.lua b/lua/tests/automated/telescope_spec.lua
index 933cfc5..dd437df 100644
--- a/lua/tests/automated/telescope_spec.lua
+++ b/lua/tests/automated/telescope_spec.lua
@@ -115,95 +115,6 @@ describe('Picker', function()
assert.are.same(1, counts_executed)
end)
end)
-
- -- describe('ngrams', function()
- -- it('should capture intself in the ngram', function()
- -- local n = utils.new_ngram()
-
- -- n:add("hi")
- -- assert.are.same(n._grams.hi, {hi = 1})
- -- end)
-
- -- it('should have repeated strings count more than once', function()
- -- local n = utils.new_ngram()
-
- -- n:add("llll")
- -- assert.are.same(n._grams.ll, {llll = 3})
- -- end)
-
- -- describe('_items_sharing_ngrams', function()
- -- -- it('should be able to find similar strings', function()
- -- -- end)
- -- local n
- -- before_each(function()
- -- n = utils.new_ngram()
-
- -- n:add("SPAM")
- -- n:add("SPAN")
- -- n:add("EG")
- -- end)
-
- -- it('should find items at the start', function()
- -- assert.are.same({ SPAM = 1, SPAN = 1 }, n:_items_sharing_ngrams("SP"))
- -- end)
-
- -- it('should find items at the end', function()
- -- assert.are.same({ SPAM = 1, }, n:_items_sharing_ngrams("AM"))
- -- end)
-
- -- it('should find items at the end', function()
- -- assert.are.same({ SPAM = 2, SPAN = 1}, n:_items_sharing_ngrams("PAM"))
- -- end)
- -- end)
-
- -- describe('search', function()
- -- describe('for simple strings', function()
- -- local n
- -- before_each(function()
- -- n = utils.new_ngram()
-
- -- n:add("SPAM")
- -- n:add("SPAN")
- -- n:add("EG")
- -- end)
-
- -- it('should sort for equal cases', function()
- -- assert.are.same({ "SPAM", "SPAN" }, n:search("SPAM"))
- -- end)
-
- -- it('should sort for obvious cases', function()
- -- assert.are.same({ "SPAM", "SPAN" }, n:search("PAM"))
- -- end)
- -- end)
-
- -- describe('for file paths', function()
- -- local n
- -- before_each(function()
- -- n = utils.new_ngram()
-
- -- n:add("sho/rt")
- -- n:add("telescope/init.lua")
- -- n:add("telescope/utils.lua")
- -- n:add("telescope/pickers.lua")
- -- n:add("a/random/file/pickers.lua")
- -- n:add("microscope/init.lua")
- -- end)
-
- -- it("should find exact match", function()
- -- assert.are.same(n:find("telescope/init.lua"), "telescope/init.lua")
- -- assert.are.same(n:score("telescope/init.lua"), 1)
- -- end)
-
- -- it("should find unique match", function()
- -- assert.are.same(n:find("micro"), "microscope/init.lua")
- -- end)
-
- -- it("should find some match", function()
- -- assert.are.same(n:find("telini"), "telescope/init.lua")
- -- end)
- -- end)
- -- end)
- -- end)
end)
describe('Sorters', function()