diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2021-07-23 17:42:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-23 11:42:37 -0400 |
| commit | 79644ab67731c7ba956c354bf0545282f34e10cc (patch) | |
| tree | e65dbf73b3442ab1aa9fc59fc56a35b4c9edf1e0 /lua/telescope/pickers.lua | |
| parent | 664690029fdb302bee8d3f27a458383e8477add7 (diff) | |
chore: use stylua for formatting (#1040)
* chore: stylua job and config
* reformat with stylua
Diffstat (limited to 'lua/telescope/pickers.lua')
| -rw-r--r-- | lua/telescope/pickers.lua | 338 |
1 files changed, 175 insertions, 163 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 00b7446..65f8cfe 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -1,38 +1,38 @@ local a = vim.api -local popup = require('popup') +local popup = require "popup" -local async_lib = require('plenary.async_lib') +local async_lib = require "plenary.async_lib" local async_util = async_lib.util local async = async_lib.async local await = async_lib.await local channel = async_util.channel -require('telescope') +require "telescope" -local actions = require('telescope.actions') -local action_set = require('telescope.actions.set') -local config = require('telescope.config') -local debounce = require('telescope.debounce') -local deprecated = require('telescope.deprecated') -local log = require('telescope.log') -local mappings = require('telescope.mappings') -local state = require('telescope.state') -local utils = require('telescope.utils') +local actions = require "telescope.actions" +local action_set = require "telescope.actions.set" +local config = require "telescope.config" +local debounce = require "telescope.debounce" +local deprecated = require "telescope.deprecated" +local log = require "telescope.log" +local mappings = require "telescope.mappings" +local state = require "telescope.state" +local utils = require "telescope.utils" -local entry_display = require('telescope.pickers.entry_display') -local p_highlighter = require('telescope.pickers.highlights') -local p_scroller = require('telescope.pickers.scroller') -local p_window = require('telescope.pickers.window') +local entry_display = require "telescope.pickers.entry_display" +local p_highlighter = require "telescope.pickers.highlights" +local p_scroller = require "telescope.pickers.scroller" +local p_window = require "telescope.pickers.window" -local EntryManager = require('telescope.entry_manager') -local MultiSelect = require('telescope.pickers.multi') +local EntryManager = require "telescope.entry_manager" +local MultiSelect = require "telescope.pickers.multi" local get_default = utils.get_default -local ns_telescope_matching = a.nvim_create_namespace('telescope_matching') -local ns_telescope_prompt = a.nvim_create_namespace('telescope_prompt') -local ns_telescope_prompt_prefix = a.nvim_create_namespace('telescope_prompt_prefix') +local ns_telescope_matching = a.nvim_create_namespace "telescope_matching" +local ns_telescope_prompt = a.nvim_create_namespace "telescope_prompt" +local ns_telescope_prompt_prefix = a.nvim_create_namespace "telescope_prompt_prefix" local pickers = {} @@ -48,7 +48,7 @@ function Picker:new(opts) opts = opts or {} if opts.layout_strategy and opts.get_window_options then - error("layout_strategy and get_window_options are not compatible keys") + error "layout_strategy and get_window_options are not compatible keys" end -- Reset actions for any replaced / enhanced actions. @@ -76,7 +76,7 @@ function Picker:new(opts) _on_input_filter_cb = opts.on_input_filter_cb or function() end, finder = opts.finder, - sorter = opts.sorter or require('telescope.sorters').empty(), + sorter = opts.sorter or require("telescope.sorters").empty(), all_previewers = opts.previewer, current_previewer_index = 1, @@ -141,7 +141,7 @@ end ---@param index number: The row being displayed ---@return number The row for the picker to display in function Picker:get_row(index) - if self.sorting_strategy == 'ascending' then + if self.sorting_strategy == "ascending" then return index - 1 else return self.max_results - index @@ -153,7 +153,7 @@ end ---@param row number: The row being displayed ---@return number The index in line_manager function Picker:get_index(row) - if self.sorting_strategy == 'ascending' then + if self.sorting_strategy == "ascending" then return row + 1 else return self.max_results - row @@ -161,7 +161,7 @@ function Picker:get_index(row) end function Picker:get_reset_row() - if self.sorting_strategy == 'ascending' then + if self.sorting_strategy == "ascending" then return 0 else return self.max_results - 1 @@ -169,12 +169,14 @@ function Picker:get_reset_row() end function Picker:is_done() - if not self.manager then return true end + if not self.manager then + return true + end end function Picker:clear_extra_rows(results_bufnr) if self:is_done() then - log.trace("Not clearing due to being already complete") + log.trace "Not clearing due to being already complete" return end @@ -184,7 +186,7 @@ function Picker:clear_extra_rows(results_bufnr) end local worst_line, ok, msg - if self.sorting_strategy == 'ascending' then + if self.sorting_strategy == "ascending" then local num_results = self.manager:num_results() worst_line = self.max_results - num_results @@ -231,28 +233,21 @@ function Picker:highlight_one_row(results_bufnr, prompt, display, row) if highlights then for _, hl in ipairs(highlights) do local highlight, start, finish - if type(hl) == 'table' then - highlight = hl.highlight or 'TelescopeMatching' + if type(hl) == "table" then + highlight = hl.highlight or "TelescopeMatching" start = hl.start finish = hl.finish or hl.start - elseif type(hl) == 'number' then - highlight = 'TelescopeMatching' + elseif type(hl) == "number" then + highlight = "TelescopeMatching" start = hl finish = hl else - error('Invalid higlighter fn') + error "Invalid higlighter fn" end - self:_increment('highlights') + self:_increment "highlights" - vim.api.nvim_buf_add_highlight( - results_bufnr, - ns_telescope_matching, - highlight, - row, - start - 1, - finish - ) + vim.api.nvim_buf_add_highlight(results_bufnr, ns_telescope_matching, highlight, row, start - 1, finish) end end @@ -261,7 +256,7 @@ function Picker:highlight_one_row(results_bufnr, prompt, display, row) end function Picker:can_select_row(row) - if self.sorting_strategy == 'ascending' then + if self.sorting_strategy == "ascending" then return row <= self.manager:num_results() else return row >= 0 and row <= self.max_results and row >= self.max_results - self.manager:num_results() @@ -304,47 +299,48 @@ function Picker:find() popup_opts.preview.minheight = popup_opts.preview.height end - local results_win, results_opts = popup.create('', popup_opts.results) + local results_win, results_opts = popup.create("", popup_opts.results) local results_bufnr = a.nvim_win_get_buf(results_win) self.results_bufnr = results_bufnr self.results_win = results_win -- TODO: Should probably always show all the line for results win, so should implement a resize for the windows - a.nvim_win_set_option(results_win, 'wrap', false) - a.nvim_win_set_option(results_win, 'winhl', 'Normal:TelescopeNormal') - a.nvim_win_set_option(results_win, 'winblend', self.window.winblend) + a.nvim_win_set_option(results_win, "wrap", false) + 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') + vim.api.nvim_win_set_option(results_border_win, "winhl", "Normal:TelescopeResultsBorder") end - local preview_win, preview_opts, preview_bufnr if popup_opts.preview then - preview_win, preview_opts = popup.create('', popup_opts.preview) + preview_win, preview_opts = popup.create("", popup_opts.preview) preview_bufnr = a.nvim_win_get_buf(preview_win) - a.nvim_win_set_option(preview_win, 'winhl', 'Normal:TelescopePreviewNormal') - a.nvim_win_set_option(preview_win, 'winblend', self.window.winblend) + a.nvim_win_set_option(preview_win, "winhl", "Normal:TelescopePreviewNormal") + 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') + vim.api.nvim_win_set_option(preview_border_win, "winhl", "Normal:TelescopePreviewBorder") end end -- TODO: We need to center this and make it prettier... - local prompt_win, prompt_opts = popup.create('', popup_opts.prompt) + local prompt_win, prompt_opts = popup.create("", popup_opts.prompt) local prompt_bufnr = a.nvim_win_get_buf(prompt_win) - a.nvim_win_set_option(prompt_win, 'winhl', 'Normal:TelescopeNormal') - a.nvim_win_set_option(prompt_win, 'winblend', self.window.winblend) + a.nvim_win_set_option(prompt_win, "winhl", "Normal:TelescopeNormal") + a.nvim_win_set_option(prompt_win, "winblend", self.window.winblend) local prompt_border_win = prompt_opts.border and prompt_opts.border.win_id - if prompt_border_win then vim.api.nvim_win_set_option(prompt_border_win, 'winhl', 'Normal:TelescopePromptBorder') end + if prompt_border_win then + vim.api.nvim_win_set_option(prompt_border_win, "winhl", "Normal:TelescopePromptBorder") + end -- Prompt prefix local prompt_prefix = self.prompt_prefix - if prompt_prefix ~= '' then - a.nvim_buf_set_option(prompt_bufnr, 'buftype', 'prompt') + if prompt_prefix ~= "" then + a.nvim_buf_set_option(prompt_bufnr, "buftype", "prompt") vim.fn.prompt_setprompt(prompt_bufnr, prompt_prefix) end self.prompt_prefix = prompt_prefix @@ -377,8 +373,12 @@ function Picker:find() return end - if not first_line then first_line = 0 end - if not last_line then last_line = 1 end + if not first_line then + first_line = 0 + end + if not last_line then + last_line = 1 + end if first_line > 0 or last_line > 1 then log.debug("ON_LINES: Bad range", first_line, last_line, self:_get_prompt()) @@ -396,7 +396,9 @@ function Picker:find() self.finder = finder end - if self.sorter then self.sorter:_start(prompt) end + if self.sorter then + self.sorter:_start(prompt) + end -- TODO: Entry manager should have a "bulk" setter. This can prevent a lot of redraws from display self.manager = EntryManager:new(self.max_results, self.entry_adder, self.stats) @@ -428,23 +430,27 @@ function Picker:find() self.closed = true -- TODO: Should we actually do this? - collectgarbage(); collectgarbage() + collectgarbage() + collectgarbage() end, }) - if self.sorter then self.sorter:_init() end + if self.sorter then + self.sorter:_init() + end async_lib.run(main_loop()) status_updater() -- TODO: Use WinLeave as well? local on_buf_leave = string.format( [[ autocmd BufLeave <buffer> ++nested ++once :silent lua require('telescope.pickers').on_close_prompt(%s)]], - prompt_bufnr) + prompt_bufnr + ) - vim.cmd([[augroup PickerInsert]]) - vim.cmd([[ au!]]) - vim.cmd( on_buf_leave) - vim.cmd([[augroup END]]) + vim.cmd [[augroup PickerInsert]] + vim.cmd [[ au!]] + vim.cmd(on_buf_leave) + vim.cmd [[augroup END]] self.prompt_bufnr = prompt_bufnr @@ -452,26 +458,31 @@ function Picker:find() self.preview_border = preview_border local preview_border_win = (preview_border and preview_border.win_id) and preview_border.win_id - state.set_status(prompt_bufnr, setmetatable({ - prompt_bufnr = prompt_bufnr, - prompt_win = prompt_win, - prompt_border_win = prompt_border_win, - - results_bufnr = results_bufnr, - results_win = results_win, - results_border_win = results_border_win, - - preview_bufnr = preview_bufnr, - preview_win = preview_win, - preview_border_win = preview_border_win, - picker = self, - }, { __mode = 'kv' })) + state.set_status( + prompt_bufnr, + setmetatable({ + prompt_bufnr = prompt_bufnr, + prompt_win = prompt_win, + prompt_border_win = prompt_border_win, + + results_bufnr = results_bufnr, + results_win = results_win, + results_border_win = results_border_win, + + preview_bufnr = preview_bufnr, + preview_win = preview_win, + preview_border_win = preview_border_win, + picker = self, + }, { + __mode = "kv", + }) + ) mappings.apply_keymap(prompt_bufnr, self.attach_mappings, config.values.mappings) -- Do filetype last, so that users can register at the last second. - pcall(a.nvim_buf_set_option, prompt_bufnr, 'filetype', 'TelescopePrompt') - pcall(a.nvim_buf_set_option, results_bufnr, 'filetype', 'TelescopeResults') + pcall(a.nvim_buf_set_option, prompt_bufnr, "filetype", "TelescopePrompt") + pcall(a.nvim_buf_set_option, results_bufnr, "filetype", "TelescopeResults") if self.default_text then self:set_prompt(self.default_text) @@ -529,7 +540,9 @@ function Picker:delete_selection(delete_cb) -- Sort in reverse order as removing an entry from the table shifts down the -- other elements to close the hole. - table.sort(selection_index, function(x, y) return x > y end) + table.sort(selection_index, function(x, y) + return x > y + end) for _, index in ipairs(selection_index) do local selection = table.remove(self.finder.results, index) delete_cb(selection) @@ -548,7 +561,7 @@ end function Picker:set_prompt(str) -- TODO(conni2461): As soon as prompt_buffers are fix use this: -- vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, 1, false, { str }) - vim.api.nvim_feedkeys(str, 'n', false) + vim.api.nvim_feedkeys(str, "n", false) end function Picker.close_windows(status) @@ -566,9 +579,7 @@ function Picker.close_windows(status) end local bufnr = vim.api.nvim_win_get_buf(win_id) - if bdelete - and vim.api.nvim_buf_is_valid(bufnr) - and not vim.api.nvim_buf_get_option(bufnr, 'buflisted') then + if bdelete and vim.api.nvim_buf_is_valid(bufnr) and not vim.api.nvim_buf_get_option(bufnr, "buflisted") then vim.cmd(string.format("silent! bdelete! %s", bufnr)) end @@ -650,10 +661,11 @@ end function Picker:_reset_prefix_color(hl_group) self._current_prefix_hl_group = hl_group or nil - if self.prompt_prefix ~= '' then - vim.api.nvim_buf_add_highlight(self.prompt_bufnr, + if self.prompt_prefix ~= "" then + vim.api.nvim_buf_add_highlight( + self.prompt_bufnr, ns_telescope_prompt_prefix, - self._current_prefix_hl_group or 'TelescopePromptPrefix', + self._current_prefix_hl_group or "TelescopePromptPrefix", 0, 0, #self.prompt_prefix @@ -665,26 +677,28 @@ end -- TODO(conni2461): Next two functions only work together otherwise color doesn't work -- Probably a issue with prompt buffers function Picker:change_prompt_prefix(new_prefix, hl_group) - if not new_prefix then return end + if not new_prefix then + return + end - if new_prefix ~= '' then + if new_prefix ~= "" then vim.fn.prompt_setprompt(self.prompt_bufnr, new_prefix) else vim.api.nvim_buf_set_text(self.prompt_bufnr, 0, 0, 0, #self.prompt_prefix, {}) - vim.api.nvim_buf_set_option(self.prompt_bufnr, 'buftype', '') + vim.api.nvim_buf_set_option(self.prompt_bufnr, "buftype", "") end self.prompt_prefix = new_prefix self:_reset_prefix_color(hl_group) end function Picker:reset_prompt(text) - local prompt_text = self.prompt_prefix .. (text or '') + local prompt_text = self.prompt_prefix .. (text or "") vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { prompt_text }) self:_reset_prefix_color(self._current_prefix_hl_group) if text then - vim.api.nvim_win_set_cursor(self.prompt_win, {1, #prompt_text}) + vim.api.nvim_win_set_cursor(self.prompt_win, { 1, #prompt_text }) end end @@ -693,10 +707,14 @@ end function Picker:refresh(finder, opts) opts = opts or {} if opts.new_prefix then - local handle = type(opts.new_prefix) == 'table' and unpack or function(x) return x end + local handle = type(opts.new_prefix) == "table" and unpack or function(x) + return x + end self:change_prompt_prefix(handle(opts.new_prefix)) end - if opts.reset_prompt then self:reset_prompt() end + if opts.reset_prompt then + self:reset_prompt() + end if finder then self.finder:close() @@ -708,7 +726,9 @@ function Picker:refresh(finder, opts) end function Picker:set_selection(row) - if not self.manager then return end + if not self.manager then + return + end row = self.scroller(self.max_results, self.manager:num_results(), row) @@ -729,11 +749,9 @@ function Picker:set_selection(row) end if row > a.nvim_buf_line_count(results_bufnr) then - log.debug(string.format( - "Should not be possible to get row this large %s %s", - row, - a.nvim_buf_line_count(results_bufnr) - )) + log.debug( + string.format("Should not be possible to get row this large %s %s", row, a.nvim_buf_line_count(results_bufnr)) + ) return end @@ -741,7 +759,9 @@ function Picker:set_selection(row) local entry = self.manager:get_entry(self:get_index(row)) state.set_global_key("selected_entry", entry) - if not entry then return end + if not entry then + return + end -- TODO: Probably should figure out what the rows are that made this happen... -- Probably something with setting a row that's too high for this? @@ -754,14 +774,13 @@ function Picker:set_selection(row) -- Only change the first couple characters, nvim_buf_set_text leaves the existing highlights a.nvim_buf_set_text( results_bufnr, - self._selection_row, 0, - self._selection_row, #self.selection_caret, - { self.entry_prefix } - ) - self.highlighter:hi_multiselect( self._selection_row, - self:is_multi_selected(self._selection_entry) + 0, + self._selection_row, + #self.selection_caret, + { self.entry_prefix } ) + self.highlighter:hi_multiselect(self._selection_row, self:is_multi_selected(self._selection_entry)) -- local display = a.nvim_buf_get_lines(results_bufnr, old_row, old_row + 1, false)[1] -- display = ' ' .. display @@ -781,10 +800,10 @@ function Picker:set_selection(row) -- TODO: You should go back and redraw the highlights for this line from the sorter. -- That's the only smart thing to do. if not a.nvim_buf_is_valid(results_bufnr) then - log.debug("Invalid buf somehow...") + log.debug "Invalid buf somehow..." return end - a.nvim_buf_set_lines(results_bufnr, row, row + 1, false, {display}) + a.nvim_buf_set_lines(results_bufnr, row, row + 1, false, { display }) -- don't highlight the ' ' at the end of caret self.highlighter:hi_selection(row, caret:sub(1, -2)) @@ -813,12 +832,9 @@ end function Picker:refresh_previewer() local status = state.get_status(self.prompt_bufnr) if status.preview_win and self.previewer then - self:_increment("previewed") + self:_increment "previewed" - self.previewer:preview( - self._selection_entry, - status - ) + self.previewer:preview(self._selection_entry, status) if self.preview_border then if config.values.dynamic_preview_title == true then self.preview_border:change_title(self.previewer:dynamic_title(self._selection_entry)) @@ -831,7 +847,9 @@ end function Picker:cycle_previewers(next) local size = #self.all_previewers - if size == 1 then return end + if size == 1 then + return + end self.current_previewer_index = self.current_previewer_index + next if self.current_previewer_index > size then @@ -845,7 +863,9 @@ function Picker:cycle_previewers(next) end function Picker:entry_adder(index, entry, _, insert) - if not entry then return end + if not entry then + return + end local row = self:get_row(index) @@ -867,13 +887,13 @@ function Picker:entry_adder(index, entry, _, insert) local prefix = self.entry_prefix display = prefix .. display - self:_increment("displayed") + self:_increment "displayed" -- TODO: Don't need to schedule this if we schedule the adder. local offset = insert and 0 or 1 vim.schedule(function() if not vim.api.nvim_buf_is_valid(self.results_bufnr) then - log.debug("ON_ENTRY: Invalid buffer") + log.debug "ON_ENTRY: Invalid buffer" return end @@ -885,12 +905,12 @@ function Picker:entry_adder(index, entry, _, insert) end if insert then - if self.sorting_strategy == 'descending' then + if self.sorting_strategy == "descending" then vim.api.nvim_buf_set_lines(self.results_bufnr, 0, 1, false, {}) end end - local set_ok, msg = pcall(vim.api.nvim_buf_set_lines, self.results_bufnr, row, row + offset, false, {display}) + local set_ok, msg = pcall(vim.api.nvim_buf_set_lines, self.results_bufnr, row, row + offset, false, { display }) if set_ok and display_highlights then self.highlighter:hi_display(row, prefix, display_highlights) end @@ -901,14 +921,13 @@ function Picker:entry_adder(index, entry, _, insert) -- This pretty much only fails when people leave newlines in their results. -- So we'll clean it up for them if it fails. - if not set_ok and display:find("\n") then + if not set_ok and display:find "\n" then display = display:gsub("\n", " | ") - vim.api.nvim_buf_set_lines(self.results_bufnr, row, row + 1, false, {display}) + vim.api.nvim_buf_set_lines(self.results_bufnr, row, row + 1, false, { display }) end end) end - function Picker:_reset_track() self.stats.processed = 0 self.stats.displayed = 0 @@ -945,7 +964,6 @@ function Picker:_decrement(key) self.stats[key] = (self.stats[key] or 0) - 1 end - -- TODO: Decide how much we want to use this. -- Would allow for better debugging of items. function Picker:register_completion_callback(cb) @@ -967,7 +985,9 @@ end function Picker:get_status_updater(prompt_win, prompt_bufnr) return function() local text = self:get_status_text() - if self.closed or not vim.api.nvim_buf_is_valid(prompt_bufnr) then return end + if self.closed or not vim.api.nvim_buf_is_valid(prompt_bufnr) then + return + end local current_prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, 0, 1, false)[1] if not current_prompt then return @@ -981,13 +1001,7 @@ function Picker:get_status_updater(prompt_win, prompt_bufnr) local padding = string.rep(" ", vim.api.nvim_win_get_width(prompt_win) - prompt_len - #text - 3) vim.api.nvim_buf_clear_namespace(prompt_bufnr, ns_telescope_prompt, 0, 1) - vim.api.nvim_buf_set_virtual_text( - prompt_bufnr, - ns_telescope_prompt, - 0, - { {padding .. text, "NonText"} }, - {} - ) + vim.api.nvim_buf_set_virtual_text(prompt_bufnr, ns_telescope_prompt, 0, { { padding .. text, "NonText" } }, {}) -- TODO: Wait for bfredl -- vim.api.nvim_buf_set_extmark(prompt_bufnr, ns_telescope_prompt, 0, 0, { @@ -997,11 +1011,10 @@ function Picker:get_status_updater(prompt_win, prompt_bufnr) -- virt_text_pos = "eol", -- }) - self:_increment("status") + self:_increment "status" end end - function Picker:get_result_processor(find_id, prompt, status_updater) local cb_add = function(score, entry) self.manager:add_entry(self, score, entry) @@ -1009,17 +1022,15 @@ function Picker:get_result_processor(find_id, prompt, status_updater) end local cb_filter = function(_) - self:_increment("filtered") + self:_increment "filtered" end return function(entry) - if find_id ~= self._find_id - or self.closed - or self:is_done() then + if find_id ~= self._find_id or self.closed or self:is_done() then return true end - self:_increment("processed") + self:_increment "processed" if not entry or entry.valid == false then return @@ -1029,11 +1040,11 @@ function Picker:get_result_processor(find_id, prompt, status_updater) -- a ton of time on large results. log.trace("Processing result... ", entry) for _, v in ipairs(self.file_ignore_patterns or {}) do - local file = type(entry.value) == 'string' and entry.value or entry.filename + local file = type(entry.value) == "string" and entry.value or entry.filename if file then if string.find(file, v) then log.trace("SKIPPING", entry.value, "because", v) - self:_decrement("processed") + self:_decrement "processed" return end end @@ -1045,18 +1056,20 @@ end function Picker:get_result_completor(results_bufnr, find_id, prompt, status_updater) return function() - if self.closed == true or self:is_done() then return end + if self.closed == true or self:is_done() then + return + end - local selection_strategy = self.selection_strategy or 'reset' + local selection_strategy = self.selection_strategy or "reset" -- TODO: Either: always leave one result or make sure we actually clean up the results when nothing matches - if selection_strategy == 'row' then + 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)) else self:set_selection(self:get_selection_row()) end - elseif selection_strategy == 'follow' then + elseif selection_strategy == "follow" then if self._selection_row == nil and self.default_selection_index ~= nil then self:set_selection(self:get_row(self.default_selection_index)) else @@ -1069,53 +1082,53 @@ function Picker:get_result_completor(results_bufnr, find_id, prompt, status_upda self:set_selection(self:get_reset_row()) end end - elseif selection_strategy == 'reset' then + elseif selection_strategy == "reset" then if self.default_selection_index ~= nil then self:set_selection(self:get_row(self.default_selection_index)) else self:set_selection(self:get_reset_row()) end - elseif selection_strategy == 'closest' then + elseif selection_strategy == "closest" then if prompt == "" and self.default_selection_index ~= nil then self:set_selection(self:get_row(self.default_selection_index)) else self:set_selection(self:get_reset_row()) end else - error('Unknown selection strategy: ' .. selection_strategy) + error("Unknown selection strategy: " .. selection_strategy) end local current_line = vim.api.nvim_get_current_line():sub(self.prompt_prefix:len() + 1) - state.set_global_key('current_line', current_line) + state.set_global_key("current_line", current_line) status_updater() self:clear_extra_rows(results_bufnr) self:highlight_displayed_rows(results_bufnr, prompt) - if self.sorter then self.sorter:_finish(prompt) end + if self.sorter then + self.sorter:_finish(prompt) + end self:_on_complete() end end - - pickers.new = function(opts, defaults) local result = {} for k, v in pairs(opts or {}) do - assert(type(k) == 'string', "Should be string, opts") + assert(type(k) == "string", "Should be string, opts") result[k] = v end for k, v in pairs(defaults or {}) do if result[k] == nil then - assert(type(k) == 'string', "Should be string, defaults") + assert(type(k) == "string", "Should be string, defaults") result[k] = v else -- For attach mappings, we want people to be able to pass in another function -- and apply their mappings after we've applied our defaults. - if k == 'attach_mappings' then + if k == "attach_mappings" then local opt_value = result[k] result[k] = function(...) v(...) @@ -1154,5 +1167,4 @@ end pickers._Picker = Picker - return pickers |
