spywhere / detect-language.nvim

neovim plugin for better language auto-detection, powered by tree-sitter
52 stars 0 forks source link

Small code optimization #5

Closed spywhere closed 3 years ago

spywhere commented 3 years ago

https://github.com/spywhere/detect-language.nvim/blob/main/lua/detect-language/init.lua#L73-L79

Instead of reading the whole document as lines and check if it's exceed the threshold, try check it from the last line number.

local last_line = fn.line('$')

if last_line > threshold then
  -- exceed limit
  return
end

local lines = api.nvim_buf_get_lines(0, 0, last_line, false)