A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neovim/neovim/commit/b680392687eeaee521b19d79a1e7effdc2dc1ed7 below:

skip or reduce debounce after idle (#16881) · neovim/neovim@b680392 · GitHub

File tree Expand file treeCollapse file tree 1 file changed

+35

-4

lines changed

Filter options

Expand file treeCollapse file tree 1 file changed

+35

-4

lines changed Original file line number Diff line number Diff line change

@@ -306,7 +306,6 @@ local function once(fn)

306 306

end

307 307

end

308 308 309 - 310 309

local changetracking = {}

311 310

do

312 311

--@private

@@ -327,6 +326,7 @@ do

327 326

if not state then

328 327

state = {

329 328

pending_changes = {};

329 +

last_flush = {};

330 330

use_incremental_sync = (

331 331

if_nil(client.config.flags.allow_incremental_sync, true)

332 332

and client.resolved_capabilities.text_document_did_change == protocol.TextDocumentSyncKind.Incremental

@@ -347,8 +347,11 @@ do

347 347

function changetracking.reset_buf(client, bufnr)

348 348

changetracking.flush(client)

349 349

local state = state_by_client[client.id]

350 -

if state and state.buffers then

351 -

state.buffers[bufnr] = nil

350 +

if state then

351 +

if state.buffers then

352 +

state.buffers[bufnr] = nil

353 +

end

354 +

state.last_flush = {}

352 355

end

353 356

end

354 357

@@ -361,6 +364,33 @@ do

361 364

end

362 365

end

363 366 367 +

---@private

368 +

--

369 +

-- Adjust debounce time by taking time of last didChange notification into

370 +

-- consideration. If the last didChange happened more than `debounce` time ago,

371 +

-- debounce can be skipped and otherwise maybe reduced.

372 +

--

373 +

-- This turns the debounce into a kind of client rate limiting

374 +

local function next_debounce(debounce, state, bufnr)

375 +

if debounce == 0 then

376 +

return 0

377 +

end

378 +

local ns_to_ms = 0.000001

379 +

local last_flush = state.last_flush[bufnr]

380 +

if not last_flush then

381 +

return debounce

382 +

end

383 +

local now = uv.hrtime()

384 +

local ms_since_last_flush = (now - last_flush) * ns_to_ms

385 +

local remaining_debounce = debounce - ms_since_last_flush

386 +

if remaining_debounce > 0 then

387 +

return remaining_debounce

388 +

else

389 +

state.last_flush[bufnr] = now

390 +

return 0

391 +

end

392 +

end

393 + 364 394

---@private

365 395

function changetracking.prepare(bufnr, firstline, lastline, new_lastline)

366 396

local incremental_changes = function(client)

@@ -383,7 +413,7 @@ do

383 413

return

384 414

end

385 415

local state = state_by_client[client.id]

386 -

local debounce = client.config.flags.debounce_text_changes or 150

416 +

local debounce = next_debounce(client.config.flags.debounce_text_changes or 150, state, bufnr)

387 417

if debounce == 0 then

388 418

local changes = state.use_incremental_sync and incremental_changes(client) or full_changes()

389 419

client.notify("textDocument/didChange", {

@@ -406,6 +436,7 @@ do

406 436

end

407 437

state.pending_change = function()

408 438

state.pending_change = nil

439 +

state.last_flush[bufnr] = uv.hrtime()

409 440

if client.is_stopped() or not vim.api.nvim_buf_is_valid(bufnr) then

410 441

return

411 442

end

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4