diff --git a/nvim/.config/nvim/lua/lsp.lua b/nvim/.config/nvim/lua/lsp.lua index 6e0fe11..13582be 100644 --- a/nvim/.config/nvim/lua/lsp.lua +++ b/nvim/.config/nvim/lua/lsp.lua @@ -6,6 +6,19 @@ local null_ls = require("null-ls") local util = require("lspconfig/util") -- https://github.com/neovim/nvim-lspconfig/wiki/User-contributed-tips +function format_range_operator() + local old_func = vim.go.operatorfunc + _G.op_func_formatting = function() + local start = vim.api.nvim_buf_get_mark(0, '[') + local finish = vim.api.nvim_buf_get_mark(0, ']') + vim.lsp.buf.range_formatting({}, start, finish) + vim.go.operatorfunc = old_func + _G.op_func_formatting = nil + end + vim.go.operatorfunc = 'v:lua.op_func_formatting' + vim.api.nvim_feedkeys('g@', 'n', false) +end + local function preview_location_callback(_, result) if result == nil or vim.tbl_isempty(result) then return nil @@ -58,7 +71,7 @@ local on_attach = function(client, bufnr) if client.resolved_capabilities.document_formatting then vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', 'lua vim.lsp.buf.formatting()', opts) elseif client.resolved_capabilities.document_range_formatting then - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', 'lua vim.lsp.buf.formatting()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', 'lua format_range_operator()', opts) end if client.resolved_capabilities.code_lens then