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

Commit

Permalink
refactor!: use vim.diagnostic for lsp provider
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ram02z authored and lukas-reineke committed Dec 22, 2021
1 parent 996984a commit 6be9ca2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ The git provider also provides a utility function `require('feline.providers.git

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.

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'`.
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.

## Themes

Expand Down
32 changes: 16 additions & 16 deletions lua/feline/providers/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
local M = {}

local lsp = vim.lsp
local diagnostic = vim.diagnostic

-- Initialize a local table with severity names to prevent having to create a table in every call of
-- the diagnostic function to improve performance
local severity_names = { "Information", "Hint", "Warning", "Error" }

function M.is_lsp_attached()
return next(lsp.buf_get_clients(0)) ~= nil
end

function M.get_diagnostics_count(severity)
local active_clients = lsp.buf_get_clients(0)

if not active_clients then return 0 end

local count = 0

for _, client in pairs(active_clients) do
count = count + lsp.diagnostic.get_count(0, severity, client.id)
if vim.fn.has("nvim-0.6") == 1 then
return vim.tbl_count(diagnostic.get(0, severity and { severity = severity }))
else
-- TODO: drop this when 0.5 is no longer used
return lsp.diagnostic.get_count(0, severity and severity_names[severity])
end

return count
end

function M.diagnostics_exist(severity)
Expand All @@ -42,19 +42,19 @@ local function diagnostics(severity)
end

function M.diagnostic_errors()
return diagnostics('Error'), ''
return diagnostics(diagnostic.severity.ERROR), ''
end

function M.diagnostic_warnings()
return diagnostics('Warning'), ''
return diagnostics(diagnostic.severity.WARN), ''
end

function M.diagnostic_hints()
return diagnostics('Hint'), ' '
function M.diagnostic_info()
return diagnostics(diagnostic.severity.INFO), ' '
end

function M.diagnostic_info()
return diagnostics('Information'), ' '
function M.diagnostic_hints()
return diagnostics(diagnostic.severity.HINT), ' '
end

return M

5 comments on commit 6be9ca2

@G-Rowell
Copy link

@G-Rowell G-Rowell commented on 6be9ca2 Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @ram02z @lukas-reineke

I'm still investigating but I think this may be a breaking change, sorry for the unfortunate news

On Debian,
NvimAppimage 0.5 & 0.6


Update:

so sorry, I've totally blazed past the "Breaking" in the title, still reading

@lukas-reineke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the diagnostics_exist function takes a different argument now.
If you get any other errors, can you post them? I can also take a look.

@G-Rowell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukas-reineke

So firstly, my apologies, I didn't investigate my config well enough.

It seems that my config referenced some breaking changes, and attempted to use some old (and now non-existent) vim.lsp api calls.

Will update if I actually find an issue, sorry!

@siduck
Copy link

@siduck siduck commented on 6be9ca2 Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the diagnostics_exist function takes a different argument now. If you get any other errors, can you post them? I can also take a look.

bg color in statusline no longer works for me now, after this commit

image

@ram02z
Copy link
Contributor Author

@ram02z ram02z commented on 6be9ca2 Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the diagnostics_exist function takes a different argument now. If you get any other errors, can you post them? I can also take a look.

bg color in statusline no longer works for me now, after this commit

image

Open an issue please.

Please sign in to comment.