diff options
author | Christian Clason <c.clason@uni-graz.at> | 2022-08-19 19:30:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-19 19:30:35 +0200 |
commit | b2f979b30beac67906b2dd717fcb6a34f46f5e54 (patch) | |
tree | 204e9fa22aeac12e4690b330fbf4e4820eb7c34b | |
parent | 7e980a4df4f17baaf347b666aacc7b8474f5217e (diff) | |
download | rneovim-b2f979b30beac67906b2dd717fcb6a34f46f5e54.tar.gz rneovim-b2f979b30beac67906b2dd717fcb6a34f46f5e54.tar.bz2 rneovim-b2f979b30beac67906b2dd717fcb6a34f46f5e54.zip |
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
-rw-r--r-- | runtime/lua/vim/filetype.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 872106b20d..99c98764dd 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -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. |