new provider: tagstack, fixed external win file actions (#336)

main
bhagwan 2 years ago
parent a487c6752f
commit b772c0de9c

@ -193,6 +193,7 @@ vim.api.nvim_set_keymap('n', '<c-P>',
| `jumps` | :jumps |
| `changes` | :changes |
| `registers` | :registers |
| `tagstack` | :tags |
| `keymaps` | key mappings |
| `spell_suggest` | spelling suggestions |
| `tags` | project tags |

@ -226,6 +226,7 @@ MISC *fzf-lua-misc*
| `jumps` | :jumps |
| `changes` | :changes |
| `registers` | :registers |
| `tagstack` | :tags |
| `keymaps` | key mappings |
| `spell_suggest` | spelling suggestions |
| `tags` | project tags |

@ -87,39 +87,34 @@ M.vimcmd_file = function(vimcmd, selected, opts)
for i = 1, #selected do
local entry = path.entry_to_file(selected[i], opts.cwd, opts.force_uri)
entry.ctag = path.entry_to_ctag(selected[i])
-- Java LSP entries, 'jdt://...'
local fullpath = entry.path or entry.uri and entry.uri:match("^%a+://(.*)")
if not path.starts_with_separator(fullpath) then
fullpath = path.join({opts.cwd or vim.loop.cwd(), fullpath})
end
if vimcmd == 'e' and curbuf ~= fullpath
and not vim.o.hidden and
utils.buffer_is_dirty(nil, true) then
-- warn the user when trying to switch from a dirty buffer
-- when `:set nohidden`
return
end
-- add current location to jumplist
if not is_term then vim.cmd("normal! m`") end
-- only change buffer if we need to (issue #122)
if vimcmd ~= "e" or curbuf ~= fullpath then
vim.cmd(vimcmd .. " " .. vim.fn.fnameescape(entry.path))
end
-- Java LSP entries, 'jdt://...' or LSP locations
if entry.uri then
if not is_term then vim.cmd("normal! m`") end
vim.lsp.util.jump_to_location(entry, "utf-16")
if not is_term then vim.cmd("norm! zvzz") end
else
-- only change buffer if we need to (issue #122)
local fullpath = entry.path
if not path.starts_with_separator(fullpath) then
fullpath = path.join({opts.cwd or vim.loop.cwd(), fullpath})
end
if vimcmd == 'e' and curbuf ~= fullpath
and not vim.o.hidden and
utils.buffer_is_dirty(nil, true) then
-- warn the user when trying to switch from a dirty buffer
-- when `:set nohidden`
return
end
-- add current location to jumplist
if not is_term then vim.cmd("normal! m`") end
if vimcmd ~= "e" or curbuf ~= fullpath then
vim.cmd(vimcmd .. " " .. vim.fn.fnameescape(entry.path))
end
if entry.ctag or entry.line>1 or entry.col>1 then
if entry.line>1 or entry.col>1 then
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
else
vim.api.nvim_win_set_cursor(0, {1, 0})
vim.fn.search(entry.ctag, "W")
end
if not is_term then vim.cmd("norm! zvzz") end
end
elseif tonumber(entry.line)>0 then
entry.col = entry.col or 1
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
elseif entry.ctag then
vim.api.nvim_win_set_cursor(0, {1, 0})
vim.fn.search(entry.ctag, "W")
end
if not is_term then vim.cmd("norm! zvzz") end
end
end

@ -462,6 +462,14 @@ M.globals.nvim = {
_ctor = previewers.builtin.jumps,
},
},
tagstack = {
prompt = 'Tagstack> ',
file_icons = true and M._has_devicons,
color_icons = true,
git_icons = true,
previewer = M._default_previewer_fn,
_actions = function() return M.globals.actions.files end,
},
commands = {
prompt = 'Commands> ',
actions = {

@ -125,6 +125,7 @@ M.tags = require'fzf-lua.providers.tags'.tags
M.btags = require'fzf-lua.providers.tags'.btags
M.jumps = require'fzf-lua.providers.nvim'.jumps
M.changes = require'fzf-lua.providers.nvim'.changes
M.tagstack = require'fzf-lua.providers.nvim'.tagstack
M.marks = require'fzf-lua.providers.nvim'.marks
M.keymaps = require'fzf-lua.providers.nvim'.keymaps
M.registers = require'fzf-lua.providers.nvim'.registers

@ -1,4 +1,5 @@
local core = require "fzf-lua.core"
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
local shell = require "fzf-lua.shell"
local config = require "fzf-lua.config"
@ -118,6 +119,68 @@ M.jumps = function(opts)
end)()
end
M.tagstack = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.tagstack)
if not opts then return end
local tagstack = vim.fn.gettagstack().items
local tags = {}
for i = #tagstack, 1, -1 do
local tag = tagstack[i]
tag.bufnr = tag.from[1]
if vim.api.nvim_buf_is_valid(tag.bufnr) then
tags[#tags + 1] = tag
tag.filename = vim.fn.bufname(tag.bufnr)
tag.lnum = tag.from[2]
tag.col = tag.from[3]
tag.text = vim.api.nvim_buf_get_lines(tag.bufnr, tag.lnum - 1, tag.lnum, false)[1] or ""
end
end
if vim.tbl_isempty(tags) then
utils.info("No tagstack available")
return
end
local entries = {}
for i, tag in ipairs(tags) do
local bufname = tag.filename
local buficon, hl
if opts.file_icons then
local filename = path.tail(bufname)
local extension = path.extension(filename)
buficon, hl = core.get_devicon(filename, extension)
if opts.color_icons then
buficon = utils.ansi_codes[hl](buficon)
end
end
-- table.insert(entries, ("%s)%s[%s]%s%s%s%s:%s:%s: %s"):format(
table.insert(entries, ("%s)%s%s%s%s:%s:%s: %s"):format(
utils.ansi_codes.yellow(tostring(i)),
utils.nbsp,
-- utils.ansi_codes.yellow(tostring(tag.bufnr)),
-- utils.nbsp,
buficon or '',
buficon and utils.nbsp or '',
utils.ansi_codes.magenta(#bufname>0 and bufname or "[No Name]"),
utils.ansi_codes.green(tostring(tag.lnum)),
tag.col,
tag.text))
end
opts.fzf_opts['--no-multi'] = ''
core.fzf_wrap(opts, entries, function(selected)
if not selected then return end
actions.act(opts.actions, selected, opts)
end)()
end
M.marks = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.marks)
if not opts then return end

Loading…
Cancel
Save