1
0
Fork 0
dotfiles/config/nvim/lua/nifoc/utils/diagnostic.lua

31 lines
817 B
Lua
Raw Normal View History

2021-12-18 22:55:56 +00:00
local M = {}
local keymap = require('nifoc.keymap')
function M.maybe_enable_lsp(client, bufnr)
2021-12-20 17:43:23 +00:00
local nifoc_lsp_enabled = vim.api.nvim_buf_get_var(bufnr, 'nifoc_lsp_enabled')
if nifoc_lsp_enabled == nil then
2021-12-18 22:55:56 +00:00
vim.api.nvim_buf_set_var(bufnr, 'nifoc_lsp_enabled', 1)
keymap.lsp_attach(client, bufnr)
end
end
function M.maybe_enable_fixer(client, bufnr)
2021-12-20 17:43:23 +00:00
local nifoc_fixer_enabled = vim.api.nvim_buf_get_var(bufnr, 'nifoc_fixer_enabled')
if client.resolved_capabilities.document_formatting and nifoc_fixer_enabled == nil then
2021-12-18 22:55:56 +00:00
vim.api.nvim_buf_set_var(bufnr, 'nifoc_fixer_enabled', 1)
vim.cmd [[
augroup nifoc_diagnostic_formatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync(nil, 1000)
augroup end
]]
end
end
return M