fix(buffer_previewer): bypass path validation for terminal buffers (#2117)

This commit is contained in:
Fabian David Schmidt
2022-08-09 11:45:06 +02:00
committed by GitHub
parent 4725867ec6
commit 787db424e3

View File

@@ -462,13 +462,18 @@ previewers.vimgrep = defaulter(function(opts)
end, end,
define_preview = function(self, entry, status) define_preview = function(self, entry, status)
local p = from_entry.path(entry, true) -- bypass path validation for terminal buffers that don't have appropriate path
local has_buftype = vim.api.nvim_buf_get_option(entry.bufnr, "buftype") ~= ""
local p
if not has_buftype then
p = from_entry.path(entry, true)
if p == nil or p == "" then if p == nil or p == "" then
return return
end end
end
-- Workaround for unnamed buffer when using builtin.buffer -- Workaround for unnamed buffer when using builtin.buffer
if entry.bufnr and (p == "[No Name]" or vim.api.nvim_buf_get_option(entry.bufnr, "buftype") ~= "") then if entry.bufnr and (p == "[No Name]" or has_buftype) then
local lines = vim.api.nvim_buf_get_lines(entry.bufnr, 0, -1, false) local lines = vim.api.nvim_buf_get_lines(entry.bufnr, 0, -1, false)
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
jump_to_line(self, self.state.bufnr, entry.lnum) jump_to_line(self, self.state.bufnr, entry.lnum)