# HG changeset patch # User Zeger Van de Vannet # Date 1606378037 -3600 # Node ID a1ed17cc354ba57864d21f6dc56dd36cef52205f # Parent f94a7c50a28d7452c449bd406652f847c3ac101b Add a post-formatting handler to reload the buffer This fixes some issues with treesitter highlighting/refactor not working after formatting the buffer. source: https://github.com/lukas-reineke/dotfiles/blob/97b95c9c27cada6ff73080600f724c58f3d7ebfd/vim/lua/lsp.lua#L31 diff -r f94a7c50a28d -r a1ed17cc354b dot_config/nvim/init.lua --- a/dot_config/nvim/init.lua Thu Nov 26 09:06:51 2020 +0100 +++ b/dot_config/nvim/init.lua Thu Nov 26 09:07:17 2020 +0100 @@ -102,6 +102,19 @@ mapper("i", "", "(completion_prev_source)", false) end +vim.lsp.handlers["textDocument/formatting"] = function(err, _, result, _, bufnr) + if err ~= nil or result == nil then + return + end + if not vim.api.nvim_buf_get_option(bufnr, "modified") then + local view = vim.fn.winsaveview() + vim.lsp.util.apply_text_edits(result, bufnr) + vim.fn.winrestview(view) + -- Fix to reload Treesitter + vim.api.nvim_command("edit") + end +end + lsp.pyls.setup{ cmd = {"pyls"}, on_attach = on_attach;