# HG changeset patch # User zegervdv # Date 1664954352 -7200 # Node ID 424764c7f51a1bfb7eb709b9ccc419e8f1ef2ee8 # Parent cefa2c4077ed261121e72ea4c06aa94f188343dd feat: disable autoformatting, force null-ls formatting in some cases diff -r cefa2c4077ed -r 424764c7f51a .chezmoitemplates/init.lua --- a/.chezmoitemplates/init.lua Wed Oct 05 09:06:12 2022 +0200 +++ b/.chezmoitemplates/init.lua Wed Oct 05 09:19:12 2022 +0200 @@ -405,10 +405,6 @@ 'jose-elias-alvarez/null-ls.nvim', requires = 'nvim-lua/plenary.nvim', } - use { - 'lukas-reineke/lsp-format.nvim', - config = function() require('lsp-format').setup { exclude = { 'sumneko_lua', 'beancount' } } end, - } use { 'folke/lua-dev.nvim' } use { 'smjonas/inc-rename.nvim', @@ -1042,11 +1038,20 @@ local lsp = require 'lspconfig' local null_ls = require 'null-ls' +local lsp_formatting = function(bufnr) + vim.lsp.buf.format { + filter = function(client) + local force_null_ls = { 'lua', 'beancount' } + if vim.tbl_contains(force_null_ls, vim.bo.filetype) then return client.name == 'null-ls' end + return true + end, + bufnr = bufnr, + } +end + local on_attach = function(client) - require('lsp-format').on_attach(client) local nmap = function(lhs, rhs, opts) return vim.keymap.set('n', lhs, rhs, opts) end - vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc' nmap('gp', require('goto-preview').goto_preview_definition, { silent = true, buffer = 0 }) nmap('gP', require('goto-preview').close_all_win, { silent = true, buffer = 0 }) @@ -1058,12 +1063,7 @@ nmap('g0', vim.lsp.buf.document_symbol, { silent = true, buffer = 0 }) nmap('ga', vim.lsp.buf.code_action, { silent = true, buffer = 0 }) - nmap('', function() require('lsp-format').format() end, { - silent = true, - buffer = 0, - }) - - vim.bo.formatexpr = 'v:lua.vim.lsp.formatexpr()' + if client.supports_method 'textDocument/formatting' then nmap('', function() lsp_formatting(0) end) end vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' })