fix(pickers): improve CRLF line splitting support for windows (#3127)
* fix(help_tags): show help tags on windows (#3126) On Windows, `builtin.help_tags` picker does not show any help tags. To fix this, the following changes are needed: 1. `util.path_tail` checks unix separator `/` on Windows and leave the original implementation intact on unix systems. 2. Line endings should be taken carefully on Windows. `vim.split` with only newline `\n` character as separator may result in unexpected crash when parsing large files. When splits on lines are needed, call it with `\r?\n`, or even set up a wrapper function in utils is more prefered. Fixes #3126 * fix: handle cross platform line splits
This commit is contained in:
@@ -307,3 +307,87 @@ describe("transform_path", function()
|
||||
end, new_relpath "doc/mydoc.md", new_relpath "d/mydoc.md")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("path_tail", function()
|
||||
local function assert_tails(paths)
|
||||
for _, path in ipairs(paths) do
|
||||
it("gets the tail of " .. path, function()
|
||||
local tail = vim.fn.fnamemodify(path, ":p:t")
|
||||
eq(tail, utils.path_tail(path))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
if jit and jit.os:lower() == "windows" then
|
||||
describe("handles windows paths", function()
|
||||
local paths = {
|
||||
[[C:\Users\username\AppData\Local\nvim-data\log]],
|
||||
[[D:\Projects\project_folder\source_code.py]],
|
||||
[[E:\Music\song.mp3]],
|
||||
[[/home/usuario/documents/archivo.txt]],
|
||||
[[/var/www/html/index.html]],
|
||||
[[/mnt/backup/backup_file.tar.gz]],
|
||||
}
|
||||
|
||||
assert_tails(paths)
|
||||
end)
|
||||
elseif jit and jit.os:lower() == "linux" then
|
||||
describe("handles linux paths", function()
|
||||
local paths = {
|
||||
[[/home/usuario/documents/archivo.txt]],
|
||||
[[/var/www/html/index.html]],
|
||||
[[/mnt/backup/backup_file.tar.gz]],
|
||||
}
|
||||
|
||||
assert_tails(paths)
|
||||
end)
|
||||
elseif jit and jit.os:lower() == "osx" then
|
||||
describe("handles macos paths", function()
|
||||
local paths = {
|
||||
[[/Users/Usuario/Documents/archivo.txt]],
|
||||
[[/Applications/App.app/Contents/MacOS/app_executable]],
|
||||
[[/Volumes/ExternalDrive/Data/file.xlsx]],
|
||||
}
|
||||
|
||||
assert_tails(paths)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
describe("split_lines", function()
|
||||
local expect = {
|
||||
"",
|
||||
"",
|
||||
"line3 of the file",
|
||||
"",
|
||||
"line5 of the file",
|
||||
"",
|
||||
"",
|
||||
"line8 of the file, last line of file",
|
||||
"",
|
||||
}
|
||||
|
||||
local function get_fake_file(line_ending)
|
||||
return table.concat(expect, line_ending)
|
||||
end
|
||||
|
||||
local newline_file = get_fake_file "\n"
|
||||
local carriage_newline_file = get_fake_file "\r\n"
|
||||
|
||||
if utils.iswin then
|
||||
describe("handles files on Windows", function()
|
||||
it("reads file with newline only", function()
|
||||
assert.are.same(expect, utils.split_lines(newline_file))
|
||||
end)
|
||||
it("reads file with carriage return and newline", function()
|
||||
assert.are.same(expect, utils.split_lines(carriage_newline_file))
|
||||
end)
|
||||
end)
|
||||
else
|
||||
describe("handles files on non Windows environment", function()
|
||||
it("reads file with newline only", function()
|
||||
assert.are.same(expect, utils.split_lines(newline_file))
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user