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

Commit

Permalink
feat: add option to customize sign priority(#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
haorenW1025 committed May 14, 2020
1 parent 4383e5c commit 03b456e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ let g:space_before_virtual_text = 5
let g:diagnostic_show_sign = 0
```

- The default priority of the diagnostic sign is 20. You can customize it by

```vim
let g:diagnostic_sign_priority = 20
```

- Make sure to use the latest branch of Neovim which has sign support.

- If you want to change the symbols of sign, use `sign_define` to change it
Expand Down
2 changes: 1 addition & 1 deletion lua/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function M.publish_diagnostics(bufnr)
util.buf_diagnostics_save_positions(bufnr, result.diagnostics)
vim.lsp.util.buf_diagnostics_underline(bufnr, result.diagnostics)
if vim.api.nvim_get_var('diagnostic_show_sign') == 1 then
vim.lsp.util.buf_diagnostics_signs(bufnr, result.diagnostics)
util.buf_diagnostics_signs(bufnr, result.diagnostics)
end
if vim.api.nvim_get_var('diagnostic_enable_virtual_text') == 1 then
util.buf_diagnostics_virtual_text(bufnr, result.diagnostics)
Expand Down
7 changes: 1 addition & 6 deletions lua/diagnostic/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,14 @@ function M.buf_diagnostics_virtual_text(bufnr, diagnostics)
end

function M.buf_diagnostics_signs(bufnr, diagnostics)
vim.fn.sign_define('LspDiagnosticsErrorSign', {text=vim.g['LspDiagnosticsErrorSign'] or 'E', texthl='LspDiagnosticsError', linehl='', numhl=''})
vim.fn.sign_define('LspDiagnosticsWarningSign', {text=vim.g['LspDiagnosticsWarningSign'] or 'W', texthl='LspDiagnosticsWarning', linehl='', numhl=''})
vim.fn.sign_define('LspDiagnosticsInformationSign', {text=vim.g['LspDiagnosticsInformationSign'] or 'I', texthl='LspDiagnosticsInformation', linehl='', numhl=''})
vim.fn.sign_define('LspDiagnosticsHintSign', {text=vim.g['LspDiagnosticsHintSign'] or 'H', texthl='LspDiagnosticsHint', linehl='', numhl=''})

for _, diagnostic in ipairs(diagnostics) do
local diagnostic_severity_map = {
[protocol.DiagnosticSeverity.Error] = "LspDiagnosticsErrorSign";
[protocol.DiagnosticSeverity.Warning] = "LspDiagnosticsWarningSign";
[protocol.DiagnosticSeverity.Information] = "LspDiagnosticsInformationSign";
[protocol.DiagnosticSeverity.Hint] = "LspDiagnosticsHintSign";
}
vim.fn.sign_place(0, sign_ns, diagnostic_severity_map[diagnostic.severity], bufnr, {lnum=(diagnostic.range.start.line+1), priority=50})
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})
end
end

Expand Down
4 changes: 4 additions & 0 deletions plugin/diagnostic.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ if ! exists('g:diagnostic_show_sign')
let g:diagnostic_show_sign = 1
endif

if ! exists('g:diagnostic_sign_priority')
let g:diagnostic_sign_priority = 20
endif

if ! exists('g:diagnostic_insert_delay')
let g:diagnostic_insert_delay = 0
endif
Expand Down

0 comments on commit 03b456e

Please sign in to comment.