aznhe21/actions-preview.nvim

Support to Delta

KevenGoncalves opened this issue · 19 comments

Would be amazing to change the output from diff to delta, if there's any way, let me know,
An example:
Captura de Tela 2023-12-21 às 16 10 16

I have a fork that almost fixes this, but the previews disappear when the user scrolls away and then scrolls back into them. Open to help if anyone knows how to fix this.

Thank you both for your suggestions and tentative implementation!

I'm working on the highlight-commands branch and it is mostly operational on the telescope backend. However, there are these problems that need to be resolved.

  • "[Process exited 0]" at the end
  • Diffs in new files are wrong

I also think it is not good that function names are not displayed in delta (because vim.diff result does not include it).

Thank you, this is amazing! I know that at least for the [Process exited 0] part, that can be fixed by changing the delta setting --paging=never to --paging=always. Unfortunately, for some reason I still get the error (with delta at least) that scrolling away and then back into a preview clears the preview, leaving it blank. Not sure why this is...

With --paging=always, scrolling with preview_scrolling_down/up is not possible, and [Process exited 0] is still displayed if the diff fits on the screen. It is also undesirable to have a command line on the last line.
As for the preview being cleared, it appears to have a height of zero. Maybe it is not a good idea to leave the process running...

P.S.
The command line on the last line seems to be acceptable, as it is in :Telescope planets and so on. Scrolling may also be implemented by setting scroll_fn.

I have a fork that almost fixes this, but the previews disappear when the user scrolls away and then scrolls back into them. Open to help if anyone knows how to fix this.

I tried in macOS and that doesn't happen

my configs:
MacBook Pro M2 2022 13", 8 RAM, macOS Ventura 13.4
Terminal Kitty 0.31.0
Shell Zsh 5.9
Lunarvim 1.3
Delta 0.15.1

Gravacao.de.Tela.2024-01-08.as.09.54.08.mov

Ah, I discovered now, when you choose a different option, it disappears

I have pushed my own implementation of the previewer to highlight-commands branch. I think it works well, so give it a try!

I have pushed my own implementation of the previewer to highlight-commands branch. I think it works well, so give it a try!

I tried the branch but when try to spawn the code actions give an error:

Captura de Tela 2024-01-08 às 14 15 41

Hmmm...what is your setting?

Hmmm...what is your setting?

I just installed normally using the lazy.nvim

Captura de Tela 2024-01-08 às 15 53 48

When I try this branch, I can only get things working when using the default telescope configuration. If I use telescope = {} (which I use to just get my default telescope style) I get no previews, and when I quit out of the previewer I get an error:

E5108: Error executing lua: ...s-preview.nvim/lua/actions-preview/backend/telescope.lua:112: Invalid buffer id: 8
stack traceback:
        [C]: in function 'nvim_buf_delete'
        ...s-preview.nvim/lua/actions-preview/backend/telescope.lua:112: in function '_teardown_func'
        ...zy/telescope.nvim/lua/telescope/previewers/previewer.lua:79: in function 'teardown'
        ...share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:1569: in function 'on_close_prompt'
        .../nvim/lazy/telescope.nvim/lua/telescope/actions/init.lua:386: in function 'run_replace_or_original'
        ...re/nvim/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
        ...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:261: in function <...hare/nvim/lazy/telescope.nvim/lua/t
elescope/mappings.lua:260>

@ribru17
The only problem right now that I'm finding is to finish the implementation to get the buff to re-run the code-action when change between options:
[bug that is happening]

Gravacao.de.Tela.2024-01-09.as.10.28.57.mov

Same, that bug was happening to my branch as well

@ribru17 @aznhe21
Today I found a new bug in your implementation @ribru17 , some of the code actions doesn't show the preview with delta but the native implementation with diff works

With Delta
Captura de Tela 2024-01-12 às 12 21 51

With Diff
Captura de Tela 2024-01-12 às 12 20 35

The default setting is disabled, but this feature has been merged in #26. You can enable it with the following configuration, so please give it a try:

local hl = require("actions-preview.highlight")
require("actions-preview").setup {
  highlight_command = {
    hl.delta("delta --no-gitconfig --side-by-side"),
  },
}

Thank you for continuing to look into this! It works for me with the default config, but I like to use

require('actions-preview').setup {
  backend = { 'telescope' },
  telescope = {},
  highlight_command = {
    hl.delta('delta --no-gitconfig --side-by-side'),
  },
}

to get actions preview to inherit my default telescope ui layout. When I do this, however, the preview disappears for some reason.

Ok I have done some testing and figured it out. In my config I have it so that terminal buffer instances are killed once the process has terminated (to prevent showing Exited 0 type messages). In nightly, this is done without the need for a configuration as they have made it standard. However, this breaks previewing if the delta command executes and there is no paging. I discovered this because setting a very small height (so that the pager has to scroll) allows the preview to show up still. But if the entire preview fits in the height, it disappears. The solution is to add --paging=always to the delta command. This makes everything work for me, as the command always pages (and doesn't exit) even if everything fits in the window height. Maybe this should be specified as a default/recommended argument in the documentation?

Wow, so there's such a feature in the nightly build.

I did take a look at the PR (neovim/neovim#15440) where that feature was introduced, and it seems like the functionality is triggered only in terminals without arguments. Therefore, it seems unlikely that such a bug would occur. I couldn't replicate it in my environment. Please double-check your configurations.

Ah ok, I guess it is fine then. Thank you!