diff --git a/data/schema.json b/data/schema.json index 0fa0cdd6d25..bab067ea8be 100644 --- a/data/schema.json +++ b/data/schema.json @@ -533,6 +533,11 @@ "description": "Use NeoVim virtual text to display diagnostics", "default": false }, + "diagnostic.virtualTextCurrentLineOnly": { + "type": "boolean", + "description": "Only show virtualText diagnostic on current cursor line", + "default": "true" + }, "diagnostic.virtualTextPrefix": { "type": "string", "description": "The prefix added virtual text diagnostics", diff --git a/doc/coc.txt b/doc/coc.txt index 3d89694fb43..715149b413a 100644 --- a/doc/coc.txt +++ b/doc/coc.txt @@ -330,6 +330,10 @@ Built-in configurations:~ Use Neovim virtual text to display diagnostics, default: `false` +"diagnostic.virtualTextCurrentLineOnly":~ + + Only show virtualText diagnostic on current cursor line, default: true + "diagnostic.virtualTextPrefix":~ The prefix added for virtual text diagnostics, default: `" "` diff --git a/src/__tests__/modules/diagnosticBuffer.test.ts b/src/__tests__/modules/diagnosticBuffer.test.ts index 8d1ac220fbc..f691629c929 100644 --- a/src/__tests__/modules/diagnosticBuffer.test.ts +++ b/src/__tests__/modules/diagnosticBuffer.test.ts @@ -19,6 +19,7 @@ const config: DiagnosticConfig = { refreshOnInsertMode: false, virtualTextSrcId: 0, virtualText: false, + virtualTextCurrentLineOnly: true, virtualTextPrefix: " ", virtualTextLines: 3, virtualTextLineSeparator: " \\ ", diff --git a/src/diagnostic/buffer.ts b/src/diagnostic/buffer.ts index 2891bd16a09..f937f513303 100644 --- a/src/diagnostic/buffer.ts +++ b/src/diagnostic/buffer.ts @@ -178,10 +178,13 @@ export class DiagnosticBuffer implements Disposable { let buffer = this.nvim.createBuffer(bufnr) let srcId = this.config.virtualTextSrcId let prefix = this.config.virtualTextPrefix - let diagnostics = this.diagnostics.filter(d => { - let { start, end } = d.range - return start.line <= lnum - 1 && end.line >= lnum - 1 - }) + let diagnostics = this.diagnostics + if (this.config.virtualTextCurrentLineOnly) { + diagnostics = this.diagnostics.filter(d => { + let { start, end } = d.range + return start.line <= lnum - 1 && end.line >= lnum - 1 + }) + } buffer.clearNamespace(srcId) for (let diagnostic of diagnostics) { let { line } = diagnostic.range.start diff --git a/src/diagnostic/manager.ts b/src/diagnostic/manager.ts index b8ec0eeeb9c..73dc25d1760 100644 --- a/src/diagnostic/manager.ts +++ b/src/diagnostic/manager.ts @@ -21,7 +21,6 @@ export interface DiagnosticConfig { enableHighlightLineNumber: boolean checkCurrentLine: boolean enableMessage: string - virtualText: boolean displayByAle: boolean srcId: number locationlist: boolean @@ -38,6 +37,8 @@ export interface DiagnosticConfig { maxWindowWidth: number refreshAfterSave: boolean refreshOnInsertMode: boolean + virtualText: boolean + virtualTextCurrentLineOnly: boolean virtualTextSrcId: number virtualTextPrefix: string virtualTextLines: number @@ -73,7 +74,7 @@ export class DiagnosticManager implements Disposable { }, this.config.messageDelay) }, null, this.disposables) - if (this.config.virtualText) { + if (this.config.virtualText && this.config.virtualTextCurrentLineOnly) { let fn = debounce(async (bufnr, cursor) => { let buf = this.buffers.find(buf => buf.bufnr == bufnr) if (buf) buf.showVirtualText(cursor[0]) @@ -577,6 +578,7 @@ export class DiagnosticManager implements Disposable { joinMessageLines: config.get('joinMessageLines', false), messageDelay: config.get('messageDelay', 200), virtualText: config.get('virtualText', false), + virtualTextCurrentLineOnly: config.get('virtualTextCurrentLineOnly', true), virtualTextPrefix: config.get('virtualTextPrefix', " "), virtualTextLineSeparator: config.get('virtualTextLineSeparator', " \\ "), virtualTextLines: config.get('virtualTextLines', 3),