fix: 126
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
local a = vim.api
|
local a = vim.api
|
||||||
|
|
||||||
local log = require('telescope.log')
|
local log = require('telescope.log')
|
||||||
|
local path = require('telescope.path')
|
||||||
local state = require('telescope.state')
|
local state = require('telescope.state')
|
||||||
|
|
||||||
local actions = setmetatable({}, {
|
local actions = setmetatable({}, {
|
||||||
@@ -89,11 +90,12 @@ local function goto_file_selection(prompt_bufnr, command)
|
|||||||
|
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
|
filename = path.normalize(filename, vim.fn.getcwd())
|
||||||
|
|
||||||
-- TODO: Sometimes we open something with missing line numbers and stuff...
|
-- TODO: Sometimes we open something with missing line numbers and stuff...
|
||||||
if entry_bufnr then
|
if entry_bufnr then
|
||||||
if command == "e" then
|
if command == "e" then
|
||||||
a.nvim_win_set_buf(original_win_id, entry_bufnr)
|
a.nvim_win_set_buf(original_win_id, entry_bufnr)
|
||||||
vim.api.nvim_command("doautocmd filetypedetect BufRead " .. vim.fn.fnameescape(filename))
|
|
||||||
else
|
else
|
||||||
vim.cmd(string.format(":%s #%d", command, entry_bufnr))
|
vim.cmd(string.format(":%s #%d", command, entry_bufnr))
|
||||||
end
|
end
|
||||||
@@ -103,7 +105,6 @@ local function goto_file_selection(prompt_bufnr, command)
|
|||||||
vim.cmd(string.format(":%s %s", command, filename))
|
vim.cmd(string.format(":%s %s", command, filename))
|
||||||
bufnr = vim.api.nvim_get_current_buf()
|
bufnr = vim.api.nvim_get_current_buf()
|
||||||
a.nvim_buf_set_option(bufnr, "buflisted", true)
|
a.nvim_buf_set_option(bufnr, "buflisted", true)
|
||||||
vim.api.nvim_command("doautocmd filetypedetect BufRead " .. vim.fn.fnameescape(filename))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if row and col then
|
if row and col then
|
||||||
@@ -113,23 +114,27 @@ local function goto_file_selection(prompt_bufnr, command)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if command == "edit" then
|
||||||
|
vim.api.nvim_command("doautocmd filetypedetect BufRead " .. vim.fn.fnameescape(filename))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function actions.goto_file_selection_edit(prompt_bufnr)
|
function actions.goto_file_selection_edit(prompt_bufnr)
|
||||||
goto_file_selection(prompt_bufnr, "e")
|
goto_file_selection(prompt_bufnr, "edit")
|
||||||
end
|
end
|
||||||
|
|
||||||
function actions.goto_file_selection_split(prompt_bufnr)
|
function actions.goto_file_selection_split(prompt_bufnr)
|
||||||
goto_file_selection(prompt_bufnr, "sp")
|
goto_file_selection(prompt_bufnr, "new")
|
||||||
end
|
end
|
||||||
|
|
||||||
function actions.goto_file_selection_vsplit(prompt_bufnr)
|
function actions.goto_file_selection_vsplit(prompt_bufnr)
|
||||||
goto_file_selection(prompt_bufnr, "vsp")
|
goto_file_selection(prompt_bufnr, "vnew")
|
||||||
end
|
end
|
||||||
|
|
||||||
function actions.goto_file_selection_tabedit(prompt_bufnr)
|
function actions.goto_file_selection_tabedit(prompt_bufnr)
|
||||||
goto_file_selection(prompt_bufnr, "tabe")
|
goto_file_selection(prompt_bufnr, "tabedit")
|
||||||
end
|
end
|
||||||
|
|
||||||
function actions.close_pum(_)
|
function actions.close_pum(_)
|
||||||
@@ -151,6 +156,7 @@ function actions.close(prompt_bufnr)
|
|||||||
vim.cmd [[stopinsert]]
|
vim.cmd [[stopinsert]]
|
||||||
|
|
||||||
vim.api.nvim_win_close(prompt_win, true)
|
vim.api.nvim_win_close(prompt_win, true)
|
||||||
|
|
||||||
pcall(vim.cmd, string.format([[silent bdelete! %s]], prompt_bufnr))
|
pcall(vim.cmd, string.format([[silent bdelete! %s]], prompt_bufnr))
|
||||||
|
|
||||||
a.nvim_set_current_win(original_win_id)
|
a.nvim_set_current_win(original_win_id)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
local has_devicons, devicons = pcall(require, 'nvim-web-devicons')
|
local has_devicons, devicons = pcall(require, 'nvim-web-devicons')
|
||||||
|
|
||||||
|
local path = require('telescope.path')
|
||||||
local utils = require('telescope.utils')
|
local utils = require('telescope.utils')
|
||||||
|
|
||||||
local get_default = utils.get_default
|
local get_default = utils.get_default
|
||||||
local os_sep = utils.get_separator()
|
|
||||||
|
|
||||||
local make_entry = {}
|
local make_entry = {}
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
local make_display = function(entry)
|
local make_display = function(entry)
|
||||||
local display_bufname
|
local display_bufname
|
||||||
if opts.shorten_path then
|
if opts.shorten_path then
|
||||||
display_bufname = utils.path_shorten(entry.filename)
|
display_bufname = path.shorten(entry.filename)
|
||||||
else
|
else
|
||||||
display_bufname = entry.filename
|
display_bufname = entry.filename
|
||||||
end
|
end
|
||||||
@@ -209,17 +209,9 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
|
|
||||||
return function(entry)
|
return function(entry)
|
||||||
local bufnr_str = tostring(entry)
|
local bufnr_str = tostring(entry)
|
||||||
local bufname = vim.api.nvim_buf_get_name(entry)
|
local bufname = path.normalize(vim.api.nvim_buf_get_name(entry), cwd)
|
||||||
|
|
||||||
-- if bufname is inside the cwd, trim that part of the string
|
-- if bufname is inside the cwd, trim that part of the string
|
||||||
if bufname:sub(1, #cwd) == cwd then
|
|
||||||
local offset = 0
|
|
||||||
-- if cwd does ends in the os separator, we need to take it off
|
|
||||||
if cwd:sub(#cwd, #cwd) ~= os_sep then
|
|
||||||
offset = 1
|
|
||||||
end
|
|
||||||
bufname = bufname:sub(#cwd + 1 + offset, #bufname)
|
|
||||||
end
|
|
||||||
|
|
||||||
local position = get_position(entry)
|
local position = get_position(entry)
|
||||||
|
|
||||||
|
|||||||
60
lua/telescope/path.lua
Normal file
60
lua/telescope/path.lua
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
local path = {}
|
||||||
|
|
||||||
|
-- TODO: Can we use vim.loop for this?
|
||||||
|
path.separator = package.config:sub(1, 1)
|
||||||
|
path.home = vim.fn.expand("~")
|
||||||
|
|
||||||
|
|
||||||
|
path.make_relative = function(filepath, cwd)
|
||||||
|
if not cwd or not filepath then return filepath end
|
||||||
|
|
||||||
|
if filepath:sub(1, #cwd) == cwd then
|
||||||
|
local offset = 0
|
||||||
|
-- if cwd does ends in the os separator, we need to take it off
|
||||||
|
if cwd:sub(#cwd, #cwd) ~= path.separator then
|
||||||
|
offset = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
filepath = filepath:sub(#cwd + 1 + offset, #filepath)
|
||||||
|
end
|
||||||
|
|
||||||
|
return filepath
|
||||||
|
end
|
||||||
|
|
||||||
|
path.shorten = (function()
|
||||||
|
if jit then
|
||||||
|
local ffi = require('ffi')
|
||||||
|
ffi.cdef [[
|
||||||
|
typedef unsigned char char_u;
|
||||||
|
char_u *shorten_dir(char_u *str);
|
||||||
|
]]
|
||||||
|
|
||||||
|
return function(filepath)
|
||||||
|
if not filepath then
|
||||||
|
return filepath
|
||||||
|
end
|
||||||
|
|
||||||
|
local c_str = ffi.new("char[?]", #filepath + 1)
|
||||||
|
ffi.copy(c_str, filepath)
|
||||||
|
return ffi.string(ffi.C.shorten_dir(c_str))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return function(filepath)
|
||||||
|
return filepath
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)()
|
||||||
|
|
||||||
|
path.normalize = function(filepath, cwd)
|
||||||
|
filepath = path.make_relative(filepath, cwd)
|
||||||
|
|
||||||
|
-- Substitute home directory w/ "~"
|
||||||
|
filepath = filepath:gsub("^" .. path.home, '~', 1)
|
||||||
|
|
||||||
|
-- Remove double path separators, it's annoying
|
||||||
|
filepath = filepath:gsub(path.separator .. path.separator, path.separator)
|
||||||
|
|
||||||
|
return filepath
|
||||||
|
end
|
||||||
|
|
||||||
|
return path
|
||||||
@@ -361,8 +361,15 @@ function Picker:find()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if first_line > 0 or last_line > 1 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, first_line, last_line, false)[1]
|
local prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, first_line, last_line, false)[1]
|
||||||
|
|
||||||
|
-- TODO: Statusbar possibilities here.
|
||||||
|
-- vim.api.nvim_buf_set_virtual_text(prompt_bufnr, 0, 1, { {"hello", "Error"} }, {})
|
||||||
|
|
||||||
local filtered_amount = 0
|
local filtered_amount = 0
|
||||||
local displayed_amount = 0
|
local displayed_amount = 0
|
||||||
local displayed_fn_amount = 0
|
local displayed_fn_amount = 0
|
||||||
@@ -643,6 +650,10 @@ function Picker:set_selection(row)
|
|||||||
-- Probably something with setting a row that's too high for this?
|
-- Probably something with setting a row that's too high for this?
|
||||||
-- Not sure.
|
-- Not sure.
|
||||||
local set_ok, set_errmsg = pcall(function()
|
local set_ok, set_errmsg = pcall(function()
|
||||||
|
if not a.nvim_buf_is_valid(results_bufnr) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local prompt = vim.api.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)[1]
|
local prompt = vim.api.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)[1]
|
||||||
|
|
||||||
-- Handle adding '> ' to beginning of selections
|
-- Handle adding '> ' to beginning of selections
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
|
local pathlib = require('telescope.path')
|
||||||
|
|
||||||
local utils = {}
|
local utils = {}
|
||||||
|
|
||||||
utils.get_separator = (function()
|
utils.get_separator = function()
|
||||||
local val = package.config:sub(1, 1)
|
return pathlib.separator
|
||||||
return function()
|
end
|
||||||
return val
|
|
||||||
end
|
|
||||||
end)()
|
|
||||||
|
|
||||||
utils.if_nil = function(x, was_nil, was_not_nil)
|
utils.if_nil = function(x, was_nil, was_not_nil)
|
||||||
if x == nil then
|
if x == nil then
|
||||||
@@ -97,29 +96,7 @@ end
|
|||||||
|
|
||||||
-- return result
|
-- return result
|
||||||
-- end or nil)
|
-- end or nil)
|
||||||
utils.path_shorten = (function()
|
utils.path_shorten = pathlib.shorten
|
||||||
if jit then
|
|
||||||
local ffi = require('ffi')
|
|
||||||
ffi.cdef [[
|
|
||||||
typedef unsigned char char_u;
|
|
||||||
char_u *shorten_dir(char_u *str);
|
|
||||||
]]
|
|
||||||
|
|
||||||
return function(path)
|
|
||||||
if not path then
|
|
||||||
return path
|
|
||||||
end
|
|
||||||
|
|
||||||
local c_str = ffi.new("char[?]", #path + 1)
|
|
||||||
ffi.copy(c_str, path)
|
|
||||||
return ffi.string(ffi.C.shorten_dir(c_str))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return function(path)
|
|
||||||
return path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)()
|
|
||||||
|
|
||||||
utils.path_tail = (function()
|
utils.path_tail = (function()
|
||||||
local os_sep = utils.get_separator()
|
local os_sep = utils.get_separator()
|
||||||
|
|||||||
Reference in New Issue
Block a user