Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 6be9ca2

Browse files
ram02zlukas-reineke
authored andcommitted
refactor!: use vim.diagnostic for lsp provider
BREAKING CHANGE: The `diagnostics_exist` utility function now takes an integer containing the diagnostic severity instead of a string. For more info, do `:help vim.diagnostic.severity` in Neovim.
1 parent 996984a commit 6be9ca2

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

USAGE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ The git provider also provides a utility function `require('feline.providers.git
667667

668668
The diagnostics and LSP providers all require the Neovim built-in LSP to be configured and at least one LSP client to be attached to the current buffer, else they'll have no output.
669669

670-
The diagnostics provider also provides a utility function `require('feline.providers.lsp').diagnostics_exist(type)` for checking if any diagnostics of the provided type exists. The values of `type` must be one of `'Error'`, `'Warning'`, `'Hint'` or `'Information'`.
670+
The diagnostics provider also provides a utility function `require('feline.providers.lsp').diagnostics_exist` for checking if any diagnostics exists. You can also optionally provide a `severity` function argument to only check for diagnostics of that severity. The value of `severity` must be one of the Neovim diagnostic API severities (eg: `vim.diagnostic.severity.WARN`). For more info on diagnostic severities, do `:help vim.diagnostic.severity` in Neovim.
671671

672672
## Themes
673673

lua/feline/providers/lsp.lua

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
local M = {}
22

33
local lsp = vim.lsp
4+
local diagnostic = vim.diagnostic
5+
6+
-- Initialize a local table with severity names to prevent having to create a table in every call of
7+
-- the diagnostic function to improve performance
8+
local severity_names = { "Information", "Hint", "Warning", "Error" }
49

510
function M.is_lsp_attached()
611
return next(lsp.buf_get_clients(0)) ~= nil
712
end
813

914
function M.get_diagnostics_count(severity)
10-
local active_clients = lsp.buf_get_clients(0)
11-
12-
if not active_clients then return 0 end
13-
14-
local count = 0
15-
16-
for _, client in pairs(active_clients) do
17-
count = count + lsp.diagnostic.get_count(0, severity, client.id)
15+
if vim.fn.has("nvim-0.6") == 1 then
16+
return vim.tbl_count(diagnostic.get(0, severity and { severity = severity }))
17+
else
18+
-- TODO: drop this when 0.5 is no longer used
19+
return lsp.diagnostic.get_count(0, severity and severity_names[severity])
1820
end
19-
20-
return count
2121
end
2222

2323
function M.diagnostics_exist(severity)
@@ -42,19 +42,19 @@ local function diagnostics(severity)
4242
end
4343

4444
function M.diagnostic_errors()
45-
return diagnostics('Error'), ''
45+
return diagnostics(diagnostic.severity.ERROR), ''
4646
end
4747

4848
function M.diagnostic_warnings()
49-
return diagnostics('Warning'), ''
49+
return diagnostics(diagnostic.severity.WARN), ''
5050
end
5151

52-
function M.diagnostic_hints()
53-
return diagnostics('Hint'), ' '
52+
function M.diagnostic_info()
53+
return diagnostics(diagnostic.severity.INFO), ' '
5454
end
5555

56-
function M.diagnostic_info()
57-
return diagnostics('Information'), ' '
56+
function M.diagnostic_hints()
57+
return diagnostics(diagnostic.severity.HINT), ' '
5858
end
5959

6060
return M

0 commit comments

Comments
 (0)