summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/lsp/handlers.lua72
-rw-r--r--lua/onedarker/LSP.lua12
2 files changed, 66 insertions, 18 deletions
diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua
index 84811581..d55bd0b2 100644
--- a/lua/lsp/handlers.lua
+++ b/lua/lsp/handlers.lua
@@ -19,11 +19,41 @@ function M.setup()
end
local diagnostics = result.diagnostics
- vim.lsp.diagnostic.save(diagnostics, bufnr, ctx.client_id)
- if not vim.api.nvim_buf_is_loaded(bufnr) then
- return
+ local ok, vim_diag = pcall(require, "vim.diagnostic")
+ if ok then
+ -- FIX: why can't we just use vim.diagnostic.get(buf_id)?
+ config.signs = true
+ for i, diagnostic in ipairs(diagnostics) do
+ local rng = diagnostic.range
+ diagnostics[i].lnum = rng["start"].line
+ diagnostics[i].end_lnum = rng["end"].line
+ diagnostics[i].col = rng["start"].character
+ diagnostics[i].end_col = rng["end"].character
+ end
+ local namespace = vim.lsp.diagnostic.get_namespace(ctx.client_id)
+
+ vim_diag.set(namespace, bufnr, diagnostics, config)
+ if not vim.api.nvim_buf_is_loaded(bufnr) then
+ return
+ end
+
+ local sign_names = {
+ "DiagnosticSignError",
+ "DiagnosticSignWarn",
+ "DiagnosticSignInfo",
+ "DiagnosticSignHint",
+ }
+ for i, sign in ipairs(lvim.lsp.diagnostics.signs.values) do
+ vim.fn.sign_define(sign_names[i], { texthl = sign_names[i], text = sign.text, numhl = "" })
+ end
+ vim_diag.show(namespace, bufnr, diagnostics, config)
+ else
+ 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
- vim.lsp.diagnostic.display(diagnostics, bufnr, ctx.client_id, config)
end
else
vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _)
@@ -53,17 +83,30 @@ end
function M.show_line_diagnostics()
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
+ local severity_highlight = {
+ "LspDiagnosticsFloatingError",
+ "LspDiagnosticsFloatingWarning",
+ "LspDiagnosticsFloatingInformation",
+ "LspDiagnosticsFloatingHint",
+ }
+ local ok, vim_diag = pcall(require, "vim.diagnostic")
+ if ok then
+ local buf_id = vim.api.nvim_win_get_buf(0)
+ local win_id = vim.api.nvim_get_current_win()
+ local cursor_position = vim.api.nvim_win_get_cursor(win_id)
+ severity_highlight = {
+ "DiagnosticFloatingError",
+ "DiagnosticFloatingWarn",
+ "DiagnosticFloatingInfo",
+ "DiagnosticFloatingHint",
+ }
+ diagnostics = vim_diag.get(buf_id, { lnum = cursor_position[1] - 1 })
+ end
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
@@ -99,14 +142,7 @@ function M.show_line_diagnostics()
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()
- )
+ vim.api.nvim_buf_add_highlight(bufnr, -1, severity_highlight[diag.severity], i - 1, 0, diag.message:len())
end
vim.api.nvim_command(
diff --git a/lua/onedarker/LSP.lua b/lua/onedarker/LSP.lua
index d2d3a870..3d88338f 100644
--- a/lua/onedarker/LSP.lua
+++ b/lua/onedarker/LSP.lua
@@ -11,10 +11,18 @@ local LSP = {
LspDiagnosticsFloatingWarning = { fg = C.warning_orange },
LspDiagnosticsFloatingInformation = { fg = C.info_yellow },
LspDiagnosticsFloatingHint = { fg = C.hint_blue },
+ DiagnosticFloatingError = { fg = C.error_red },
+ DiagnosticFloatingWarn = { fg = C.warning_orange },
+ DiagnosticFloatingInfo = { fg = C.info_yellow },
+ DiagnosticFloatingHint = { fg = C.hint_blue },
LspDiagnosticsSignError = { fg = C.error_red },
LspDiagnosticsSignWarning = { fg = C.warning_orange },
LspDiagnosticsSignInformation = { fg = C.info_yellow },
LspDiagnosticsSignHint = { fg = C.hint_blue },
+ DiagnosticSignError = { fg = C.error_red },
+ DiagnosticSignWarn = { fg = C.warning_orange },
+ DiagnosticSignInfo = { fg = C.info_yellow },
+ DiagnosticSignHint = { fg = C.hint_blue },
LspDiagnosticsError = { fg = C.error_red },
LspDiagnosticsWarning = { fg = C.warning_orange },
LspDiagnosticsInformation = { fg = C.info_yellow },
@@ -23,6 +31,10 @@ local LSP = {
LspDiagnosticsUnderlineWarning = { style = "underline" },
LspDiagnosticsUnderlineInformation = { style = "underline" },
LspDiagnosticsUnderlineHint = { style = "underline" },
+ DiagnosticUnderlineError = { style = "underline" },
+ DiagnosticUnderlineWarn = { style = "underline" },
+ DiagnosticUnderlineInfo = { style = "underline" },
+ DiagnosticUnderlineHint = { style = "underline" },
QuickScopePrimary = { fg = C.purple_test, style = "underline" },
QuickScopeSecondary = { fg = C.cyan_test, style = "underline" },
TelescopeSelection = { fg = C.hint_blue },