refactor: more autocmd api updates
* feat: add format_timeout user option
This commit is contained in:
parent
8b5f9f44c0
commit
6eb01f3404
5 changed files with 25 additions and 8 deletions
|
@ -20,6 +20,8 @@ local config = {
|
||||||
lsp = {
|
lsp = {
|
||||||
-- True/false or table of filetypes {'.ts', '.js',}
|
-- True/false or table of filetypes {'.ts', '.js',}
|
||||||
format_on_save = true,
|
format_on_save = true,
|
||||||
|
-- Time in MS before format timeout
|
||||||
|
format_timeout = 3000,
|
||||||
-- Set to false to disable rename notification
|
-- Set to false to disable rename notification
|
||||||
rename_notification = true,
|
rename_notification = true,
|
||||||
-- Enable non-default servers, use default lsp config
|
-- Enable non-default servers, use default lsp config
|
||||||
|
|
|
@ -50,6 +50,7 @@ return packer.startup(function()
|
||||||
'NvimTreeToggle',
|
'NvimTreeToggle',
|
||||||
},
|
},
|
||||||
disable = vim.tbl_contains(user_config.disable_builtin_plugins, 'nvim-tree'),
|
disable = vim.tbl_contains(user_config.disable_builtin_plugins, 'nvim-tree'),
|
||||||
|
event = 'VimEnter',
|
||||||
})
|
})
|
||||||
|
|
||||||
use({
|
use({
|
||||||
|
@ -60,6 +61,7 @@ return packer.startup(function()
|
||||||
config = function()
|
config = function()
|
||||||
require('cosmic.plugins.cosmic-ui')
|
require('cosmic.plugins.cosmic-ui')
|
||||||
end,
|
end,
|
||||||
|
event = 'BufWinEnter',
|
||||||
})
|
})
|
||||||
|
|
||||||
use({
|
use({
|
||||||
|
@ -88,6 +90,7 @@ return packer.startup(function()
|
||||||
disable = vim.tbl_contains(user_config.disable_builtin_plugins, 'lsp_signature'),
|
disable = vim.tbl_contains(user_config.disable_builtin_plugins, 'lsp_signature'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
event = 'BufWinEnter',
|
||||||
})
|
})
|
||||||
|
|
||||||
-- autocompletion
|
-- autocompletion
|
||||||
|
@ -136,7 +139,7 @@ return packer.startup(function()
|
||||||
'lewis6991/gitsigns.nvim',
|
'lewis6991/gitsigns.nvim',
|
||||||
requires = { 'nvim-lua/plenary.nvim' },
|
requires = { 'nvim-lua/plenary.nvim' },
|
||||||
opt = true,
|
opt = true,
|
||||||
event = 'BufRead',
|
event = 'BufWinEnter',
|
||||||
config = function()
|
config = function()
|
||||||
require('cosmic.plugins.gitsigns')
|
require('cosmic.plugins.gitsigns')
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -12,6 +12,7 @@ local default_config = {
|
||||||
theme = 'tokyonight',
|
theme = 'tokyonight',
|
||||||
lsp = {
|
lsp = {
|
||||||
format_on_save = true, -- true/false or table of filetypes {'.ts', '.js',}
|
format_on_save = true, -- true/false or table of filetypes {'.ts', '.js',}
|
||||||
|
format_timeout = 3000,
|
||||||
rename_notification = true,
|
rename_notification = true,
|
||||||
servers = {
|
servers = {
|
||||||
jsonls = {
|
jsonls = {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
local config = require('cosmic.core.user')
|
local config = require('cosmic.core.user')
|
||||||
|
local augroup_name = 'CosmicNvimLspFormat'
|
||||||
|
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local auto_format_lock = false
|
local auto_format_lock = false
|
||||||
|
@ -25,12 +27,14 @@ function M.on_attach(client, bufnr)
|
||||||
else
|
else
|
||||||
format_filetypes = '*'
|
format_filetypes = '*'
|
||||||
end
|
end
|
||||||
vim.cmd(([[
|
|
||||||
augroup CosmicFormat
|
vim.api.nvim_create_autocmd(string.format('BufWritePre %s', format_filetypes), {
|
||||||
autocmd!
|
callback = function()
|
||||||
autocmd BufWritePre %s lua vim.lsp.buf.formatting_sync(nil, 3000)
|
vim.lsp.buf.formatting_sync(nil, config.lsp.format_timeout)
|
||||||
augroup end
|
end,
|
||||||
]]):format(format_filetypes))
|
group = group,
|
||||||
|
nested = true,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
client.resolved_capabilities.document_formatting = false
|
client.resolved_capabilities.document_formatting = false
|
||||||
|
|
|
@ -2,6 +2,8 @@ local config = require('cosmic.core.user')
|
||||||
local g = vim.g
|
local g = vim.g
|
||||||
local icons = require('cosmic.theme.icons')
|
local icons = require('cosmic.theme.icons')
|
||||||
local u = require('cosmic.utils')
|
local u = require('cosmic.utils')
|
||||||
|
local augroup_name = 'CosmicNvimNvimTree'
|
||||||
|
local group = vim.api.nvim_create_augroup(augroup_name, { clear = true })
|
||||||
|
|
||||||
-- settings
|
-- settings
|
||||||
g.nvim_tree_git_hl = 1
|
g.nvim_tree_git_hl = 1
|
||||||
|
@ -27,7 +29,6 @@ g.nvim_tree_respect_buf_cwd = 1
|
||||||
|
|
||||||
-- set up args
|
-- set up args
|
||||||
local args = {
|
local args = {
|
||||||
auto_close = true,
|
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
enable = true,
|
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 {}))
|
require('nvim-tree').setup(u.merge(args, config.nvim_tree or {}))
|
||||||
|
|
Loading…
Add table
Reference in a new issue