fix(__internal) : fix slash problem in oldfiles (#3260)

* fix(__internal) : fix slash problem in oldfiles

- Problems

Problem with slash and backslash being mixed up is chronic issue of
neovim in Windows. it makes telescope prompt perceive same path
differently when it execute to oldfiles picker.

some function like `nvim_buf_get_name()` or `vim.v.oldfiles` give paths
which are mixed up with slash and backslash.

- What it did
For windows, it always needs to change slash(/) to backslash(\) when
function which deal with path because entry_maker works properly only
the case that path string has \ not /.

- Effect

1) oldfiles picker doesn't show duplicated list
2) `defaults.path_display` configuration feature will works well at
   oldfiles pikcer

* fix(__internal) : Repeated comments are erased
This commit is contained in:
Jaehaks
2024-09-22 12:35:27 +09:00
committed by GitHub
parent b5fd7f7ae0
commit 175178e388

View File

@@ -532,12 +532,19 @@ internal.oldfiles = function(opts)
local current_file = vim.api.nvim_buf_get_name(current_buffer) local current_file = vim.api.nvim_buf_get_name(current_buffer)
local results = {} local results = {}
if utils.iswin then -- for slash problem in windows
current_file = current_file:gsub("/", "\\")
end
if opts.include_current_session then if opts.include_current_session then
for _, buffer in ipairs(utils.split_lines(vim.fn.execute ":buffers! t")) do for _, buffer in ipairs(utils.split_lines(vim.fn.execute ":buffers! t")) do
local match = tonumber(string.match(buffer, "%s*(%d+)")) local match = tonumber(string.match(buffer, "%s*(%d+)"))
local open_by_lsp = string.match(buffer, "line 0$") local open_by_lsp = string.match(buffer, "line 0$")
if match and not open_by_lsp then if match and not open_by_lsp then
local file = vim.api.nvim_buf_get_name(match) local file = vim.api.nvim_buf_get_name(match)
if utils.iswin then
file = file:gsub("/", "\\")
end
if vim.loop.fs_stat(file) and match ~= current_buffer then if vim.loop.fs_stat(file) and match ~= current_buffer then
table.insert(results, file) table.insert(results, file)
end end
@@ -546,6 +553,9 @@ internal.oldfiles = function(opts)
end end
for _, file in ipairs(vim.v.oldfiles) do for _, file in ipairs(vim.v.oldfiles) do
if utils.iswin then
file = file:gsub("/", "\\")
end
local file_stat = vim.loop.fs_stat(file) local file_stat = vim.loop.fs_stat(file)
if file_stat and file_stat.type == "file" and not vim.tbl_contains(results, file) and file ~= current_file then if file_stat and file_stat.type == "file" and not vim.tbl_contains(results, file) and file ~= current_file then
table.insert(results, file) table.insert(results, file)