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

changeset 1064
fcfa295076a8
parent 1062
77bf3b44f6f9
child 1069
0e871a1b59e3
equal deleted inserted replaced
1063:2763a54b0410 1064:fcfa295076a8
1 local diag_virtual_min_threshold = "WARN" 1 local diag_virtual_min_threshold = "WARN"
2 local diag_float_max_threshold = "INFO" 2 local diag_float_max_threshold = "INFO"
3 3
4 vim.diagnostic.config({ 4 vim.diagnostic.config({
5 severity_sort = true, 5 severity_sort = true,
6 underline = { severity = {min = diag_virtual_min_threshold} }, 6 underline = { severity = { min = diag_virtual_min_threshold } },
7 virtual_text = { true, severity = {min = diag_virtual_min_threshold} }, 7 virtual_text = { true, severity = { min = diag_virtual_min_threshold } },
8 float = { source = "if_many" }, 8 float = { source = "if_many" },
9 }) 9 })
10 10
11 -- 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
12 -- play. Note they're global 12 -- play. Note they're global
25 local bufnr = args.buf 25 local bufnr = args.buf
26 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)
27 27
28 -- enable auto diags in message area for below threshold 28 -- enable auto diags in message area for below threshold
29 vim.api.nvim_create_autocmd("CursorHold", { 29 vim.api.nvim_create_autocmd("CursorHold", {
30 group = vim.api.nvim_create_augroup("lsp_buf_diags", {clear = true}), 30 group = vim.api.nvim_create_augroup("lsp_buf_diags", { clear = true }),
31 buffer = bufnr, 31 buffer = bufnr,
32 callback = function(opts, bufnr, line_nr, client_id) 32 callback = function(opts, bufnr, line_nr, client_id)
33 vim.diagnostic.open_float(nil, { 33 vim.diagnostic.open_float(nil, {
34 focusable = false, 34 focusable = false,
35 close_events = {"BufLeave", "CursorMoved", "InsertEnter", "FocusLost"}, 35 close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
36 scope = "line", 36 scope = "line",
37 severity = {max = diag_float_max_threshold}, 37 severity = { max = diag_float_max_threshold },
38 }) 38 })
39 end, 39 end,
40 }) 40 })
41 end 41 end,
42 }) 42 })
43 43
44 -- Format on write, but only certain languages 44 -- Format on write, but only certain languages
45 local autoformat_filetypes = { elixir = true, go = true } 45 local autoformat_filetypes = { elixir = true, go = true }
46 46
47 vim.api.nvim_create_autocmd("BufWritePre", { 47 vim.api.nvim_create_autocmd("BufWritePre", {
48 group = vim.api.nvim_create_augroup("lsp_autoformat", {clear = true}), 48 group = vim.api.nvim_create_augroup("lsp_autoformat", { clear = true }),
49 callback = function(opts, bufnr) 49 callback = function(opts, bufnr)
50 if autoformat_filetypes[vim.bo.filetype] then 50 if autoformat_filetypes[vim.bo.filetype] then
51 vim.lsp.buf.formatting_seq_sync(nil, 100) 51 vim.lsp.buf.formatting_seq_sync(nil, 100)
52 end 52 end
53 end, 53 end,
55 55
56 -- This can be removed when mason-lspconfig gets support for standardrb 56 -- This can be removed when mason-lspconfig gets support for standardrb
57 if vim.fn.executable("standardrb") == 1 then 57 if vim.fn.executable("standardrb") == 1 then
58 vim.api.nvim_create_autocmd("FileType", { 58 vim.api.nvim_create_autocmd("FileType", {
59 pattern = "ruby", 59 pattern = "ruby",
60 group = vim.api.nvim_create_augroup("lsp_ruby", {clear = true}), 60 group = vim.api.nvim_create_augroup("lsp_ruby", { clear = true }),
61 once = true, 61 once = true,
62 callback = function() 62 callback = function()
63 require("lspconfig").standardrb.setup({ 63 require("lspconfig").standardrb.setup({
64 autostart = true, 64 autostart = true,
65 single_file_support = true 65 single_file_support = true,
66 }) 66 })
67 vim.cmd.LspStart("standardrb") 67 vim.cmd.LspStart("standardrb")
68 end, 68 end,
69 }) 69 })
70 end 70 end
71

mercurial