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

Mon, 13 Mar 2023 23:43:25 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 13 Mar 2023 23:43:25 -0500
changeset 1085
c2d11f022cf0
parent 1083
cc48b040ddbb
child 1099
28f3c3900576
permissions
-rw-r--r--

Port encrypted file edit to lua

1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
1 local diag_virtual_min_threshold = "WARN"
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
2 local diag_float_max_threshold = "INFO"
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
3
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 vim.diagnostic.config({
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
5 severity_sort = true,
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
6 underline = { severity = { min = diag_virtual_min_threshold } },
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
7 virtual_text = { true, severity = { min = diag_virtual_min_threshold } },
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
8 float = { source = "if_many" },
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
9 })
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
10
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
11 -- 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
12 -- play. Note they're global
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
13 vim.api.nvim_create_autocmd("LspAttach", {
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
14 once = true,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
15 group = "lsp_attach",
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
16 callback = function(args)
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
17 vim.opt.number = true
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
18 vim.opt.updatetime = 250
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
19 end,
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 })
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22 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
23 group = "lsp_attach",
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 callback = function(args)
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
25 local bufnr = args.buf
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
26 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
27
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
28 -- enable auto diags in message area for below threshold
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
29 vim.api.nvim_create_autocmd("CursorHold", {
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
30 group = vim.api.nvim_create_augroup("lsp_buf_diags", { clear = true }),
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
31 buffer = bufnr,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
32 callback = function(opts, bufnr, line_nr, client_id)
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
33 vim.diagnostic.open_float(nil, {
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
34 focusable = false,
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
35 close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
36 scope = "line",
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
37 severity = { max = diag_float_max_threshold },
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
38 })
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
39 end,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
40 })
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
41 end,
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 })
1059
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
43
1062
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
44 -- Format on write, but only certain languages
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
45 local autoformat_filetypes = { elixir = true, go = true }
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
46
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
47 vim.api.nvim_create_autocmd("BufWritePre", {
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
48 group = vim.api.nvim_create_augroup("lsp_autoformat", { clear = true }),
1062
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
49 callback = function(opts, bufnr)
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
50 if autoformat_filetypes[vim.bo.filetype] then
1069
0e871a1b59e3 use current format function
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
51 vim.lsp.buf.format({ timeout_ms = 100 })
1062
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
52 end
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
53 end,
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
54 })

mercurial