Skip to content

Commit

Permalink
Add virtualTextCurrentLineOnly option (#1865)
Browse files Browse the repository at this point in the history
* Add virtualTextCurrentLineOnly option

Allows the user to restore previous behavior setting it false

* Add virtualTextCurrentLineOnly to doc

* Fix review
  • Loading branch information
Avi-D-coder authored May 8, 2020
1 parent c24c3d5 commit bfe134b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: `" "`
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/modules/diagnosticBuffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const config: DiagnosticConfig = {
refreshOnInsertMode: false,
virtualTextSrcId: 0,
virtualText: false,
virtualTextCurrentLineOnly: true,
virtualTextPrefix: " ",
virtualTextLines: 3,
virtualTextLineSeparator: " \\ ",
Expand Down
11 changes: 7 additions & 4 deletions src/diagnostic/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/diagnostic/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface DiagnosticConfig {
enableHighlightLineNumber: boolean
checkCurrentLine: boolean
enableMessage: string
virtualText: boolean
displayByAle: boolean
srcId: number
locationlist: boolean
Expand All @@ -38,6 +37,8 @@ export interface DiagnosticConfig {
maxWindowWidth: number
refreshAfterSave: boolean
refreshOnInsertMode: boolean
virtualText: boolean
virtualTextCurrentLineOnly: boolean
virtualTextSrcId: number
virtualTextPrefix: string
virtualTextLines: number
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -577,6 +578,7 @@ export class DiagnosticManager implements Disposable {
joinMessageLines: config.get<boolean>('joinMessageLines', false),
messageDelay: config.get<number>('messageDelay', 200),
virtualText: config.get<boolean>('virtualText', false),
virtualTextCurrentLineOnly: config.get<boolean>('virtualTextCurrentLineOnly', true),
virtualTextPrefix: config.get<string>('virtualTextPrefix', " "),
virtualTextLineSeparator: config.get<string>('virtualTextLineSeparator', " \\ "),
virtualTextLines: config.get<number>('virtualTextLines', 3),
Expand Down

0 comments on commit bfe134b

Please sign in to comment.