diff --git a/.luarc.json b/.luarc.json index e1b9d70..b4057c8 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,4 +1,7 @@ { - "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", - "Lua.workspace.checkThirdParty": false -} \ No newline at end of file + "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", + "workspace.library": [ + "${3rd}/luv/library", + "${3rd}/luassert/library" + ] +} diff --git a/lua/smoothcursor/callbacks/buffer.lua b/lua/smoothcursor/callbacks/buffer.lua index b21634e..3ae0aa0 100644 --- a/lua/smoothcursor/callbacks/buffer.lua +++ b/lua/smoothcursor/callbacks/buffer.lua @@ -1,28 +1,31 @@ local sc_debug = require('smoothcursor.debug') +-- #require('smoothcursor.callbacks.buffer').buffer + local function create_buffer() return { buffer = {}, - length = 1, - bufnr = 1, -- cache bufnr + length = 0, + bufnr = 0, -- cache bufnr + indexes = {}, push_front = function(self, data) - table.insert(self, 1, data) - table.remove(self, self.length + 1) + table.insert(self.indexes, 1, data) + table.remove(self.indexes, #self.indexes) end, resize_buffer = function(self, size) - local diff = size - self.length + local diff = size - #self.indexes if diff < 0 then for _ = 1, -diff, 1 do - table.remove(self, self.length + 1) + table.remove(self.indexes, #self.indexes) end else for _ = 1, diff, 1 do - table.insert(self, 1, 0) + table.insert(self.indexes, 1, 0) end end - self.length = size + self.length = #self.indexes end, switch_buf = function(self) @@ -31,15 +34,15 @@ local function create_buffer() end, all = function(self, value) - for i = 1, self.length, 1 do - self[i] = value + for i = 1, #self.indexes, 1 do + self.indexes[i] = value end end, is_stay_still = function(self) - local first_val = self[1] - for i = 2, self.length do - if first_val ~= self[i] then + local first_val = self.indexes[1] + for i = 2, #self.indexes do + if first_val ~= self.indexes[i] then return false end end @@ -51,12 +54,19 @@ end local function buffer_metatable() return { __index = function(t, k) + if t.indexes[k] ~= nil then + return t.indexes[k] + end if t.buffer[t.bufnr] == nil then t.buffer[t.bufnr] = {} end return t.buffer[t.bufnr][k] end, __newindex = function(t, k, v) + if t.indexes[k] ~= nil then + t.indexes[k] = v + return + end if t.buffer[t.bufnr] == nil then t.buffer[t.bufnr] = {} end diff --git a/lua/smoothcursor/callbacks/init.lua b/lua/smoothcursor/callbacks/init.lua index adb89d0..4fd5a00 100644 --- a/lua/smoothcursor/callbacks/init.lua +++ b/lua/smoothcursor/callbacks/init.lua @@ -13,19 +13,21 @@ local function init() end end ----@param value integer | nil +---@param value? integer local function buffer_set_all(value) if value == nil then value = vim.fn.getcurpos(vim.fn.win_getid())[2] end buffer['prev'] = value buffer:all(value) + + -- Debug debug_callback(buffer, { 'Buffer Reset' }, function() sc_debug.reset_counter = sc_debug.reset_counter + 1 end) end ---- @param with_timer_stop? boolean +---@param with_timer_stop? boolean local function unplace_signs(with_timer_stop) if with_timer_stop == true then sc_timer:abort() @@ -36,7 +38,7 @@ end -- place 'name' sign to the 'position' ---@param position number ----@param name string +---@param name? string local function place_sign(position, name) position = math.floor(position + 0.5) if position < buffer['w0'] or position > buffer['w$'] then diff --git a/lua/smoothcursor/callbacks/timer.lua b/lua/smoothcursor/callbacks/timer.lua index 894e9ba..f2f0f6c 100644 --- a/lua/smoothcursor/callbacks/timer.lua +++ b/lua/smoothcursor/callbacks/timer.lua @@ -13,7 +13,7 @@ function ScTimer:post(func) if self.is_running then return end - vim.loop.timer_start(self.timer, 0, config.config.intervals, vim.schedule_wrap(func)) + vim.uv.timer_start(self.timer, 0, config.config.intervals, vim.schedule_wrap(func)) self.is_running = true end diff --git a/plugin/smoothcursor.lua b/plugin/smoothcursor.lua index 748713b..835aba1 100644 --- a/plugin/smoothcursor.lua +++ b/plugin/smoothcursor.lua @@ -35,3 +35,5 @@ vim.api.nvim_create_user_command('SmoothCursorStatus', function() end, {}) vim.api.nvim_create_user_command('SmoothCursorDeleteSigns', utils.smoothcursor_delete_signs, {}) + +vim.api.nvim_create_user_command('SmoothCursorDebug', require('smoothcursor.debug').debug, {})