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

changeset 1062
77bf3b44f6f9
parent 1061
8141190cc943
child 1064
fcfa295076a8
equal deleted inserted replaced
1061:8141190cc943 1062:77bf3b44f6f9
24 callback = function(args) 24 callback = function(args)
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_augroup('lsp_diags', {clear = false})
30 vim.api.nvim_create_autocmd("CursorHold", { 29 vim.api.nvim_create_autocmd("CursorHold", {
31 group = "lsp_diags", 30 group = vim.api.nvim_create_augroup("lsp_buf_diags", {clear = true}),
32 buffer = bufnr, 31 buffer = bufnr,
33 callback = function(opts, bufnr, line_nr, client_id) 32 callback = function(opts, bufnr, line_nr, client_id)
34 vim.diagnostic.open_float(nil, { 33 vim.diagnostic.open_float(nil, {
35 focusable = false, 34 focusable = false,
36 close_events = {"BufLeave", "CursorMoved", "InsertEnter", "FocusLost"}, 35 close_events = {"BufLeave", "CursorMoved", "InsertEnter", "FocusLost"},
38 severity = {max = diag_float_max_threshold}, 37 severity = {max = diag_float_max_threshold},
39 }) 38 })
40 end, 39 end,
41 }) 40 })
42 end 41 end
42 })
43
44 -- Format on write, but only certain languages
45 local autoformat_filetypes = { elixir = true, go = true }
46
47 vim.api.nvim_create_autocmd("BufWritePre", {
48 group = vim.api.nvim_create_augroup("lsp_autoformat", {clear = true}),
49 callback = function(opts, bufnr)
50 if autoformat_filetypes[vim.bo.filetype] then
51 vim.lsp.buf.formatting_seq_sync(nil, 100)
52 end
53 end,
43 }) 54 })
44 55
45 -- This can be removed when mason-lspconfig gets support for standardrb 56 -- This can be removed when mason-lspconfig gets support for standardrb
46 if vim.fn.executable("standardrb") == 1 then 57 if vim.fn.executable("standardrb") == 1 then
47 vim.api.nvim_create_autocmd("FileType", { 58 vim.api.nvim_create_autocmd("FileType", {

mercurial