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:
xudyang1
2024-05-26 10:15:31 -04:00
committed by GitHub
parent c2ce039188
commit 349660c0d3
5 changed files with 124 additions and 14 deletions

View File

@@ -5,12 +5,14 @@ local conf = require("telescope.config").values
local Job = require "plenary.job"
local Path = require "plenary.path"
local telescope_utils = require "telescope.utils"
local utils = {}
local detect_from_shebang = function(p)
local s = p:readbyterange(0, 256)
if s then
local lines = vim.split(s, "\n")
local lines = telescope_utils.split_lines(s)
return vim.filetype.match { contents = lines }
end
end
@@ -24,7 +26,7 @@ end
local detect_from_modeline = function(p)
local s = p:readbyterange(-256, 256)
if s then
local lines = vim.split(s, "\n")
local lines = telescope_utils.split_lines(s)
local idx = lines[#lines] ~= "" and #lines or #lines - 1
if idx >= 1 then
return parse_modeline(lines[idx])