1 local diag_threshold = "WARN" |
1 local diag_virtual_min_threshold = "WARN" |
|
2 local diag_float_max_threshold = "INFO" |
2 |
3 |
3 vim.diagnostic.config({ |
4 vim.diagnostic.config({ |
4 underline = { severity = {min = diag_threshold} }, |
5 severity_sort = true, |
5 virtual_text = { true, severity = {min = diag_threshold} }, |
6 underline = { severity = {min = diag_virtual_min_threshold} }, |
|
7 virtual_text = { true, severity = {min = diag_virtual_min_threshold} }, |
|
8 float = { source = "if_many" }, |
6 }) |
9 }) |
7 |
10 |
8 -- Some options are more chill in text mode, this unchills them if a LSP is in |
11 -- Some options are more chill in text mode, this unchills them if a LSP is in |
9 -- play. Note they're global |
12 -- play. Note they're global |
10 vim.api.nvim_create_autocmd("LspAttach", { |
13 vim.api.nvim_create_autocmd("LspAttach", { |
22 local bufnr = args.buf |
25 local bufnr = args.buf |
23 local client = vim.lsp.get_client_by_id(args.data.client_id) |
26 local client = vim.lsp.get_client_by_id(args.data.client_id) |
24 |
27 |
25 -- enable auto diags in message area for below threshold |
28 -- enable auto diags in message area for below threshold |
26 vim.api.nvim_create_augroup('lsp_diags', {clear = false}) |
29 vim.api.nvim_create_augroup('lsp_diags', {clear = false}) |
27 |
30 vim.api.nvim_create_autocmd("CursorHold", { |
28 vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, { |
|
29 group = "lsp_diags", |
31 group = "lsp_diags", |
30 buffer = bufnr, |
32 buffer = bufnr, |
31 callback = function(opts, bufnr, line_nr, client_id) |
33 callback = function(opts, bufnr, line_nr, client_id) |
32 bufnr = bufnr or 0 |
34 vim.diagnostic.open_float(nil, { |
33 line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) |
35 focusable = false, |
34 opts = opts or {['lnum'] = line_nr} |
36 close_events = {"BufLeave", "CursorMoved", "InsertEnter", "FocusLost"}, |
35 |
37 scope = "line", |
36 local line_diagnostics = vim.diagnostic.get(bufnr, {lnum = line_nr, severity = {max = diag_threshold}}) |
38 severity = {max = diag_float_max_threshold}, |
37 if vim.tbl_isempty(line_diagnostics) then return end |
39 }) |
38 |
|
39 local diagnostic_message = "" |
|
40 for i, diagnostic in ipairs(line_diagnostics) do |
|
41 diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") |
|
42 print(diagnostic_message) |
|
43 if i ~= #line_diagnostics then |
|
44 diagnostic_message = diagnostic_message .. "\n" |
|
45 end |
|
46 end |
|
47 vim.api.nvim_echo({{diagnostic_message, "Normal"}}, false, {}) |
|
48 end, |
40 end, |
49 }) |
41 }) |
50 |
42 |
51 end |
43 end |
52 }) |
44 }) |