refactor: more autocmd api updates

* feat: add format_timeout user option
This commit is contained in:
Matt Leong 2022-03-28 14:10:46 -07:00
parent 8b5f9f44c0
commit 6eb01f3404
5 changed files with 25 additions and 8 deletions

View file

@ -20,6 +20,8 @@ local config = {
lsp = {
-- True/false or table of filetypes {'.ts', '.js',}
format_on_save = true,
-- Time in MS before format timeout
format_timeout = 3000,
-- Set to false to disable rename notification
rename_notification = true,
-- Enable non-default servers, use default lsp config

View file

@ -50,6 +50,7 @@ return packer.startup(function()
'NvimTreeToggle',
},
disable = vim.tbl_contains(user_config.disable_builtin_plugins, 'nvim-tree'),
event = 'VimEnter',
})
use({
@ -60,6 +61,7 @@ return packer.startup(function()
config = function()
require('cosmic.plugins.cosmic-ui')
end,
event = 'BufWinEnter',
})
use({
@ -88,6 +90,7 @@ return packer.startup(function()
disable = vim.tbl_contains(user_config.disable_builtin_plugins, 'lsp_signature'),
},
},
event = 'BufWinEnter',
})
-- autocompletion
@ -136,7 +139,7 @@ return packer.startup(function()
'lewis6991/gitsigns.nvim',
requires = { 'nvim-lua/plenary.nvim' },
opt = true,
event = 'BufRead',
event = 'BufWinEnter',
config = function()
require('cosmic.plugins.gitsigns')
end,

View file

@ -12,6 +12,7 @@ local default_config = {
theme = 'tokyonight',
lsp = {
format_on_save = true, -- true/false or table of filetypes {'.ts', '.js',}
format_timeout = 3000,
rename_notification = true,
servers = {
jsonls = {

View file

@ -1,4 +1,6 @@
local config = require('cosmic.core.user')
local augroup_name = 'CosmicNvimLspFormat'
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
local M = {}
local auto_format_lock = false
@ -25,12 +27,14 @@ function M.on_attach(client, bufnr)
else
format_filetypes = '*'
end
vim.cmd(([[
augroup CosmicFormat
autocmd!
autocmd BufWritePre %s lua vim.lsp.buf.formatting_sync(nil, 3000)
augroup end
]]):format(format_filetypes))
vim.api.nvim_create_autocmd(string.format('BufWritePre %s', format_filetypes), {
callback = function()
vim.lsp.buf.formatting_sync(nil, config.lsp.format_timeout)
end,
group = group,
nested = true,
})
end
else
client.resolved_capabilities.document_formatting = false

View file

@ -2,6 +2,8 @@ local config = require('cosmic.core.user')
local g = vim.g
local icons = require('cosmic.theme.icons')
local u = require('cosmic.utils')
local augroup_name = 'CosmicNvimNvimTree'
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
-- settings
g.nvim_tree_git_hl = 1
@ -27,7 +29,6 @@ g.nvim_tree_respect_buf_cwd = 1
-- set up args
local args = {
auto_close = true,
diagnostics = {
enable = true,
},
@ -49,4 +50,10 @@ local args = {
},
}
vim.api.nvim_create_autocmd('BufEnter', {
command = [[if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif]],
group = group,
nested = true,
})
require('nvim-tree').setup(u.merge(args, config.nvim_tree or {}))