mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
fix(filetype): only check first 100 and last line of buffer (#19819)
fix(filetype): only pass first 100 and last lines to contents check sufficient for current content checks and avoids performance issues for buffers with a large number of lines fixes #19817
This commit is contained in:
parent
7e980a4df4
commit
b2f979b30b
@ -2489,7 +2489,15 @@ function M.match(args)
|
||||
|
||||
-- Finally, check file contents
|
||||
if contents or bufnr then
|
||||
contents = contents or M.getlines(bufnr)
|
||||
if contents == nil then
|
||||
if api.nvim_buf_line_count(bufnr) > 101 then
|
||||
-- only need first 100 and last line for current checks
|
||||
contents = M.getlines(bufnr, 1, 100)
|
||||
contents[#contents + 1] = M.getlines(bufnr, -1)
|
||||
else
|
||||
contents = M.getlines(bufnr)
|
||||
end
|
||||
end
|
||||
-- If name is nil, catch any errors from the contents filetype detection function.
|
||||
-- If the function tries to use the filename that is nil then it will fail,
|
||||
-- but this enables checks which do not need a filename to still work.
|
||||
|
Loading…
Reference in New Issue
Block a user