mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
add support to show diagnostics count in statusline (#11641)
* add support to show diagnostics count in statusline * documentation
This commit is contained in:
@@ -893,21 +893,22 @@ function lsp.buf_request_sync(bufnr, method, params, timeout_ms)
|
||||
return request_results
|
||||
end
|
||||
|
||||
--- Sends a notification to all servers attached to the buffer.
|
||||
---
|
||||
--@param bufnr (optional, number) Buffer handle, or 0 for current
|
||||
--@param method (string) LSP method name
|
||||
--@param params (string) Parameters to send to the server
|
||||
---
|
||||
--@returns nil
|
||||
--- Send a notification to a server
|
||||
-- @param bufnr [number] (optional): The number of the buffer
|
||||
-- @param method [string]: Name of the request method
|
||||
-- @param params [string]: Arguments to send to the server
|
||||
--
|
||||
-- @returns true if any client returns true; false otherwise
|
||||
function lsp.buf_notify(bufnr, method, params)
|
||||
validate {
|
||||
bufnr = { bufnr, 'n', true };
|
||||
method = { method, 's' };
|
||||
}
|
||||
local resp = false
|
||||
for_each_buffer_client(bufnr, function(client, _client_id)
|
||||
client.rpc.notify(method, params)
|
||||
if client.rpc.notify(method, params) then resp = true end
|
||||
end)
|
||||
return resp
|
||||
end
|
||||
|
||||
--- Implements 'omnifunc' compatible LSP completion.
|
||||
|
||||
@@ -23,6 +23,10 @@ local function request(method, params, callback)
|
||||
return vim.lsp.buf_request(0, method, params, callback)
|
||||
end
|
||||
|
||||
function M.server_ready()
|
||||
return not not vim.lsp.buf_notify(0, "window/progress", {})
|
||||
end
|
||||
|
||||
function M.hover()
|
||||
local params = util.make_position_params()
|
||||
request('textDocument/hover', params)
|
||||
|
||||
@@ -33,6 +33,7 @@ M['textDocument/publishDiagnostics'] = function(_, _, result)
|
||||
util.buf_diagnostics_underline(bufnr, result.diagnostics)
|
||||
util.buf_diagnostics_virtual_text(bufnr, result.diagnostics)
|
||||
-- util.set_loclist(result.diagnostics)
|
||||
vim.api.nvim_command("doautocmd User LspDiagnosticsChanged")
|
||||
end
|
||||
|
||||
M['textDocument/references'] = function(_, _, result)
|
||||
|
||||
@@ -743,6 +743,18 @@ do
|
||||
api.nvim_buf_set_virtual_text(bufnr, diagnostic_ns, line, virt_texts, {})
|
||||
end
|
||||
end
|
||||
function M.buf_diagnostics_count(kind)
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local buffer_line_diagnostics = all_buffer_diagnostics[bufnr]
|
||||
if not buffer_line_diagnostics then return end
|
||||
local count = 0
|
||||
for _, line_diags in pairs(buffer_line_diagnostics) do
|
||||
for _, diag in ipairs(line_diags) do
|
||||
if protocol.DiagnosticSeverity[kind] == diag.severity then count = count + 1 end
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
end
|
||||
|
||||
local position_sort = sort_by_key(function(v)
|
||||
|
||||
Reference in New Issue
Block a user