diff --git a/files/nvim.lua b/files/nvim.conform.lua similarity index 94% rename from files/nvim.lua rename to files/nvim.conform.lua index 46ee351..801df29 100644 --- a/files/nvim.lua +++ b/files/nvim.conform.lua @@ -1,4 +1,4 @@ --- example of a project specific nvim configuration file using :exrc +-- example of a project specific nvim configuration file using :exrc and conform local conform = require 'conform'; diff --git a/files/nvim.lsp.lua b/files/nvim.lsp.lua new file mode 100644 index 0000000..ff06a44 --- /dev/null +++ b/files/nvim.lsp.lua @@ -0,0 +1,33 @@ +-- example of a project specific nvim configuration file using :exrc and lsp formatting + +local format_clients = { + 'ruff', + 'lua_ls', + 'bashls', + 'jsonls', + 'ts_ls', + 'ansiblels', + 'yamlls', + 'cssls', + 'html', +} + +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:supports_method('textDocument/formatting') + and vim.tbl_contains(format_clients, client.name) 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 +})