Skip to content

Commit

Permalink
feat(diagnostic): add highlight group for virtualText
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Jun 5, 2019
1 parent 32f5551 commit ebae7b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
9 changes: 9 additions & 0 deletions autoload/coc/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -890,3 +890,12 @@ function! coc#util#pclose()
endif
endfor
endfunction

function! coc#util#init_virtual_hl()
let names = ['Error', 'Warning', 'Info', 'Hint']
for name in names
if !hlexists('Coc'.name.'VirtualText')
exe 'hi default link Coc'.name.'VirtualText Coc'.name.'Sign'
endif
endfor
endfunction
24 changes: 24 additions & 0 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,30 @@ CocHintSign *CocHintSign*

The highlight used for hint signs.

CocErrorVirtualText *CocErrorVirtualText*

Default: `hi default link CocErrorVirtualText CocErrorSign`

The highlight used for error signs.

CocWarningVirtualText *CocWarningVirtualText*

Default: `hi default link CocWarningVirtualText CocWarningSign`

The highlight used for warning signs.

CocInfoVirtualText *CocInfoVirtualText*

Default: `hi default link CocInfoVirtualText CocInfoSign`

The highlight used for information signs.

CocHintVirtualText *CocHintVirtualText*

Default: `hi default link CocHintVirtualText CocHintSign`

The highlight used for hint signs.

CocErrorHighlight *CocErrorHighlight*

Default: `hi default link CocErrorHighlight CocUnderline`
Expand Down
19 changes: 13 additions & 6 deletions src/diagnostic/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ export class DiagnosticManager implements Disposable {
this.setConfiguration(e)
}, null, this.disposables)

let { errorSign, warningSign, infoSign, hintSign } = this.config
nvim.command(`sign define CocError text=${errorSign} linehl=CocErrorLine texthl=CocErrorSign`, true)
nvim.command(`sign define CocWarning text=${warningSign} linehl=CocWarningLine texthl=CocWarningSign`, true)
nvim.command(`sign define CocInfo text=${infoSign} linehl=CocInfoLine texthl=CocInfoSign`, true)
nvim.command(`sign define CocHint text=${hintSign} linehl=CocHintLine texthl=CocHintSign`, true)

// create buffers
for (let doc of workspace.documents) {
this.createDiagnosticBuffer(doc)
Expand All @@ -150,6 +144,19 @@ export class DiagnosticManager implements Disposable {
workspace.configurations.onError(async () => {
this.setConfigurationErrors()
}, null, this.disposables)

let { errorSign, warningSign, infoSign, hintSign } = this.config
nvim.pauseNotification()
nvim.command(`sign define CocError text=${errorSign} linehl=CocErrorLine texthl=CocErrorSign`, true)
nvim.command(`sign define CocWarning text=${warningSign} linehl=CocWarningLine texthl=CocWarningSign`, true)
nvim.command(`sign define CocInfo text=${infoSign} linehl=CocInfoLine texthl=CocInfoSign`, true)
nvim.command(`sign define CocHint text=${hintSign} linehl=CocHintLine texthl=CocHintSign`, true)
if (this.config.virtualText) {
nvim.call('coc#util#init_virtual_hl', [], true)
}
nvim.resumeNotification(false, true).catch(_e => {
// noop
})
}

private createDiagnosticBuffer(doc: Document): void {
Expand Down

0 comments on commit ebae7b9

Please sign in to comment.