Skip to content

Commit 48bbc13

Browse files
committed
perf: change vim.fn.shiftwidth to get_sw_value
1 parent 2b2ccc0 commit 48bbc13

File tree

7 files changed

+10
-20
lines changed

7 files changed

+10
-20
lines changed

.luacheckrc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ codes = true
44

55
-- Glorious list of warnings: https://luacheck.readthedocs.io/en/stable/warnings.html
66
ignore = {
7-
"212/self", -- Unused argument, In the case of callback function
8-
"212/mod",
9-
"111/_",
10-
"122/vim",
11-
"112",
12-
"111",
137
"631",
148
}
159

lua/hlchunk/mods/base_mod/init.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local class = require("hlchunk.utils.class")
22
local BaseConf = require("hlchunk.mods.base_mod.base_conf")
33
local Scope = require("hlchunk.utils.scope")
4+
local cFunc = require("hlchunk.utils.cFunc")
45

56
local api = vim.api
67
local fn = vim.fn
@@ -67,9 +68,7 @@ end
6768
function BaseMod:shouldRender(bufnr)
6869
if api.nvim_buf_is_valid(bufnr) then
6970
local ft = vim.bo[bufnr].ft
70-
local shiftwidth = api.nvim_buf_call(bufnr, function()
71-
return fn.shiftwidth()
72-
end)
71+
local shiftwidth = cFunc.get_sw(bufnr)
7372
if ft then
7473
return self.conf.enable and not self.conf.exclude_filetypes[ft] and shiftwidth ~= 0
7574
end
@@ -178,7 +177,7 @@ function BaseMod:setHl()
178177
end
179178

180179
function BaseMod:clearHl()
181-
-- TODO:
180+
self:notify("clearHl not impl")
182181
end
183182

184183
---@param msg string

lua/hlchunk/mods/blank/init.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function BlankMod:renderLine(bufnr, index, blankLen)
4545
priority = self.conf.priority,
4646
}
4747
local leftcol = fn.winsaveview().leftcol --[[@as number]]
48-
local sw = fn.shiftwidth() --[[@as number]]
48+
local sw = cFunc.get_sw(bufnr)
4949
local render_char_num, offset, shadow_char_num = cFunc.calc(blankLen, leftcol, sw)
5050

5151
self:renderLeader(bufnr, index, offset, shadow_char_num, row_opts)
@@ -60,10 +60,7 @@ function BlankMod:renderLine(bufnr, index, blankLen)
6060
row_opts.virt_text_win_col = offset + (i - 1) * sw
6161

6262
-- when use treesitter, without this judge, when paste code will over render
63-
if
64-
row_opts.virt_text_win_col < 0
65-
or row_opts.virt_text_win_col >= cFunc.get_indent(bufnr, index - 1)
66-
then
63+
if row_opts.virt_text_win_col < 0 or row_opts.virt_text_win_col >= cFunc.get_indent(bufnr, index - 1) then
6764
-- if the len of the line is 0, and have leftcol, we should draw it indent by context
6865
if api.nvim_buf_get_lines(bufnr, index - 1, index, false)[1] ~= "" then
6966
return

lua/hlchunk/mods/chunk/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local LoopTask = require("hlchunk.utils.loopTask")
55
local debounce = require("hlchunk.utils.timer").debounce
66
local Pos = require("hlchunk.utils.position")
77
local Scope = require("hlchunk.utils.scope")
8-
local cFunc = require('hlchunk.utils.cFunc')
8+
local cFunc = require("hlchunk.utils.cFunc")
99

1010
local class = require("hlchunk.utils.class")
1111

@@ -179,7 +179,7 @@ function ChunkMod:createAutocmd()
179179
use_treesitter = self.conf.use_treesitter,
180180
})
181181
api.nvim_win_call(winid, function()
182-
self.meta.shiftwidth = api.nvim_get_option_value("shiftwidth", { buf = bufnr })
182+
self.meta.shiftwidth = cFunc.get_sw(bufnr)
183183
self.meta.leftcol = fn.winsaveview().leftcol
184184
end)
185185
if ret_code == CHUNK_RANGE_RET.OK then

lua/hlchunk/mods/indent/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local class = require("hlchunk.utils.class")
44
local indentHelper = require("hlchunk.utils.indentHelper")
55
local Scope = require("hlchunk.utils.scope")
66
local throttle = require("hlchunk.utils.timer").throttle
7+
local cFunc = require("hlchunk.utils.cFunc")
78

89
local api = vim.api
910
local fn = vim.fn
@@ -94,7 +95,7 @@ function IndentMod:createAutocmd()
9495
range.start = math.max(0, range.start - ahead_lines)
9596
range.finish = math.min(api.nvim_buf_line_count(bufnr) - 1, range.finish + ahead_lines)
9697
api.nvim_win_call(winid, function()
97-
self.meta.shiftwidth = api.nvim_get_option_value("shiftwidth", { buf = bufnr })
98+
self.meta.shiftwidth = cFunc.get_sw(bufnr)
9899
self.meta.leftcol = fn.winsaveview().leftcol
99100
self:render(range)
100101
end)

lua/hlchunk/utils/indentHelper.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local fn = vim.fn
2-
local cFunc = require('hlchunk.utils.cFunc')
2+
local cFunc = require("hlchunk.utils.cFunc")
33

44
-- get the virtual indent of the given line
55
---@param rows_indent table<number, number>

test/spec.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
vim.api.nvim_command([[set rtp+=.]])
22

3-
vim.opt.swapfile = false
43
local cwd = vim.fn.getcwd()
54

65
vim.api.nvim_command(string.format([[set rtp+=%s,%s/test]], cwd, cwd))

0 commit comments

Comments
 (0)