Skip to content

Commit

Permalink
fix(diagnostic): only set on displayByVimDiagnostic
Browse files Browse the repository at this point in the history
Closes #5242
  • Loading branch information
fannheyward committed Jan 13, 2025
1 parent 674482c commit dc17e00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/__tests__/modules/diagnosticManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand Down Expand Up @@ -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)
})
})

Expand Down
15 changes: 11 additions & 4 deletions src/diagnostic/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down

0 comments on commit dc17e00

Please sign in to comment.