summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp/handlers.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-09-06 21:53:56 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-09-06 21:53:56 +0200
commit6a1732982287ef5aff2a6de171192b9e2bb90758 (patch)
tree543f94f80d548b9ed7a9d0daecb08575a01a9a45 /.config/nvim/lua/lsp/handlers.lua
parentb89e893bfc7b8893dc4c13aa55f627096b32758a (diff)
Updates to nvim from lvim
Diffstat (limited to '.config/nvim/lua/lsp/handlers.lua')
-rw-r--r--.config/nvim/lua/lsp/handlers.lua135
1 files changed, 87 insertions, 48 deletions
diff --git a/.config/nvim/lua/lsp/handlers.lua b/.config/nvim/lua/lsp/handlers.lua
index e273261..d19cb33 100644
--- a/.config/nvim/lua/lsp/handlers.lua
+++ b/.config/nvim/lua/lsp/handlers.lua
@@ -3,69 +3,108 @@
local M = {}
function M.setup()
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics,
- {
+ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
+ virtual_text = options.lsp.diagnostics.virtual_text,
+ signs = options.lsp.diagnostics.signs.active,
+ underline = options.lsp.document_highlight,
+ })
+
+ vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _)
+ local config = { -- your config
virtual_text = options.lsp.diagnostics.virtual_text,
- signs = options.lsp.diagnostics.signs.active,
- underline = options.lsp.document_highlight,
+ signs = options.lsp.diagnostics.signs,
+ underline = options.lsp.diagnostics.underline,
+ update_in_insert = options.lsp.diagnostics.update_in_insert,
+ severity_sort = options.lsp.diagnostics.severity_sort,
}
- )
+ local uri = params.uri
+ local bufnr = vim.uri_to_bufnr(uri)
- vim.lsp.handlers["textDocument/publishDiagnostics"] =
- function(_, _, params, client_id, _)
- local config = { -- your config
- virtual_text = options.lsp.diagnostics.virtual_text,
- signs = options.lsp.diagnostics.signs,
- underline = options.lsp.diagnostics.underline,
- update_in_insert = options.lsp.diagnostics.update_in_insert,
- severity_sort = options.lsp.diagnostics.severity_sort,
- }
- local uri = params.uri
- local bufnr = vim.uri_to_bufnr(uri)
+ if not bufnr then
+ return
+ end
- if not bufnr then
- return
- end
+ local diagnostics = params.diagnostics
- local diagnostics = params.diagnostics
+ vim.lsp.diagnostic.save(diagnostics, bufnr, client_id)
- for i, v in ipairs(diagnostics) do
- local source = v.source
- if source then
- if string.find(source, "/") then
- source = string.sub(v.source, string.find(v.source, "([%w-_]+)$"))
- end
- diagnostics[i].message = string.format("%s: %s", source, v.message)
- else
- diagnostics[i].message = string.format("%s", v.message)
- end
+ if not vim.api.nvim_buf_is_loaded(bufnr) then
+ return
+ end
+ vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config)
+ end
- if vim.tbl_contains(vim.tbl_keys(v), "code") then
- diagnostics[i].message = diagnostics[i].message
- .. string.format(" [%s]", v.code)
- end
- end
+ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
+ border = options.lsp.popup_border,
+ })
- vim.lsp.diagnostic.save(diagnostics, bufnr, client_id)
+ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
+ border = options.lsp.popup_border,
+ })
+end
+
+function M.show_line_diagnostics()
+ local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
+ local diags = vim.deepcopy(diagnostics)
+ local height = #diagnostics
+ local width = 0
+ local opts = {}
+ local close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" }
+ local diagnostic_severities = {
+ "Error",
+ "Warning",
+ "Information",
+ "Hint",
+ }
+ if height == 0 then
+ return
+ end
+ local bufnr = vim.api.nvim_create_buf(false, true)
- if not vim.api.nvim_buf_is_loaded(bufnr) then
- return
+ for i, diagnostic in ipairs(diagnostics) do
+ local source = diagnostic.source
+ if source then
+ if string.find(source, "/") then
+ source = string.sub(diagnostic.source, string.find(diagnostic.source, "([%w-_]+)$"))
end
+ diags[i].message = string.format("%s: %s", source, diagnostic.message)
+ else
+ diags[i].message = string.format("%s", diagnostic.message)
+ end
- vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config)
+ if diagnostic.code then
+ diags[i].message = string.format("%s [%s]", diags[i].message, diagnostic.code)
+ end
+ if diags[i].message:len() > width then
+ width = string.len(diags[i].message)
end
+ end
- vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
- border = options.lsp.popup_border,
- })
+ opts = vim.lsp.util.make_floating_popup_options(width, height, opts)
+ opts["style"] = "minimal"
+ opts["border"] = "rounded"
- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
- vim.lsp.handlers.signature_help,
- {
- border = options.lsp.popup_border,
- }
+ vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
+ local winnr = vim.api.nvim_open_win(bufnr, false, opts)
+ vim.api.nvim_win_set_option(winnr, "winblend", 0)
+ vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr)
+ for i, diag in ipairs(diags) do
+ local message = diag.message:gsub("[\n\r]", " ")
+ vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { message })
+ vim.api.nvim_buf_add_highlight(
+ bufnr,
+ -1,
+ "LspDiagnosticsFloating" .. diagnostic_severities[diag.severity],
+ i - 1,
+ 0,
+ diag.message:len()
+ )
+ end
+
+ vim.api.nvim_command(
+ "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)"
)
+ vim.lsp.util.close_preview_autocmd(close_events, winnr)
end
return M