Skip to content

Commit

Permalink
fix: don't debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed May 28, 2024
1 parent e7d0aab commit 955bcde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 197 deletions.
26 changes: 11 additions & 15 deletions lua/regexplainer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ local component = require 'regexplainer.component'
local tree = require 'regexplainer.utils.treesitter'
local utils = require 'regexplainer.utils'
local Buffers = require 'regexplainer.buffers'
local defer = require 'regexplainer.utils.defer'

local get_node_text = vim.treesitter.get_node_text
local extend = vim.tbl_deep_extend
local deep_extend = vim.tbl_deep_extend
local map = vim.tbl_map
local buf_delete = vim.api.nvim_buf_delete
local ag = vim.api.nvim_create_augroup
local au = vim.api.nvim_create_autocmd
Expand Down Expand Up @@ -73,14 +73,14 @@ local default_config = {
--- During setup(), any user-provided config will be folded in
---@type RegexplainerOptions
--
local local_config = extend('keep', default_config, {})
local local_config = deep_extend('keep', default_config, {})

--- Show the explainer for the regexp under the cursor
---@param options? RegexplainerOptions overrides for this call
---@return nil|number bufnr the bufnr of the regexplaination
--
local function show_for_real(options)
options = extend('force', local_config, options or {})
options = deep_extend('force', local_config, options or {})
local node, scratchnr, error = tree.get_regexp_pattern_at_cursor()

if error and options.debug then
Expand Down Expand Up @@ -114,10 +114,6 @@ end

local disable_auto = false

local show_debounced_trailing, timer_trailing = defer.debounce_trailing(show_for_real, 5)

Buffers.register_timer(timer_trailing)

local M = {}

--- Show the explainer for the regexp under the cursor
Expand All @@ -135,7 +131,7 @@ function M.yank(options)
if type(options) == 'string' then
options = { register = options }
end
show_for_real(vim.tbl_deep_extend('force', options, { display = 'register' }))
show_for_real(deep_extend('force', options, { display = 'register' }))
disable_auto = false
end

Expand All @@ -144,16 +140,16 @@ end
---@return nil
--
function M.setup(config)
local_config = vim.tbl_deep_extend('keep', config or {}, default_config)
local_config = deep_extend('keep', config or {}, default_config)

-- bind keys from config
local has_which_key = pcall(require, 'which-key')
for cmd, binding in pairs(local_config.mappings) do
local command = ':' .. config_command_map[cmd][1] .. '<CR>'
for cmdmap, binding in pairs(local_config.mappings) do
local cmd, description = unpack(config_command_map[cmdmap])
local command = ':' .. cmd .. '<CR>'

if has_which_key then
local wk = require 'which-key'
local description = config_command_map[cmd][2]
wk.register({ [binding] = { command, description } }, { mode = 'n' })
else
utils.map('n', binding, command)
Expand All @@ -165,10 +161,10 @@ function M.setup(config)
ag(augroup_name, { clear = true })
au('CursorMoved', {
group = 'Regexplainer',
pattern = vim.tbl_map(function(x) return '*.' .. x end, local_config.filetypes),
pattern = map(function(x) return '*.' .. x end, local_config.filetypes),
callback = function()
if tree.has_regexp_at_cursor() and not disable_auto then
show_debounced_trailing()
show_for_real()
end
end,
})
Expand Down
182 changes: 0 additions & 182 deletions lua/regexplainer/utils/defer.lua

This file was deleted.

0 comments on commit 955bcde

Please sign in to comment.