comparison .chezmoitemplates/init.lua @ 722:20256729c355

fix: use current bufnr for formatting
author zegervdv <zegervdv@me.com>
date Tue, 06 Dec 2022 21:14:09 +0100
parents 6d036fac4dbd
children e442bbd36b87
comparison
equal deleted inserted replaced
721:0e91f6416812 722:20256729c355
1109 end 1109 end
1110 1110
1111 local on_attach = function(client, bufnr) 1111 local on_attach = function(client, bufnr)
1112 local nmap = function(lhs, rhs, opts) return vim.keymap.set('n', lhs, rhs, opts) end 1112 local nmap = function(lhs, rhs, opts) return vim.keymap.set('n', lhs, rhs, opts) end
1113 1113
1114 nmap('gp', require('goto-preview').goto_preview_definition, { silent = true, buffer = 0 }) 1114 local opts = { silent = true, buffer = bufnr }
1115 nmap('gP', require('goto-preview').close_all_win, { silent = true, buffer = 0 }) 1115
1116 1116 nmap('gp', require('goto-preview').goto_preview_definition, opts)
1117 nmap('gd', vim.lsp.buf.declaration, { silent = true, buffer = 0 }) 1117 nmap('gP', require('goto-preview').close_all_win, opts)
1118 nmap('K', vim.lsp.buf.hover, { silent = true, buffer = 0 }) 1118
1119 nmap('gD', vim.lsp.buf.implementation, { silent = true, buffer = 0 }) 1119 nmap('gd', vim.lsp.buf.declaration, opts)
1120 nmap('1gD', vim.lsp.buf.type_definition, { silent = true, buffer = 0 }) 1120 nmap('K', vim.lsp.buf.hover, opts)
1121 nmap('gr', vim.lsp.buf.references, { silent = true, buffer = 0 }) 1121 nmap('gD', vim.lsp.buf.implementation, opts)
1122 nmap('g0', vim.lsp.buf.document_symbol, { silent = true, buffer = 0 }) 1122 nmap('1gD', vim.lsp.buf.type_definition, opts)
1123 nmap('ga', vim.lsp.buf.code_action, { silent = true, buffer = 0 }) 1123 nmap('gr', vim.lsp.buf.references, opts)
1124 nmap('g0', vim.lsp.buf.document_symbol, opts)
1125 nmap('ga', vim.lsp.buf.code_action, opts)
1124 1126
1125 vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) 1127 vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' })
1126 vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) 1128 vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' })
1127 1129
1128 if client.supports_method 'textDocument/rangeFormatting' then 1130 if client.supports_method 'textDocument/rangeFormatting' then
1131 if root then vcs = vim.fs.basename(root[1]):sub(2) end 1133 if root then vcs = vim.fs.basename(root[1]):sub(2) end
1132 1134
1133 vim.notify('Enabled modification formatting via ' .. vcs .. ' using ' .. client.name, vim.log.levels.INFO) 1135 vim.notify('Enabled modification formatting via ' .. vcs .. ' using ' .. client.name, vim.log.levels.INFO)
1134 local lsp_format_modifications = require 'lsp-format-modifications' 1136 local lsp_format_modifications = require 'lsp-format-modifications'
1135 lsp_format_modifications.attach(client, bufnr, { format_on_save = false, vcs = vcs }) 1137 lsp_format_modifications.attach(client, bufnr, { format_on_save = false, vcs = vcs })
1136 nmap('<c-p>', function() lsp_format_modifications.format_modifications_current_buffer() end) 1138 nmap('<c-p>', function() lsp_format_modifications.format_modifications_current_buffer() end, opts)
1137 elseif client.supports_method 'textDocument/formatting' then 1139 elseif client.supports_method 'textDocument/formatting' then
1138 nmap('<c-p>', function() lsp_formatting(0) end) 1140 nmap('<c-p>', function() lsp_formatting(bufnr) end, opts)
1139 end 1141 end
1140 end 1142 end
1141 1143
1142 local capabilities = require('cmp_nvim_lsp').default_capabilities() 1144 local capabilities = require('cmp_nvim_lsp').default_capabilities()
1143 capabilities.textDocument.completion.completionItem.snippetSupport = true 1145 capabilities.textDocument.completion.completionItem.snippetSupport = true