From 457b8cd9c4cffc4bc615979e8cbba79d6d101883 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Tue, 27 Aug 2024 20:28:15 +0800 Subject: [PATCH] fix(handler): correct current winid Closes #5116 --- autoload/coc/window.vim | 6 +++--- src/handler/inlayHint/buffer.ts | 2 +- src/handler/semanticTokens/buffer.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/coc/window.vim b/autoload/coc/window.vim index 0c0e4325f87..299b09fd009 100644 --- a/autoload/coc/window.vim +++ b/autoload/coc/window.vim @@ -194,9 +194,9 @@ function! coc#window#close(winid) abort endif endfunction -function! coc#window#visible_range(bufnr) abort - let winid = bufwinid(a:bufnr) - if winid == -1 +function! coc#window#visible_range() abort + let winid = win_getid() + if winid == 0 return v:null endif let info = getwininfo(winid)[0] diff --git a/src/handler/inlayHint/buffer.ts b/src/handler/inlayHint/buffer.ts index 620a83547e5..22952970d51 100644 --- a/src/handler/inlayHint/buffer.ts +++ b/src/handler/inlayHint/buffer.ts @@ -176,7 +176,7 @@ export default class InlayHintBuffer implements SyncItem { if ((events.insertMode && !this.config.refreshOnInsertMode) || !this.enabled) return this.tokenSource = new CancellationTokenSource() let token = this.tokenSource.token - let res = await this.nvim.call('coc#window#visible_range', [this.doc.bufnr]) as [number, number] + let res = await this.nvim.call('coc#window#visible_range') as [number, number] if (!Array.isArray(res) || res[1] <= 0 || token.isCancellationRequested) return if (!srcId) srcId = await this.nvim.createNamespace('coc-inlayHint') if (token.isCancellationRequested || this.regions.has(res[0], res[1])) return diff --git a/src/handler/semanticTokens/buffer.ts b/src/handler/semanticTokens/buffer.ts index 87a63abcfb8..a3a06d5e879 100644 --- a/src/handler/semanticTokens/buffer.ts +++ b/src/handler/semanticTokens/buffer.ts @@ -423,7 +423,7 @@ export default class SemanticTokensBuffer implements SyncItem { */ public async requestRangeHighlights(token: CancellationToken): Promise { let { nvim, doc } = this - let region = await nvim.call('coc#window#visible_range', [this.bufnr]) as [number, number] + let region = await nvim.call('coc#window#visible_range') as [number, number] if (!region || token.isCancellationRequested) return null let endLine = Math.min(region[0] + workspace.env.lines * 2, region[1] + workspace.env.lines, doc.lineCount) let range = Range.create(region[0] - 1, 0, endLine, 0)