comparison .chezmoitemplates/init.lua @ 690:424764c7f51a

feat: disable autoformatting, force null-ls formatting in some cases
author zegervdv <zegervdv@me.com>
date Wed, 05 Oct 2022 09:19:12 +0200
parents 6e98364a5a28
children 989cedcc0a38
comparison
equal deleted inserted replaced
689:cefa2c4077ed 690:424764c7f51a
403 } 403 }
404 use { 404 use {
405 'jose-elias-alvarez/null-ls.nvim', 405 'jose-elias-alvarez/null-ls.nvim',
406 requires = 'nvim-lua/plenary.nvim', 406 requires = 'nvim-lua/plenary.nvim',
407 } 407 }
408 use {
409 'lukas-reineke/lsp-format.nvim',
410 config = function() require('lsp-format').setup { exclude = { 'sumneko_lua', 'beancount' } } end,
411 }
412 use { 'folke/lua-dev.nvim' } 408 use { 'folke/lua-dev.nvim' }
413 use { 409 use {
414 'smjonas/inc-rename.nvim', 410 'smjonas/inc-rename.nvim',
415 config = function() 411 config = function()
416 require('inc_rename').setup { 412 require('inc_rename').setup {
1040 1036
1041 -- LSP config 1037 -- LSP config
1042 local lsp = require 'lspconfig' 1038 local lsp = require 'lspconfig'
1043 local null_ls = require 'null-ls' 1039 local null_ls = require 'null-ls'
1044 1040
1041 local lsp_formatting = function(bufnr)
1042 vim.lsp.buf.format {
1043 filter = function(client)
1044 local force_null_ls = { 'lua', 'beancount' }
1045 if vim.tbl_contains(force_null_ls, vim.bo.filetype) then return client.name == 'null-ls' end
1046 return true
1047 end,
1048 bufnr = bufnr,
1049 }
1050 end
1051
1045 local on_attach = function(client) 1052 local on_attach = function(client)
1046 require('lsp-format').on_attach(client)
1047 local nmap = function(lhs, rhs, opts) return vim.keymap.set('n', lhs, rhs, opts) end 1053 local nmap = function(lhs, rhs, opts) return vim.keymap.set('n', lhs, rhs, opts) end
1048 1054
1049 vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
1050 nmap('gp', require('goto-preview').goto_preview_definition, { silent = true, buffer = 0 }) 1055 nmap('gp', require('goto-preview').goto_preview_definition, { silent = true, buffer = 0 })
1051 nmap('gP', require('goto-preview').close_all_win, { silent = true, buffer = 0 }) 1056 nmap('gP', require('goto-preview').close_all_win, { silent = true, buffer = 0 })
1052 1057
1053 nmap('gd', vim.lsp.buf.declaration, { silent = true, buffer = 0 }) 1058 nmap('gd', vim.lsp.buf.declaration, { silent = true, buffer = 0 })
1054 nmap('K', vim.lsp.buf.hover, { silent = true, buffer = 0 }) 1059 nmap('K', vim.lsp.buf.hover, { silent = true, buffer = 0 })
1056 nmap('1gD', vim.lsp.buf.type_definition, { silent = true, buffer = 0 }) 1061 nmap('1gD', vim.lsp.buf.type_definition, { silent = true, buffer = 0 })
1057 nmap('gr', vim.lsp.buf.references, { silent = true, buffer = 0 }) 1062 nmap('gr', vim.lsp.buf.references, { silent = true, buffer = 0 })
1058 nmap('g0', vim.lsp.buf.document_symbol, { silent = true, buffer = 0 }) 1063 nmap('g0', vim.lsp.buf.document_symbol, { silent = true, buffer = 0 })
1059 nmap('ga', vim.lsp.buf.code_action, { silent = true, buffer = 0 }) 1064 nmap('ga', vim.lsp.buf.code_action, { silent = true, buffer = 0 })
1060 1065
1061 nmap('<c-p>', function() require('lsp-format').format() end, { 1066 if client.supports_method 'textDocument/formatting' then nmap('<c-p>', function() lsp_formatting(0) end) end
1062 silent = true,
1063 buffer = 0,
1064 })
1065
1066 vim.bo.formatexpr = 'v:lua.vim.lsp.formatexpr()'
1067 1067
1068 vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) 1068 vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' })
1069 vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) 1069 vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' })
1070 end 1070 end
1071 1071