Skip to content

Commit

Permalink
feat:stop rendering when edit big file shellRaining#85
Browse files Browse the repository at this point in the history
add new options choke_at_linecount
check_choke
  • Loading branch information
PostCyberPunk committed Jan 31, 2024
1 parent 1d4d8b4 commit 7b5f433
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lua/hlchunk/base_mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local fn = vim.fn
---@field exclude_filetypes table<string, boolean>
---@field support_filetypes table<string>
---@field notify boolean
---@field choke_at_linecount number

---@class RuntimeVar
---@field old_win_info table<number, number>
Expand Down Expand Up @@ -36,6 +37,7 @@ local BaseMod = {
exclude_filetypes = {},
support_filetypes = {},
notify = false,
choke_at_linecount = -1,
},
ns_id = -1,
old_win_info = fn.winsaveview(),
Expand Down Expand Up @@ -181,6 +183,13 @@ function BaseMod:set_hl()
end
end

function BaseMod:check_choke(line_count)
if self.options.choke_at_linecount ~= -1 and line_count >= self.options.choke_at_linecount then
return true
else
return false
end
end
-- set options for mod, if the mod dont have default config, it will notify you
---@param options BaseModOpts
function BaseMod:set_options(options)
Expand Down
8 changes: 7 additions & 1 deletion lua/hlchunk/mods/blank.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local blank_mod = BaseMod:new({
api.nvim_get_hl(0, { name = "Whitespace" }),
},
exclude_filetypes = ft.exclude_filetypes,
choke_at_linecount = -1,
},
})

Expand Down Expand Up @@ -60,7 +61,12 @@ function blank_mod:render_line(index, indent)
end

function blank_mod:render()
if (not self.options.enable) or self.options.exclude_filetypes[vim.bo.filetype] or fn.shiftwidth() == 0 then
if
not self.options.enable
or self.options.exclude_filetypes[vim.bo.filetype]
or fn.shiftwidth() == 0
or BaseMod.check_choke(self, vim.api.nvim_buf_line_count(0))
then
return
end

Expand Down
7 changes: 6 additions & 1 deletion lua/hlchunk/mods/chunk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local chunk_mod = BaseMod:new({
textobject = "",
max_file_size = 1024 * 1024,
error_sign = true,
choke_at_linecount = -1,
},
})

Expand All @@ -49,7 +50,11 @@ end

-- set new virtual text to the right place
function chunk_mod:render(opts)
if not self.options.enable or self.options.exclude_filetypes[vim.bo.ft] then
if
not self.options.enable
or self.options.exclude_filetypes[vim.bo.ft]
or BaseMod.check_choke(self, vim.api.nvim_buf_line_count(0))
then
return
end

Expand Down
7 changes: 6 additions & 1 deletion lua/hlchunk/mods/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ local context_mod = BaseMod:new({
"#806d9c",
},
exclude_filetypes = ft.exclude_filetypes,
choke_at_linecount = -1,
},
})

function context_mod:render()
if (not self.options.enable) or self.options.exclude_filetypes[vim.bo.filetype] then
if
not self.options.enable
or self.options.exclude_filetypes[vim.bo.filetype]
or BaseMod.check_choke(self, vim.api.nvim_buf_line_count(0))
then
return
end

Expand Down
8 changes: 7 additions & 1 deletion lua/hlchunk/mods/indent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local indent_mod = BaseMod:new({
fn.synIDattr(fn.synIDtrans(fn.hlID("Whitespace")), "fg", "gui"),
},
exclude_filetypes = ft.exclude_filetypes,
choke_at_linecount = -1,
},
})

Expand Down Expand Up @@ -67,7 +68,12 @@ function indent_mod:render_line(index, indent)
end

function indent_mod:render()
if (not self.options.enable) or self.options.exclude_filetypes[vim.bo.filetype] or fn.shiftwidth() == 0 then
if
not self.options.enable
or self.options.exclude_filetypes[vim.bo.filetype]
or fn.shiftwidth() == 0
or BaseMod.check_choke(self, vim.api.nvim_buf_line_count(0))
then
return
end

Expand Down
7 changes: 6 additions & 1 deletion lua/hlchunk/mods/line_num.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ local line_num_mod = BaseMod:new({
style = "#806d9c",
support_filetypes = ft.support_filetypes,
exclude_filetypes = ft.exclude_filetypes,
choke_at_linecount = -1,
},
})

function line_num_mod:render()
if not self.options.enable or self.options.exclude_filetypes[vim.bo.ft] then
if
not self.options.enable
or self.options.exclude_filetypes[vim.bo.ft]
or BaseMod.check_choke(self, vim.api.nvim_buf_line_count(0))
then
return
end

Expand Down

0 comments on commit 7b5f433

Please sign in to comment.