.config/nvim/lua/config/lsp.lua

Sun, 19 Feb 2023 13:25:46 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 19 Feb 2023 13:25:46 -0600
changeset 1031
ceb2e56c6e8f
parent 1030
03d507b3c122
child 1032
b0497894f69b
permissions
-rw-r--r--

Use vim-illuminate

1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
1 local diag_threshold = "WARN"
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
2
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 vim.diagnostic.config({
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
4 underline = { severity = {min = diag_threshold} },
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
5 virtual_text = { true, severity = {min = diag_threshold} },
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
6 })
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
7
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
8 -- Some options are more chill in text mode, this unchills them if a LSP is in
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
9 -- play. Note they're global
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
10 vim.api.nvim_create_autocmd("LspAttach", {
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
11 once = true,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
12 group = "lsp_attach",
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
13 callback = function(args)
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
14 vim.opt.number = true
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
15 vim.opt.updatetime = 250
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
16 end,
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 })
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 vim.api.nvim_create_autocmd("LspAttach", {
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
20 group = "lsp_attach",
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21 callback = function(args)
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
22 local bufnr = args.buf
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
23 local client = vim.lsp.get_client_by_id(args.data.client_id)
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
24
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
25 -- enable auto diags in message area for below threshold
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
26 vim.api.nvim_create_augroup('lsp_diags', {clear = false})
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
27
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
28 vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
29 group = "lsp_diags",
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
30 buffer = bufnr,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
31 callback = function(opts, bufnr, line_nr, client_id)
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
32 bufnr = bufnr or 0
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
33 line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1)
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
34 opts = opts or {['lnum'] = line_nr}
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
35
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
36 local line_diagnostics = vim.diagnostic.get(bufnr, {lnum = line_nr, severity = {max = diag_threshold}})
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
37 if vim.tbl_isempty(line_diagnostics) then return end
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
38
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
39 local diagnostic_message = ""
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
40 for i, diagnostic in ipairs(line_diagnostics) do
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
41 diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "")
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
42 print(diagnostic_message)
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
43 if i ~= #line_diagnostics then
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
44 diagnostic_message = diagnostic_message .. "\n"
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
45 end
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
46 end
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
47 vim.api.nvim_echo({{diagnostic_message, "Normal"}}, false, {})
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
48 end,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
49 })
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
50
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
51 end
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
52 })

mercurial