Skip to content

Commit 7469b0c

Browse files
committed
build: switch to plenary.path2 for improve Windows path support
1 parent 43c47eb commit 7469b0c

File tree

16 files changed

+29
-36
lines changed

16 files changed

+29
-36
lines changed

lua/telescope/actions/history.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local conf = require("telescope.config").values
2-
local Path = require "plenary.path"
2+
local Path = require "plenary.path2"
33
local utils = require "telescope.utils"
44

55
local uv = vim.loop

lua/telescope/actions/set.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
local a = vim.api
1515

1616
local log = require "telescope.log"
17-
local Path = require "plenary.path"
17+
local Path = require "plenary.path2"
1818
local state = require "telescope.state"
1919
local utils = require "telescope.utils"
2020

@@ -196,7 +196,7 @@ action_set.edit = function(prompt_bufnr, command)
196196
-- check if we didn't pick a different buffer
197197
-- prevents restarting lsp server
198198
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
199-
filename = Path:new(filename):normalize(vim.loop.cwd())
199+
filename = Path:new(filename):make_relative(vim.loop.cwd(), true)
200200
pcall(vim.cmd, string.format("%s %s", command, vim.fn.fnameescape(filename)))
201201
end
202202
end

lua/telescope/actions/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ end
108108

109109
-- Best effort to infer function names for actions.which_key
110110
function utils._get_anon_function_name(info)
111-
local Path = require "plenary.path"
111+
local Path = require "plenary.path2"
112112
local fname
113113
-- if fn defined in string (ie loadstring) source is string
114114
-- if fn defined in file, source is file name prefixed with a `@´

lua/telescope/algos/fzy.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
-- > matches on consecutive letters and starts of words. This allows matching
88
-- > using acronyms or different parts of the path." - J Hawthorn
99

10-
local has_path, Path = pcall(require, "plenary.path")
11-
if not has_path then
12-
Path = {
13-
path = {
14-
separator = "/",
15-
},
16-
}
17-
end
10+
local Path = require "plenary.path2"
1811

1912
local SCORE_GAP_LEADING = -0.005
2013
local SCORE_GAP_TRAILING = -0.005

lua/telescope/builtin/__files.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local utils = require "telescope.utils"
1010
local conf = require("telescope.config").values
1111
local log = require "telescope.log"
1212

13-
local Path = require "plenary.path"
13+
local Path = require "plenary.path2"
1414

1515
local flatten = utils.flatten
1616
local filter = vim.tbl_filter

lua/telescope/builtin/__git.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local previewers = require "telescope.previewers"
88
local utils = require "telescope.utils"
99
local entry_display = require "telescope.pickers.entry_display"
1010
local strings = require "plenary.strings"
11-
local Path = require "plenary.path"
11+
local Path = require "plenary.path2"
1212

1313
local conf = require("telescope.config").values
1414
local git_command = utils.__git_command

lua/telescope/builtin/__internal.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local action_set = require "telescope.actions.set"
33
local action_state = require "telescope.actions.state"
44
local finders = require "telescope.finders"
55
local make_entry = require "telescope.make_entry"
6-
local Path = require "plenary.path"
6+
local Path = require "plenary.path2"
77
local pickers = require "telescope.pickers"
88
local previewers = require "telescope.previewers"
99
local p_window = require "telescope.pickers.window"
@@ -319,7 +319,7 @@ internal.symbols = function(opts)
319319

320320
local results = {}
321321
for _, source in ipairs(sources) do
322-
local data = vim.json.decode(Path:new(source):read())
322+
local data = vim.json.decode(assert(Path:new(source):read()))
323323
for _, entry in ipairs(data) do
324324
table.insert(results, entry)
325325
end

lua/telescope/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local strings = require "plenary.strings"
22
local deprecated = require "telescope.deprecated"
33
local sorters = require "telescope.sorters"
4-
local os_sep = require("plenary.path").path.sep
4+
local os_sep = require("plenary.path2").path.sep
55
local has_win = vim.fn.has "win32" == 1
66

77
-- Keep the values around between reloads

lua/telescope/make_entry.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
local entry_display = require "telescope.pickers.entry_display"
3838
local utils = require "telescope.utils"
3939
local strings = require "plenary.strings"
40-
local Path = require "plenary.path"
40+
local Path = require "plenary.path2"
4141

4242
local treesitter_type_highlight = {
4343
["associated"] = "TSConstant",
@@ -625,7 +625,7 @@ function make_entry.gen_from_buffer(opts)
625625

626626
return function(entry)
627627
local filename = entry.info.name ~= "" and entry.info.name or nil
628-
local bufname = filename and Path:new(filename):normalize(cwd) or "[No Name]"
628+
local bufname = filename and Path:new(filename):make_relative(cwd, true) or "[No Name]"
629629

630630
local hidden = entry.info.hidden == 1 and "h" or "a"
631631
local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " "
@@ -1026,7 +1026,7 @@ function make_entry.gen_from_ctags(opts)
10261026
opts = opts or {}
10271027

10281028
local cwd = utils.path_expand(opts.cwd or vim.loop.cwd())
1029-
local current_file = Path:new(vim.api.nvim_buf_get_name(opts.bufnr)):normalize(cwd)
1029+
local current_file = Path:new(vim.api.nvim_buf_get_name(opts.bufnr)):make_relative(cwd)
10301030

10311031
local display_items = {
10321032
{ remaining = true },
@@ -1111,7 +1111,7 @@ function make_entry.gen_from_ctags(opts)
11111111

11121112
if opts.only_current_file then
11131113
if current_file_cache[file] == nil then
1114-
current_file_cache[file] = Path:new(file):normalize(cwd) == current_file
1114+
current_file_cache[file] = Path:new(file):make_relative(cwd, true) == current_file
11151115
end
11161116

11171117
if current_file_cache[file] == false then

lua/telescope/previewers/buffer_previewer.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local from_entry = require "telescope.from_entry"
2-
local Path = require "plenary.path"
2+
local Path = require "plenary.path2"
33
local utils = require "telescope.utils"
44
local putils = require "telescope.previewers.utils"
55
local Previewer = require "telescope.previewers.previewer"
@@ -98,7 +98,7 @@ color_hash[6] = function(line)
9898
end
9999

100100
local colorize_ls_long = function(bufnr, data, sections)
101-
local windows_add = Path.path.sep == "\\" and 2 or 0
101+
local windows_add = utils.iswin and 2 or 0
102102
for lnum, line in ipairs(data) do
103103
local section = sections[lnum]
104104
for i = 1, section[1].end_index - 1 do -- Highlight permissions
@@ -125,7 +125,7 @@ local handle_directory_preview = function(filepath, bufnr, opts)
125125
local set_colorize_lines
126126
if opts.preview.ls_short then
127127
set_colorize_lines = function(data, sections)
128-
local PATH_SECTION = Path.path.sep == "\\" and 4 or 6
128+
local PATH_SECTION = utils.iswin and 4 or 6
129129
local paths = {}
130130
for i, line in ipairs(data) do
131131
local section = sections[i][PATH_SECTION]
@@ -195,7 +195,7 @@ local handle_file_preview = function(filepath, bufnr, stat, opts)
195195
end
196196

197197
opts.start_time = vim.loop.hrtime()
198-
Path:new(filepath):_read_async(vim.schedule_wrap(function(data)
198+
Path:new(filepath):read(vim.schedule_wrap(function(data)
199199
if not vim.api.nvim_buf_is_valid(bufnr) then
200200
return
201201
end
@@ -491,7 +491,7 @@ previewers.cat = defaulter(function(opts)
491491
return previewers.new_buffer_previewer {
492492
title = "File Preview",
493493
dyn_title = function(_, entry)
494-
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
494+
return Path:new(from_entry.path(entry, false, false)):make_relative(cwd, true)
495495
end,
496496

497497
get_buffer_by_name = function(_, entry)
@@ -554,7 +554,7 @@ previewers.vimgrep = defaulter(function(opts)
554554
return previewers.new_buffer_previewer {
555555
title = "Grep Preview",
556556
dyn_title = function(_, entry)
557-
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
557+
return Path:new(from_entry.path(entry, false, false)):make_relative(cwd, true)
558558
end,
559559

560560
get_buffer_by_name = function(_, entry)

0 commit comments

Comments
 (0)