Skip to content

Commit 8a2c5b6

Browse files
committed
feat: implement two-phase activity update debouncing
- Add `delay` and `interval` config fields to optimize performance and prevent stale data. - Heavily refactor ActivityManager into modular classes.
1 parent 08b12a1 commit 8a2c5b6

File tree

3 files changed

+738
-498
lines changed

3 files changed

+738
-498
lines changed

.github/wiki/Configuration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ If you want a fresh start, you can copy the default config and tweak it. I sugge
112112
autocmds = true,
113113
cursor_update = 'on_hold',
114114
match_in_mappings = true,
115+
debounce = {
116+
delay = 100,
117+
interval = 1000,
118+
},
115119
},
116120
server = {
117121
update = 'fetch',
@@ -402,6 +406,8 @@ require('cord').setup {
402406
| `advanced.plugin.autocmds` | `boolean` | `true` | Enable autocmds |
403407
| `advanced.plugin.cursor_update` | `string` | `'on_hold'` | When to update cursor position: `'on_move'`, `'on_hold'`, or `'none'`. See [Cursor Update Mode](#cursor-update-mode) |
404408
| `advanced.plugin.match_in_mappings` | `boolean` | `true` | Whether to match against file extensions in mappings |
409+
| `advanced.plugin.debounce.delay` | `integer` | `50` | Delay in milliseconds before sending the first update. Allows events received in quick succession (e.g., buffer switches) to settle before sending data. Set to 0 to disable. |
410+
| `advanced.plugin.debounce.interval` | `integer` | `750` | Minimum interval in milliseconds between updates. Prevents flooding the server during rapid cursor movement. Set to 0 to disable. |
405411

406412
### Server Settings
407413

lua/cord/api/config/init.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ local logger = require 'cord.api.log'
8989
---@field autocmds? boolean Whether to enable autocmds
9090
---@field cursor_update? string Cursor update mode
9191
---@field match_in_mappings? boolean Whether to match against file extensions in mappings
92+
---@field debounce? CordAdvancedDebounceConfig Debounce/throttle configuration for activity updates
93+
94+
---@class CordAdvancedDebounceConfig
95+
---@field delay? integer Delay in milliseconds before sending the first update. Allows events received in quick succession (e.g., buffer switches) to settle before sending data. Set to 0 to disable.
96+
---@field interval? integer Minimum interval in milliseconds between updates. Prevents flooding the server during rapid cursor movement. Set to 0 to disable.
9297

9398
---@class CordAdvancedServerConfig
9499
---@field update? 'fetch'|'install'|'build'|'none'|string How to acquire the server executable: 'fetch' or 'install' or 'build' or 'none'
@@ -130,10 +135,10 @@ local logger = require 'cord.api.log'
130135
---@field plugins? string[]|table<string, table>[] Plugin configuration
131136
---@field advanced? CordAdvancedConfig Advanced configuration
132137

133-
---@class CordConfig
138+
---@class InternalCordConfig: CordConfig
134139
local M = {}
135140

136-
---@class CordConfig
141+
---@type CordConfig
137142
local defaults = {
138143
enabled = true,
139144
log_level = vim.log.levels.OFF,
@@ -204,6 +209,10 @@ local defaults = {
204209
autocmds = true,
205210
cursor_update = 'on_hold',
206211
match_in_mappings = true,
212+
debounce = {
213+
delay = 50,
214+
interval = 750,
215+
},
207216
},
208217
server = {
209218
update = 'fetch',
@@ -403,6 +412,9 @@ local rules = {
403412
['advanced.plugin.autocmds'] = { 'boolean' },
404413
['advanced.plugin.cursor_update'] = { 'string' },
405414
['advanced.plugin.match_in_mappings'] = { 'boolean' },
415+
['advanced.plugin.debounce'] = { 'table' },
416+
['advanced.plugin.debounce.delay'] = { 'number' },
417+
['advanced.plugin.debounce.interval'] = { 'number' },
406418
['advanced.server'] = { 'table' },
407419
['advanced.server.update'] = { 'string' },
408420
['advanced.server.pipe_path'] = { 'string' },

0 commit comments

Comments
 (0)