(chore) run formatter
All checks were successful
NeoVim tests / plenary-tests (push) Successful in 11s
All checks were successful
NeoVim tests / plenary-tests (push) Successful in 11s
This commit is contained in:
parent
5a6451a85e
commit
0e7b741b38
@ -121,7 +121,10 @@ end
|
|||||||
---
|
---
|
||||||
--- @return { expand: fun(path: string), collapse: fun(path: string) }
|
--- @return { expand: fun(path: string), collapse: fun(path: string) }
|
||||||
local function _render_in_buffer(opts)
|
local function _render_in_buffer(opts)
|
||||||
local winnr = vim.api.nvim_buf_call(opts.bufnr, function() return vim.api.nvim_get_current_win() end)
|
local winnr = vim.api.nvim_buf_call(
|
||||||
|
opts.bufnr,
|
||||||
|
function() return vim.api.nvim_get_current_win() end
|
||||||
|
)
|
||||||
local s_tree_inf = tracker.create_signal(H.get_tree_inf(opts.root_path))
|
local s_tree_inf = tracker.create_signal(H.get_tree_inf(opts.root_path))
|
||||||
local s_focused_path = tracker.create_signal(H.normalize(opts.focus_path or opts.root_path))
|
local s_focused_path = tracker.create_signal(H.normalize(opts.focus_path or opts.root_path))
|
||||||
|
|
||||||
@ -343,7 +346,11 @@ local function _render_in_buffer(opts)
|
|||||||
return ''
|
return ''
|
||||||
end,
|
end,
|
||||||
n = function()
|
n = function()
|
||||||
vim.schedule(function() controller.new(node.kind == 'file' and vim.fs.dirname(node.path) or node.path) end)
|
vim.schedule(
|
||||||
|
function()
|
||||||
|
controller.new(node.kind == 'file' and vim.fs.dirname(node.path) or node.path)
|
||||||
|
end
|
||||||
|
)
|
||||||
return ''
|
return ''
|
||||||
end,
|
end,
|
||||||
r = function()
|
r = function()
|
||||||
@ -363,7 +370,11 @@ local function _render_in_buffer(opts)
|
|||||||
local icon = node.expanded and '' or ''
|
local icon = node.expanded and '' or ''
|
||||||
tb:put {
|
tb:put {
|
||||||
current_line > 1 and '\n',
|
current_line > 1 and '\n',
|
||||||
h('text', { hl = 'Constant', nmap = nmaps }, { string.rep(' ', level), icon, ' ', name }),
|
h(
|
||||||
|
'text',
|
||||||
|
{ hl = 'Constant', nmap = nmaps },
|
||||||
|
{ string.rep(' ', level), icon, ' ', name }
|
||||||
|
),
|
||||||
}
|
}
|
||||||
if node.expanded then
|
if node.expanded then
|
||||||
for _, child in ipairs(node.children) do
|
for _, child in ipairs(node.children) do
|
||||||
|
@ -7,7 +7,8 @@ local tracker = require 'u.tracker'
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local S_EDITOR_DIMENSIONS = tracker.create_signal(utils.get_editor_dimensions(), 's:editor_dimensions')
|
local S_EDITOR_DIMENSIONS =
|
||||||
|
tracker.create_signal(utils.get_editor_dimensions(), 's:editor_dimensions')
|
||||||
vim.api.nvim_create_autocmd('VimResized', {
|
vim.api.nvim_create_autocmd('VimResized', {
|
||||||
callback = function()
|
callback = function()
|
||||||
local new_dim = utils.get_editor_dimensions()
|
local new_dim = utils.get_editor_dimensions()
|
||||||
@ -202,7 +203,9 @@ function M.create_picker(opts) -- {{{
|
|||||||
|
|
||||||
local s_filter_text_undebounced = tracker.create_signal('', 's:filter_text')
|
local s_filter_text_undebounced = tracker.create_signal('', 's:filter_text')
|
||||||
w_input_buf:autocmd('TextChangedI', {
|
w_input_buf:autocmd('TextChangedI', {
|
||||||
callback = safe_wrap(function() s_filter_text_undebounced:set(vim.api.nvim_get_current_line()) end),
|
callback = safe_wrap(
|
||||||
|
function() s_filter_text_undebounced:set(vim.api.nvim_get_current_line()) end
|
||||||
|
),
|
||||||
})
|
})
|
||||||
local s_filter_text = s_filter_text_undebounced:debounce(50)
|
local s_filter_text = s_filter_text_undebounced:debounce(50)
|
||||||
|
|
||||||
@ -211,10 +214,15 @@ function M.create_picker(opts) -- {{{
|
|||||||
--
|
--
|
||||||
|
|
||||||
local s_formatted_items = tracker.create_memo(function()
|
local s_formatted_items = tracker.create_memo(function()
|
||||||
local function _format_item(item) return opts.format_item and opts.format_item(item) or tostring(item) end
|
local function _format_item(item)
|
||||||
|
return opts.format_item and opts.format_item(item) or tostring(item)
|
||||||
|
end
|
||||||
|
|
||||||
local items = s_items:get()
|
local items = s_items:get()
|
||||||
return vim.iter(items):map(function(item) return { item = item, formatted = _format_item(item) } end):totable()
|
return vim
|
||||||
|
.iter(items)
|
||||||
|
:map(function(item) return { item = item, formatted = _format_item(item) } end)
|
||||||
|
:totable()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- When the filter text changes, update the filtered items:
|
-- When the filter text changes, update the filtered items:
|
||||||
@ -247,7 +255,9 @@ function M.create_picker(opts) -- {{{
|
|||||||
local new_filtered_items = vim
|
local new_filtered_items = vim
|
||||||
.iter(formatted_items)
|
.iter(formatted_items)
|
||||||
:enumerate()
|
:enumerate()
|
||||||
:map(function(i, inf) return { orig_idx = i, item = inf.item, formatted = inf.formatted } end)
|
:map(
|
||||||
|
function(i, inf) return { orig_idx = i, item = inf.item, formatted = inf.formatted } end
|
||||||
|
)
|
||||||
:filter(function(inf)
|
:filter(function(inf)
|
||||||
if filter_text == '' then return true end
|
if filter_text == '' then return true end
|
||||||
local formatted_as_string = Renderer.markup_to_string({ tree = inf.formatted }):lower()
|
local formatted_as_string = Renderer.markup_to_string({ tree = inf.formatted }):lower()
|
||||||
@ -255,9 +265,7 @@ function M.create_picker(opts) -- {{{
|
|||||||
formatted_strings[inf.orig_idx] = formatted_as_string
|
formatted_strings[inf.orig_idx] = formatted_as_string
|
||||||
if use_plain_pattern then
|
if use_plain_pattern then
|
||||||
local x, y = formatted_as_string:find(filter_pattern, 1, true)
|
local x, y = formatted_as_string:find(filter_pattern, 1, true)
|
||||||
if x ~= nil and y ~= nil then
|
if x ~= nil and y ~= nil then matches[inf.orig_idx] = formatted_as_string:sub(x, y) end
|
||||||
matches[inf.orig_idx] = formatted_as_string:sub(x, y)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
matches[inf.orig_idx] = string.match(formatted_as_string, filter_pattern)
|
matches[inf.orig_idx] = string.match(formatted_as_string, filter_pattern)
|
||||||
end
|
end
|
||||||
@ -320,7 +328,9 @@ function M.create_picker(opts) -- {{{
|
|||||||
local filtered_items = s_filtered_items:get()
|
local filtered_items = s_filtered_items:get()
|
||||||
local cursor_index = s_cursor_index:get()
|
local cursor_index = s_cursor_index:get()
|
||||||
local indices = shallow_copy_arr(selected_indices)
|
local indices = shallow_copy_arr(selected_indices)
|
||||||
if #indices == 0 and #filtered_items > 0 then indices = { filtered_items[cursor_index].orig_idx } end
|
if #indices == 0 and #filtered_items > 0 then
|
||||||
|
indices = { filtered_items[cursor_index].orig_idx }
|
||||||
|
end
|
||||||
return {
|
return {
|
||||||
items = vim.iter(indices):map(function(i) return items[i] end):totable(),
|
items = vim.iter(indices):map(function(i) return items[i] end):totable(),
|
||||||
indices = indices,
|
indices = indices,
|
||||||
@ -397,8 +407,18 @@ function M.create_picker(opts) -- {{{
|
|||||||
end
|
end
|
||||||
s_cursor_index:set(next_cursor_index)
|
s_cursor_index:set(next_cursor_index)
|
||||||
end
|
end
|
||||||
vim.keymap.set('i', '<C-n>', safe_wrap(action_next_line), { buffer = w_input_buf.bufnr, desc = 'Picker: next' })
|
vim.keymap.set(
|
||||||
vim.keymap.set('i', '<Down>', safe_wrap(action_next_line), { buffer = w_input_buf.bufnr, desc = 'Picker: next' })
|
'i',
|
||||||
|
'<C-n>',
|
||||||
|
safe_wrap(action_next_line),
|
||||||
|
{ buffer = w_input_buf.bufnr, desc = 'Picker: next' }
|
||||||
|
)
|
||||||
|
vim.keymap.set(
|
||||||
|
'i',
|
||||||
|
'<Down>',
|
||||||
|
safe_wrap(action_next_line),
|
||||||
|
{ buffer = w_input_buf.bufnr, desc = 'Picker: next' }
|
||||||
|
)
|
||||||
|
|
||||||
local function action_prev_line()
|
local function action_prev_line()
|
||||||
local max_line = #s_filtered_items:get()
|
local max_line = #s_filtered_items:get()
|
||||||
@ -406,8 +426,18 @@ function M.create_picker(opts) -- {{{
|
|||||||
if next_cursor_index - s_top_offset:get() < 1 then s_top_offset:set(s_top_offset:get() - 1) end
|
if next_cursor_index - s_top_offset:get() < 1 then s_top_offset:set(s_top_offset:get() - 1) end
|
||||||
s_cursor_index:set(next_cursor_index)
|
s_cursor_index:set(next_cursor_index)
|
||||||
end
|
end
|
||||||
vim.keymap.set('i', '<C-p>', safe_wrap(action_prev_line), { buffer = w_input_buf.bufnr, desc = 'Picker: previous' })
|
vim.keymap.set(
|
||||||
vim.keymap.set('i', '<Up>', safe_wrap(action_prev_line), { buffer = w_input_buf.bufnr, desc = 'Picker: previous' })
|
'i',
|
||||||
|
'<C-p>',
|
||||||
|
safe_wrap(action_prev_line),
|
||||||
|
{ buffer = w_input_buf.bufnr, desc = 'Picker: previous' }
|
||||||
|
)
|
||||||
|
vim.keymap.set(
|
||||||
|
'i',
|
||||||
|
'<Up>',
|
||||||
|
safe_wrap(action_prev_line),
|
||||||
|
{ buffer = w_input_buf.bufnr, desc = 'Picker: previous' }
|
||||||
|
)
|
||||||
|
|
||||||
vim.keymap.set(
|
vim.keymap.set(
|
||||||
'i',
|
'i',
|
||||||
@ -417,7 +447,9 @@ function M.create_picker(opts) -- {{{
|
|||||||
|
|
||||||
local index = s_filtered_items:get()[s_cursor_index:get()].orig_idx
|
local index = s_filtered_items:get()[s_cursor_index:get()].orig_idx
|
||||||
if vim.tbl_contains(s_selected_indices:get(), index) then
|
if vim.tbl_contains(s_selected_indices:get(), index) then
|
||||||
s_selected_indices:set(vim.iter(s_selected_indices:get()):filter(function(i) return i ~= index end):totable())
|
s_selected_indices:set(
|
||||||
|
vim.iter(s_selected_indices:get()):filter(function(i) return i ~= index end):totable()
|
||||||
|
)
|
||||||
else
|
else
|
||||||
local new_selected_indices = shallow_copy_arr(s_selected_indices:get())
|
local new_selected_indices = shallow_copy_arr(s_selected_indices:get())
|
||||||
table.insert(new_selected_indices, index)
|
table.insert(new_selected_indices, index)
|
||||||
@ -429,7 +461,12 @@ function M.create_picker(opts) -- {{{
|
|||||||
)
|
)
|
||||||
|
|
||||||
for key, fn in pairs(opts.mappings or {}) do
|
for key, fn in pairs(opts.mappings or {}) do
|
||||||
vim.keymap.set('i', key, safe_wrap(function() return fn(controller) end), { buffer = w_input_buf.bufnr })
|
vim.keymap.set(
|
||||||
|
'i',
|
||||||
|
key,
|
||||||
|
safe_wrap(function() return fn(controller) end),
|
||||||
|
{ buffer = w_input_buf.bufnr }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Render:
|
-- Render:
|
||||||
@ -499,10 +536,9 @@ function M.create_picker(opts) -- {{{
|
|||||||
if ephemeral == nil then ephemeral = false end
|
if ephemeral == nil then ephemeral = false end
|
||||||
|
|
||||||
if ephemeral and #indicies == 1 then
|
if ephemeral and #indicies == 1 then
|
||||||
local matching_filtered_item_idx, _ = vim
|
local matching_filtered_item_idx, _ = vim.iter(s_filtered_items:get()):enumerate():find(
|
||||||
.iter(s_filtered_items:get())
|
function(_idx, inf) return inf.orig_idx == indicies[1] end
|
||||||
:enumerate()
|
)
|
||||||
:find(function(_idx, inf) return inf.orig_idx == indicies[1] end)
|
|
||||||
if matching_filtered_item_idx ~= nil then s_cursor_index:set(indicies[1]) end
|
if matching_filtered_item_idx ~= nil then s_cursor_index:set(indicies[1]) end
|
||||||
else
|
else
|
||||||
if not opts.multi then
|
if not opts.multi then
|
||||||
@ -721,7 +757,10 @@ function M.files(opts) -- {{{
|
|||||||
-- fast laptop. Show a warning and truncate the list in this case.
|
-- fast laptop. Show a warning and truncate the list in this case.
|
||||||
if #lines >= opts.limit then
|
if #lines >= opts.limit then
|
||||||
if not job_inf.notified_over_limit then
|
if not job_inf.notified_over_limit then
|
||||||
vim.notify('Picker list is too large (truncating list to ' .. opts.limit .. ' items)', vim.log.levels.WARN)
|
vim.notify(
|
||||||
|
'Picker list is too large (truncating list to ' .. opts.limit .. ' items)',
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
pcall(vim.fn.jobstop, job_inf.id)
|
pcall(vim.fn.jobstop, job_inf.id)
|
||||||
job_inf.notified_over_limit = true
|
job_inf.notified_over_limit = true
|
||||||
end
|
end
|
||||||
@ -764,10 +803,7 @@ function M.buffers() -- {{{
|
|||||||
-- trim leading `cwd` from the buffer name:
|
-- trim leading `cwd` from the buffer name:
|
||||||
if item_name:sub(1, #cwd) == cwd then item_name = item_name:sub(#cwd + 1) end
|
if item_name:sub(1, #cwd) == cwd then item_name = item_name:sub(#cwd + 1) end
|
||||||
|
|
||||||
return TreeBuilder.new()
|
return TreeBuilder.new():put(item.changed == 1 and '[+] ' or ' '):put(item_name):tree()
|
||||||
:put(item.changed == 1 and '[+] ' or ' ')
|
|
||||||
:put(item_name)
|
|
||||||
:tree()
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- @params items { bufnr: number }[]
|
--- @params items { bufnr: number }[]
|
||||||
@ -880,7 +916,9 @@ function M.lsp_code_symbols() -- {{{
|
|||||||
local item = items[1]
|
local item = items[1]
|
||||||
|
|
||||||
-- Jump to the file/buffer:
|
-- Jump to the file/buffer:
|
||||||
local buf = vim.iter(vim.fn.getbufinfo { buflisted = 1 }):find(function(b) return b.name == item.filename end)
|
local buf = vim
|
||||||
|
.iter(vim.fn.getbufinfo { buflisted = 1 })
|
||||||
|
:find(function(b) return b.name == item.filename end)
|
||||||
if buf ~= nil then
|
if buf ~= nil then
|
||||||
vim.api.nvim_win_set_buf(0, buf.bufnr)
|
vim.api.nvim_win_set_buf(0, buf.bufnr)
|
||||||
else
|
else
|
||||||
|
@ -46,7 +46,11 @@ function Pos.invalid() return Pos.new(0, 0, 0, 0) end
|
|||||||
function Pos.__lt(a, b) return a.lnum < b.lnum or (a.lnum == b.lnum and a.col < b.col) end
|
function Pos.__lt(a, b) return a.lnum < b.lnum or (a.lnum == b.lnum and a.col < b.col) end
|
||||||
function Pos.__le(a, b) return a < b or a == b end
|
function Pos.__le(a, b) return a < b or a == b end
|
||||||
function Pos.__eq(a, b)
|
function Pos.__eq(a, b)
|
||||||
return getmetatable(a) == Pos and getmetatable(b) == Pos and a.bufnr == b.bufnr and a.lnum == b.lnum and a.col == b.col
|
return getmetatable(a) == Pos
|
||||||
|
and getmetatable(b) == Pos
|
||||||
|
and a.bufnr == b.bufnr
|
||||||
|
and a.lnum == b.lnum
|
||||||
|
and a.col == b.col
|
||||||
end
|
end
|
||||||
function Pos.__add(x, y)
|
function Pos.__add(x, y)
|
||||||
if type(x) == 'number' then
|
if type(x) == 'number' then
|
||||||
|
@ -3,7 +3,7 @@ local Pos = require 'u.pos'
|
|||||||
-- Certain functions in the Range class yank text. In order to prevent unwanted
|
-- Certain functions in the Range class yank text. In order to prevent unwanted
|
||||||
-- highlighting, we intercept and discard some calls to the `on_yank` callback.
|
-- highlighting, we intercept and discard some calls to the `on_yank` callback.
|
||||||
local orig_on_yank = (vim.hl or vim.highlight).on_yank
|
local orig_on_yank = (vim.hl or vim.highlight).on_yank
|
||||||
local on_yank_enabled = true;
|
local on_yank_enabled = true
|
||||||
((vim.hl or vim.highlight) --[[@as any]]).on_yank = function(opts)
|
((vim.hl or vim.highlight) --[[@as any]]).on_yank = function(opts)
|
||||||
if not on_yank_enabled then return end
|
if not on_yank_enabled then return end
|
||||||
return orig_on_yank(opts)
|
return orig_on_yank(opts)
|
||||||
|
@ -117,7 +117,11 @@ describe('Renderer', function()
|
|||||||
r:render {
|
r:render {
|
||||||
R.h('text', { hl = 'HighlightGroup1' }, {
|
R.h('text', { hl = 'HighlightGroup1' }, {
|
||||||
'Hello',
|
'Hello',
|
||||||
R.h('text', { hl = 'HighlightGroup2', extmark = { hl_group = 'HighlightGroup2' } }, ' World'),
|
R.h(
|
||||||
|
'text',
|
||||||
|
{ hl = 'HighlightGroup2', extmark = { hl_group = 'HighlightGroup2' } },
|
||||||
|
' World'
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user