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

Sun, 05 Mar 2023 19:32:15 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 05 Mar 2023 19:32:15 -0600
changeset 1064
fcfa295076a8
parent 1062
77bf3b44f6f9
child 1069
0e871a1b59e3
permissions
-rw-r--r--

Apply stylua

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
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
51 vim.lsp.buf.formatting_seq_sync(nil, 100)
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 })
77bf3b44f6f9 Add format-on-write for elixir and go
Meredith Howard <mhoward@roomag.org>
parents: 1061
diff changeset
55
1059
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
56 -- This can be removed when mason-lspconfig gets support for standardrb
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
57 if vim.fn.executable("standardrb") == 1 then
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
58 vim.api.nvim_create_autocmd("FileType", {
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
59 pattern = "ruby",
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
60 group = vim.api.nvim_create_augroup("lsp_ruby", { clear = true }),
1059
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
61 once = true,
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
62 callback = function()
1061
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
63 require("lspconfig").standardrb.setup({
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
64 autostart = true,
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1062
diff changeset
65 single_file_support = true,
1061
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
66 })
1059
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
67 vim.cmd.LspStart("standardrb")
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
68 end,
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
69 })
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
70 end

mercurial