summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp/handlers.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-09-09 20:48:47 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-09-09 20:48:47 +0200
commit81b5ea969f26c520c4da9248d5e6d9b6a32b709c (patch)
tree3a86af02c5dc80cb82c296aa72614131f04905b0 /.config/nvim/lua/lsp/handlers.lua
parent6a1732982287ef5aff2a6de171192b9e2bb90758 (diff)
Change compe to cmp package
Diffstat (limited to '.config/nvim/lua/lsp/handlers.lua')
-rw-r--r--.config/nvim/lua/lsp/handlers.lua77
1 files changed, 47 insertions, 30 deletions
diff --git a/.config/nvim/lua/lsp/handlers.lua b/.config/nvim/lua/lsp/handlers.lua
index d19cb33..04b8477 100644
--- a/.config/nvim/lua/lsp/handlers.lua
+++ b/.config/nvim/lua/lsp/handlers.lua
@@ -3,44 +3,56 @@
local M = {}
function M.setup()
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
+ local config = { -- your config
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,
- 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)
+ 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,
+ }
+ if vim.fn.has "nvim-0.5.1" > 0 then
+ vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, result, ctx, _)
+ local uri = result.uri
+ local bufnr = vim.uri_to_bufnr(uri)
+ if not bufnr then
+ return
+ end
- if not bufnr then
- return
+ local diagnostics = result.diagnostics
+ vim.lsp.diagnostic.save(diagnostics, bufnr, ctx.client_id)
+ if not vim.api.nvim_buf_is_loaded(bufnr) then
+ return
+ end
+ vim.lsp.diagnostic.display(diagnostics, bufnr, ctx.client_id, config)
end
+ else
+ vim.lsp.handlers["textDocument/publishDiagnostics"] =
+ function(_, _, params, client_id, _)
+ local uri = params.uri
+ local bufnr = vim.uri_to_bufnr(uri)
+ if not bufnr then
+ return
+ end
- local diagnostics = params.diagnostics
-
- vim.lsp.diagnostic.save(diagnostics, bufnr, client_id)
-
- if not vim.api.nvim_buf_is_loaded(bufnr) then
- return
- end
- vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config)
+ local diagnostics = params.diagnostics
+ vim.lsp.diagnostic.save(diagnostics, bufnr, client_id)
+ if not vim.api.nvim_buf_is_loaded(bufnr) then
+ return
+ end
+ vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config)
+ end
end
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = options.lsp.popup_border,
})
- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
- border = options.lsp.popup_border,
- })
+ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
+ vim.lsp.handlers.signature_help,
+ {
+ border = options.lsp.popup_border,
+ }
+ )
end
function M.show_line_diagnostics()
@@ -65,7 +77,10 @@ function M.show_line_diagnostics()
local source = diagnostic.source
if source then
if string.find(source, "/") then
- source = string.sub(diagnostic.source, string.find(diagnostic.source, "([%w-_]+)$"))
+ source = string.sub(
+ diagnostic.source,
+ string.find(diagnostic.source, "([%w-_]+)$")
+ )
end
diags[i].message = string.format("%s: %s", source, diagnostic.message)
else
@@ -102,7 +117,9 @@ function M.show_line_diagnostics()
end
vim.api.nvim_command(
- "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)"
+ "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, "
+ .. winnr
+ .. ", true)"
)
vim.lsp.util.close_preview_autocmd(close_events, winnr)
end