tapayne88 / dotfiles

A place for all my dotfiles and each one in its place
10 stars 0 forks source link

Folds disappear on save when LSP formatting enabled #34

Open tapayne88 opened 2 years ago

tapayne88 commented 2 years ago

Neovim's folds are setup using treesitter (when available). On save of a file, if the LSP supports it the document will be formatted. This process seems to blow away all the treesitter folds.

Manually running :e restores them.

tapayne88 commented 2 years ago

Tried re-setting foldmethod on BufWritePost similar to Filetype detection autocmd https://github.com/tapayne88/dotfiles/blob/f64443fa41de7498a93f0d23a02eeec1dcba0482/dot_config/nvim/lua/tap/plugins/treesitter.lua#L8-L14

augroup("TreesitterFolding2", {
    {
        events = {"BufWritePost"},
        targets = {"<buffer>"},
        command = 'setlocal foldmethod=expr foldexpr=nvim_treesitter#foldexpr()'
    }
})

This doesn't work for some reason

tapayne88 commented 2 years ago

This helps debugging

vi -V9debug1.log packages/create-react-app/src/__tests__/MountApp.test.tsx
tapayne88 commented 2 years ago

After reading this it sounds like an upstream issue https://github.com/neovim/neovim/issues/14977

towry commented 1 year ago

After reading this it sounds like an upstream issue neovim/neovim#14977

Doesn't fix this issue.

towry commented 1 year ago

command = 'setlocal foldmethod=expr foldexpr=nvim_treesitter#foldexpr()'

nvim-treesitter have some bugs and is being rewritten. use v:lua.vim.treeesitter.foldexpr()

tapayne88 commented 1 year ago

command = 'setlocal foldmethod=expr foldexpr=nvim_treesitter#foldexpr()'

nvim-treesitter have some bugs and is being rewritten. use v:lua.vim.treeesitter.foldexpr()

ah, thanks @towry! I'll see if this help! Much appreciated 🙌

ribru17 commented 1 year ago

Have you tried running vim.cmd.mkview() and vim.cmd.loadview() before and after formatting, respectively?