aznhe21 / actions-preview.nvim

Fully customizable previewer for LSP code actions.
GNU General Public License v3.0
365 stars 9 forks source link

Support to Delta #22

Closed KevenGoncalves closed 6 months ago

KevenGoncalves commented 7 months ago

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

ribru17 commented 7 months ago

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.

aznhe21 commented 7 months ago

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.

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

ribru17 commented 7 months ago

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...

aznhe21 commented 7 months ago

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.

KevenGoncalves commented 7 months ago

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

https://github.com/aznhe21/actions-preview.nvim/assets/80492657/145248ff-bf1f-4d82-afd4-e8bc54a5854c

KevenGoncalves commented 7 months ago

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

aznhe21 commented 7 months ago

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

KevenGoncalves commented 6 months ago

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

aznhe21 commented 6 months ago

Hmmm...what is your setting?

KevenGoncalves commented 6 months ago

Hmmm...what is your setting?

I just installed normally using the lazy.nvim

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

ribru17 commented 6 months ago

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>
KevenGoncalves commented 6 months ago

@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]

https://github.com/aznhe21/actions-preview.nvim/assets/80492657/a5112774-0b29-4115-add4-bdf4b6226b47

ribru17 commented 6 months ago

Same, that bug was happening to my branch as well

KevenGoncalves commented 6 months ago

@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

aznhe21 commented 6 months ago

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"),
  },
}
ribru17 commented 6 months ago

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.

ribru17 commented 6 months ago

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?

aznhe21 commented 6 months ago

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.

ribru17 commented 6 months ago

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