Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Aug 8, 2024
1 parent 2c4f76a commit e00266b
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 17 deletions.
67 changes: 65 additions & 2 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,78 @@ M.vimcmd = function(vimcmd, selected, noesc)
end
end

M.vimcmd_entry = function(vimcmd, selected, opts, pcall_vimcmd)
for _, sel in ipairs(selected) do
(function()
-- Lua 5.1 goto compatiblity hack (function wrap)
local entry = path.entry_to_file(sel, opts, opts._uri)
-- "<none>" could be set by `autocmds`
if entry.path == "<none>" then return end
local fullpath = entry.bufname or entry.uri and entry.uri:match("^%a+://(.*)") or entry.path
-- Something is not right, goto next entry
if not fullpath then return end
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or opts._cwd or uv.cwd(), fullpath })
end
-- Force full paths when `autochdir=true` (#882)
local relpath = vim.o.autochdir and fullpath or path.relative_to(entry.path, uv.cwd())
-- Are we replacing the origin buffer?
local will_replace_curbuf = vimcmd == "e" and path.equals(fullpath, utils.CTX().bname)
or vimcmd == "b" and entry.bufnr and entry.bufnr == utils.CTX().bufnr
if will_replace_curbuf
and not vim.o.hidden
and not vim.o.autowriteall
and utils.buffer_is_dirty(nil, false, true) then
-- when `:set nohidden`, confirm with the user when trying to switch
-- from a dirty buffer, abort if declined, save buffer if requested
if utils.save_dialog(nil) then
vimcmd = vimcmd .. "!"
else
return
end
end
if will_replace_curbuf
and vim.fn.exists("&winfixbuf") == 1
and vim.wo.winfixbuf
then
utils.warn("'winfixbuf' is set for current window, will open in a split.")
vimcmd = "split | " .. vimcmd
end
-- Add current location to jumplist
if not entry.term then vim.cmd("normal! m`") end
-- Killing term buffers requires "!" (#1078)
if entry.term and vimcmd == "bd" then
vimcmd = vimcmd .. "!"
end
-- Only change from current buffer if target is different
-- NOTE: uri entries only execute new buffers (new|vnew|tabnew)
if not entry.uri and (will_replace_curbuf or vimcmd ~= "b" and vimcmd ~= "e") then
vimcmd = string.format("%s %s", vimcmd, entry.bufnr
-- we normalize the path or Windows will fail with directories starting
-- with special characters, for example "C:\app\(web)" will be translated
-- by neovim to "c:\app(web)" (#1082)
or vim.fn.fnameescape(path.normalize(relpath)))
end
if pcall_vimcmd ~= false then
local ok, err = pcall(function() vim.cmd(vimcmd) end)
if not ok then
utils.warn(string.format("':%s' failed: %s", vimcmd, err))
end
else
vim.cmd(vimcmd)
end
end)()
end
end

M.vimcmd_file = function(vimcmd, selected, opts, pcall_vimcmd)
local curbuf = vim.api.nvim_buf_get_name(0)
local is_term = utils.is_term_buffer(0)
for i = 1, #selected do
(function()
-- Lua 5.1 goto compatiblity hack (function wrap)
local entry = path.entry_to_file(selected[i], opts, opts.force_uri)
local entry = path.entry_to_file(selected[i], opts, opts._uri)
if entry.path == "<none>" then return end
entry.ctag = opts._ctag and path.entry_to_ctag(selected[i])
local fullpath = entry.path or entry.uri and entry.uri:match("^%a+://(.*)")
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or opts._cwd or uv.cwd(), fullpath })
Expand Down
4 changes: 4 additions & 0 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ M.defaults.lsp = {
fzf_opts = { ["--multi"] = true },
_actions = function() return M.globals.actions.files end,
_cached_hls = { "path_colnr", "path_linenr" },
-- Signals actions to use uri triggering the use of `lsp.util.jump_to_location`
_uri = true,
}

M.defaults.lsp.symbols = {
Expand Down Expand Up @@ -833,6 +835,7 @@ M.defaults.lsp.symbols = {
_actions = function() return M.globals.actions.files end,
actions = { ["ctrl-g"] = { actions.sym_lsym } },
_cached_hls = { "live_sym", "path_colnr", "path_linenr" },
_uri = true,
}

M.defaults.lsp.finder = {
Expand Down Expand Up @@ -867,6 +870,7 @@ M.defaults.lsp.finder = {
},
fzf_opts = { ["--multi"] = true },
_cached_hls = { "path_colnr", "path_linenr" },
_uri = true,
}

M.defaults.lsp.code_actions = {
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ function M.entry_to_file(entry, opts, force_uri)
path = file,
line = tonumber(line) or 0,
col = tonumber(col) or 0,
ctag = opts._ctag and M.entry_to_ctag(stripped) or nil,
}
end

Expand Down
10 changes: 0 additions & 10 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1118,16 +1118,6 @@ function Previewer.tags:new(o, opts, fzf_win)
return self
end

function Previewer.tags:parse_entry(entry_str)
-- first parse as normal entry
-- must use 'super.' and send self as 1st arg
-- or the ':' syntactic sugar will send super's
-- self which doesn't have self.opts
local entry = self.super.parse_entry(self, entry_str)
entry.ctag = path.entry_to_ctag(entry_str)
return entry
end

function Previewer.tags:set_cursor_hl(entry)
-- pcall(vim.fn.clearmatches, self.win.preview_winid)
pcall(api.nvim_win_call, self.win.preview_winid, function()
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/previewer/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function Previewer.cmd_async:parse_entry_and_verify(entrystr)
-- make relative for bat's header display
local filepath = path.relative_to(entry.bufname or entry.path or "", uv.cwd())
if self.opts._ctag then
-- NOTE: override `entry.ctag` with the unescaped version
entry.ctag = path.entry_to_ctag(entry.stripped, true)
if not tonumber(entry.line) or tonumber(entry.line) < 1 then
-- default tags are without line numbers
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/profiles/fzf-vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local function setup_commands(no_override, prefix)
["Changes"] = utils.create_user_command_callback("changes"),
["Marks"] = utils.create_user_command_callback("marks"),
["Jumps"] = utils.create_user_command_callback("jumps"),
["Commands"] = utils.create_user_command_callback("commands"),
["History"] = utils.create_user_command_callback("oldfiles", "query", {
[":"] = "command_history",
["/"] = "search_history",
Expand Down
5 changes: 0 additions & 5 deletions lua/fzf-lua/providers/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ end
local function fzf_lsp_locations(opts, fn_contents)
opts = normalize_lsp_opts(opts, "lsp")
if not opts then return end
if opts.force_uri == nil then opts.force_uri = true end
opts = core.set_fzf_field_index(opts)
opts = fn_contents(opts)
if not opts.__contents then
Expand Down Expand Up @@ -682,7 +681,6 @@ end
M.finder = function(opts)
opts = normalize_lsp_opts(opts, "lsp.finder")
if not opts then return end
if opts.force_uri == nil then opts.force_uri = true end
local contents = {}
local lsp_params = opts.lsp_params
for _, p in ipairs(opts.providers) do
Expand Down Expand Up @@ -773,7 +771,6 @@ M.document_symbols = function(opts)
end
opts = core.set_header(opts, opts.headers or { "regex_filter" })
opts = core.set_fzf_field_index(opts)
if opts.force_uri == nil then opts.force_uri = true end
if not opts.fzf_opts or opts.fzf_opts["--with-nth"] == nil then
-- our delims are {nbsp,:} make sure entry has no icons
-- "{nbsp}file:line:col:" and hide the last 4 fields
Expand Down Expand Up @@ -804,7 +801,6 @@ M.workspace_symbols = function(opts)
opts = core.set_header(opts, opts.headers or
{ "actions", "cwd", "lsp_query", "regex_filter" })
opts = core.set_fzf_field_index(opts)
if opts.force_uri == nil then opts.force_uri = true end
opts = gen_lsp_contents(opts)
if not opts.__contents then
core.__CTX = nil
Expand Down Expand Up @@ -873,7 +869,6 @@ M.live_workspace_symbols = function(opts)

opts = core.set_header(opts, opts.headers or { "actions", "cwd", "regex_filter" })
opts = core.set_fzf_field_index(opts)
if opts.force_uri == nil then opts.force_uri = true end
if opts.symbol_style or opts.symbol_fmt then
opts.fn_pre_fzf = function() gen_sym2style_map(opts) end
opts.fn_post_fzf = function() M._sym2style = nil end
Expand Down
4 changes: 4 additions & 0 deletions lua/fzf-lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ function M.fzf_winobj()
return loadstring("return require'fzf-lua'.win.__SELF()")()
end

function M.CTX()
return loadstring("return require'fzf-lua'.core.CTX()")()
end

function M.resume_get(what, opts)
local f = loadstring("return require'fzf-lua'.config.resume_get")()
return f(what, opts)
Expand Down

0 comments on commit e00266b

Please sign in to comment.