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

Mon, 13 Mar 2023 15:45:24 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 13 Mar 2023 15:45:24 -0500
changeset 1083
cc48b040ddbb
parent 1069
0e871a1b59e3
child 1099
28f3c3900576
permissions
-rw-r--r--

remove standardrb glue now that mason-lspconfig is updated

local diag_virtual_min_threshold = "WARN"
local diag_float_max_threshold = "INFO"

vim.diagnostic.config({
  severity_sort = true,
  underline = { severity = { min = diag_virtual_min_threshold } },
  virtual_text = { true, severity = { min = diag_virtual_min_threshold } },
  float = { source = "if_many" },
})

-- Some options are more chill in text mode, this unchills them if a LSP is in
-- play.  Note they're global
vim.api.nvim_create_autocmd("LspAttach", {
  once = true,
  group = "lsp_attach",
  callback = function(args)
    vim.opt.number = true
    vim.opt.updatetime = 250
  end,
})

vim.api.nvim_create_autocmd("LspAttach", {
  group = "lsp_attach",
  callback = function(args)
    local bufnr = args.buf
    local client = vim.lsp.get_client_by_id(args.data.client_id)

    -- enable auto diags in message area for below threshold
    vim.api.nvim_create_autocmd("CursorHold", {
      group = vim.api.nvim_create_augroup("lsp_buf_diags", { clear = true }),
      buffer = bufnr,
      callback = function(opts, bufnr, line_nr, client_id)
        vim.diagnostic.open_float(nil, {
          focusable = false,
          close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
          scope = "line",
          severity = { max = diag_float_max_threshold },
        })
      end,
    })
  end,
})

-- Format on write, but only certain languages
local autoformat_filetypes = { elixir = true, go = true }

vim.api.nvim_create_autocmd("BufWritePre", {
  group = vim.api.nvim_create_augroup("lsp_autoformat", { clear = true }),
  callback = function(opts, bufnr)
    if autoformat_filetypes[vim.bo.filetype] then
      vim.lsp.buf.format({ timeout_ms = 100 })
    end
  end,
})

mercurial