Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 03b456e

Browse files
committed
feat: add option to customize sign priority(#19)
1 parent 4383e5c commit 03b456e

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ let g:space_before_virtual_text = 5
100100
let g:diagnostic_show_sign = 0
101101
```
102102

103+
- The default priority of the diagnostic sign is 20. You can customize it by
104+
105+
```vim
106+
let g:diagnostic_sign_priority = 20
107+
```
108+
103109
- Make sure to use the latest branch of Neovim which has sign support.
104110

105111
- If you want to change the symbols of sign, use `sign_define` to change it

lua/diagnostic.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function M.publish_diagnostics(bufnr)
7777
util.buf_diagnostics_save_positions(bufnr, result.diagnostics)
7878
vim.lsp.util.buf_diagnostics_underline(bufnr, result.diagnostics)
7979
if vim.api.nvim_get_var('diagnostic_show_sign') == 1 then
80-
vim.lsp.util.buf_diagnostics_signs(bufnr, result.diagnostics)
80+
util.buf_diagnostics_signs(bufnr, result.diagnostics)
8181
end
8282
if vim.api.nvim_get_var('diagnostic_enable_virtual_text') == 1 then
8383
util.buf_diagnostics_virtual_text(bufnr, result.diagnostics)

lua/diagnostic/util.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,14 @@ function M.buf_diagnostics_virtual_text(bufnr, diagnostics)
103103
end
104104

105105
function M.buf_diagnostics_signs(bufnr, diagnostics)
106-
vim.fn.sign_define('LspDiagnosticsErrorSign', {text=vim.g['LspDiagnosticsErrorSign'] or 'E', texthl='LspDiagnosticsError', linehl='', numhl=''})
107-
vim.fn.sign_define('LspDiagnosticsWarningSign', {text=vim.g['LspDiagnosticsWarningSign'] or 'W', texthl='LspDiagnosticsWarning', linehl='', numhl=''})
108-
vim.fn.sign_define('LspDiagnosticsInformationSign', {text=vim.g['LspDiagnosticsInformationSign'] or 'I', texthl='LspDiagnosticsInformation', linehl='', numhl=''})
109-
vim.fn.sign_define('LspDiagnosticsHintSign', {text=vim.g['LspDiagnosticsHintSign'] or 'H', texthl='LspDiagnosticsHint', linehl='', numhl=''})
110-
111106
for _, diagnostic in ipairs(diagnostics) do
112107
local diagnostic_severity_map = {
113108
[protocol.DiagnosticSeverity.Error] = "LspDiagnosticsErrorSign";
114109
[protocol.DiagnosticSeverity.Warning] = "LspDiagnosticsWarningSign";
115110
[protocol.DiagnosticSeverity.Information] = "LspDiagnosticsInformationSign";
116111
[protocol.DiagnosticSeverity.Hint] = "LspDiagnosticsHintSign";
117112
}
118-
vim.fn.sign_place(0, sign_ns, diagnostic_severity_map[diagnostic.severity], bufnr, {lnum=(diagnostic.range.start.line+1), priority=50})
113+
vim.fn.sign_place(0, sign_ns, diagnostic_severity_map[diagnostic.severity], bufnr, {lnum=(diagnostic.range.start.line+1), priority=vim.g.diagnostic_sign_priority})
119114
end
120115
end
121116

plugin/diagnostic.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ if ! exists('g:diagnostic_show_sign')
3131
let g:diagnostic_show_sign = 1
3232
endif
3333

34+
if ! exists('g:diagnostic_sign_priority')
35+
let g:diagnostic_sign_priority = 20
36+
endif
37+
3438
if ! exists('g:diagnostic_insert_delay')
3539
let g:diagnostic_insert_delay = 0
3640
endif

0 commit comments

Comments
 (0)