From dc17e00484d9dd105b78b1fc791fd0be85329e69 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Mon, 13 Jan 2025 09:34:25 +0800 Subject: [PATCH] fix(diagnostic): only set on displayByVimDiagnostic Closes #5242 --- src/__tests__/modules/diagnosticManager.test.ts | 3 +-- src/diagnostic/buffer.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/__tests__/modules/diagnosticManager.test.ts b/src/__tests__/modules/diagnosticManager.test.ts index 4e4f9ee89fa..8faf9323c14 100644 --- a/src/__tests__/modules/diagnosticManager.test.ts +++ b/src/__tests__/modules/diagnosticManager.test.ts @@ -152,6 +152,7 @@ describe('diagnostic manager', () => { await nvim.call('cursor', [1, 3]) await helper.wait(30) markers = await doc.buffer.getExtMarks(virtualTextSrcId, 0, -1, { details: true }) + console.error(markers) expect(markers.length).toBe(0) }) }) @@ -687,8 +688,6 @@ describe('diagnostic manager', () => { await manager.toggleDiagnosticBuffer(doc.bufnr, 1) res = await buf.getVar('coc_diagnostic_info') as any expect(res.error).toBe(2) - let items = await buf.getVar('coc_diagnostic_map') as any - expect(items.length).toBe(5) }) }) diff --git a/src/diagnostic/buffer.ts b/src/diagnostic/buffer.ts index cfaeabd8bf8..21a45ceeef6 100644 --- a/src/diagnostic/buffer.ts +++ b/src/diagnostic/buffer.ts @@ -420,7 +420,7 @@ export class DiagnosticBuffer implements SyncItem { nvim.resumeNotification(true, true) } else if (displayByVimDiagnostic) { nvim.pauseNotification() - this.setDiagnosticInfo() + this.setDiagnosticMap() nvim.resumeNotification(true, true) } else { let emptyCollections: string[] = [] @@ -488,7 +488,6 @@ export class DiagnosticBuffer implements SyncItem { public setDiagnosticInfo(): void { let lnums = [0, 0, 0, 0] let info = { error: 0, warning: 0, information: 0, hint: 0, lnums } - let items: DiagnosticItem[] = [] for (let diagnostics of this.diagnosticsMap.values()) { for (let diagnostic of diagnostics) { let lnum = diagnostic.range.start.line + 1 @@ -509,7 +508,17 @@ export class DiagnosticBuffer implements SyncItem { lnums[0] = lnums[0] ? Math.min(lnums[0], lnum) : lnum info.error = info.error + 1 } + } + } + let buf = this.nvim.createBuffer(this.bufnr) + buf.setVar('coc_diagnostic_info', info, true) + this.nvim.call('coc#util#do_autocmd', ['CocDiagnosticChange'], true) + } + public setDiagnosticMap(): void { + let items: DiagnosticItem[] = [] + for (let diagnostics of this.diagnosticsMap.values()) { + for (let diagnostic of diagnostics) { let { start, end } = diagnostic.range items.push({ file: URI.parse(this.doc.uri).fsPath, @@ -523,12 +532,10 @@ export class DiagnosticBuffer implements SyncItem { severity: getSeverityName(diagnostic.severity), level: diagnostic.severity ?? 0, location: Location.create(this.doc.uri, diagnostic.range) - }) } } let buf = this.nvim.createBuffer(this.bufnr) - buf.setVar('coc_diagnostic_info', info, true) buf.setVar('coc_diagnostic_map', items, true) this.nvim.call('coc#util#do_autocmd', ['CocDiagnosticChange'], true) }