Move formatting configuration to separate file
This commit is contained in:
parent
6adb1f506f
commit
6d801bcb4e
4 changed files with 26 additions and 25 deletions
|
|
@ -120,3 +120,6 @@
|
||||||
|
|
||||||
- src: 'templates/nvim/lua/filetype.lua.j2'
|
- src: 'templates/nvim/lua/filetype.lua.j2'
|
||||||
dest: '{{ xdg_config_dir }}/nvim/lua/_filetype.lua'
|
dest: '{{ xdg_config_dir }}/nvim/lua/_filetype.lua'
|
||||||
|
|
||||||
|
- src: 'templates/nvim/lua/formatting.lua.j2'
|
||||||
|
dest: '{{ xdg_config_dir }}/nvim/lua/formatting.lua'
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
-- {{ ansible_managed }}
|
-- {{ ansible_managed }}
|
||||||
|
|
||||||
-- TODO: load environment vars from .env files
|
|
||||||
require('options')
|
require('options')
|
||||||
require('_filetype')
|
require('_filetype')
|
||||||
require('colorscheme')
|
require('colorscheme')
|
||||||
|
|
@ -12,3 +11,4 @@ require('indent-blankline')
|
||||||
require('_nvim-tree')
|
require('_nvim-tree')
|
||||||
require('lua-line')
|
require('lua-line')
|
||||||
require('_source-link')
|
require('_source-link')
|
||||||
|
require('formatting')
|
||||||
|
|
|
||||||
22
templates/nvim/lua/formatting.lua.j2
Normal file
22
templates/nvim/lua/formatting.lua.j2
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
local enable_formatting = os.getenv("enable_formatting") == 'true';
|
||||||
|
|
||||||
|
if (enable_formatting) then
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
group = vim.api.nvim_create_augroup('lsp', { clear = true }),
|
||||||
|
callback = function(args)
|
||||||
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
|
|
||||||
|
if client.server_capabilities.documentFormattingProvider then
|
||||||
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||||
|
buffer = args.buf,
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format {
|
||||||
|
async = false,
|
||||||
|
id = args.data.client_id
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
@ -187,27 +187,3 @@ vim.diagnostic.config {
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local enable_formatting = os.getenv("enable_formatting") == 'true';
|
|
||||||
|
|
||||||
-- format buffers before saving for specific LSPs
|
|
||||||
if (enable_formatting) then
|
|
||||||
vim.api.nvim_create_autocmd('LspAttach', {
|
|
||||||
group = vim.api.nvim_create_augroup('lsp', { clear = true }),
|
|
||||||
callback = function(args)
|
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
||||||
|
|
||||||
if client.server_capabilities.documentFormattingProvider then
|
|
||||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
|
||||||
buffer = args.buf,
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.buf.format {
|
|
||||||
async = false,
|
|
||||||
id = args.data.client_id
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue