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

Sun, 05 Mar 2023 15:36:09 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 05 Mar 2023 15:36:09 -0500
changeset 1061
8141190cc943
parent 1059
dc0095e5bbc8
child 1062
77bf3b44f6f9
permissions
-rw-r--r--

Simplify standardrb lsp setup

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,
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
6 underline = { severity = {min = diag_virtual_min_threshold} },
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
7 virtual_text = { true, severity = {min = diag_virtual_min_threshold} },
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
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
29 vim.api.nvim_create_augroup('lsp_diags', {clear = false})
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
30 vim.api.nvim_create_autocmd("CursorHold", {
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
31 group = "lsp_diags",
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
32 buffer = bufnr,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
33 callback = function(opts, bufnr, line_nr, client_id)
1032
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
34 vim.diagnostic.open_float(nil, {
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
35 focusable = false,
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
36 close_events = {"BufLeave", "CursorMoved", "InsertEnter", "FocusLost"},
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
37 scope = "line",
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
38 severity = {max = diag_float_max_threshold},
b0497894f69b Customize LSP float diags further
Meredith Howard <mhoward@roomag.org>
parents: 1031
diff changeset
39 })
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
40 end,
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
41 })
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
42 end
1016
07d37da233ef Add lsp-specific config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 })
1059
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
44
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
45 -- 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
46 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
47 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
48 pattern = "ruby",
1061
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
49 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
50 once = true,
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
51 callback = function()
1061
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
52 require("lspconfig").standardrb.setup({
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
53 autostart = true,
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
54 single_file_support = true
8141190cc943 Simplify standardrb lsp setup
Meredith Howard <mhoward@roomag.org>
parents: 1059
diff changeset
55 })
1059
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
56 vim.cmd.LspStart("standardrb")
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
57 end,
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
58 })
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
59 end
dc0095e5bbc8 disable rubocop and formatting in solargraph, add standardrb glue
Meredith Howard <mhoward@roomag.org>
parents: 1032
diff changeset
60

mercurial