linrongbin16 / fzfx.nvim

A Neovim fuzzy finder that updates on every keystroke.
https://linrongbin16.github.io/fzfx.nvim/
MIT License
122 stars 5 forks source link

Preview using nVim instead of `cat` or `bat` #491

Closed savchenko closed 7 months ago

savchenko commented 9 months ago

Is it technically possible? Having consistent colourscheme would be great.

linrongbin16 commented 9 months ago

Is it technically possible? Having consistent colourscheme would be great.

hi, it should be possible, but it requires a lot of effort, and I had once did a little investigation on the solution.

the nvim preview should be a nvim buffer and float window that open an read only file.

but now I still don't know how to do it.

the fzf-lua can do it, but I don't understand the source code. it should be the builtin previewer: https://github.com/ibhagwan/fzf-lua/blob/main/lua/fzf-lua/previewer/builtin.lua

the solution is relate to several things:

linrongbin16 commented 9 months ago

it's also one of the very important feature I want to add to it, for very long time.

I will look into it.

linrongbin16 commented 7 months ago

the first buffer previewer work is at: https://github.com/linrongbin16/fzfx.nvim/pull/556

for now it can only preview file content (but I think it's the only major use case), without line number support (I will support line numbers for live grep in next PR).


The nvim buffer previewer is merged into main branch, but the key mappings (toggle-preview, scroll-half-page-down, etc) are not implemented.

I will do it in next PR.

linrongbin16 commented 7 months ago

hi @savchenko , after #557 and #564 been merged into main branch, can you take a look if current bat previewer is good enough?

I will say it's about 85% close to native nvim buffer.

The nvim buffer previewer is also usable, but it's still experimental, it's sometimes super laggy.

I am a little tired of maintaining two separated implementation of previewers, improve bat theme is much easier than nvim buffer. The nvim buffer eats a lof of effort and time, like a black hole.

savchenko commented 7 months ago

Hi @linrongbin16, the last release does not behave as usual. For example, selecting multiple entries returns:

Error executing vim.schedule lua callback: ...l/share/nvim/lazy/fzfx.nvim/lua/fzfx/commons/strings.lua:180: assertion failed!
stack traceback:
        [C]: in function 'assert'
        ...l/share/nvim/lazy/fzfx.nvim/lua/fzfx/commons/strings.lua:180: in function 'replace'
        ...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:536: in function '_render_theme'
        ...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:580: in function '_build_theme'
        ...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:641: in function <...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:638

...and the search is now very particular about escape character (?!). Check this out:

image

...add a single bracket...

image

Might be an issue on my side, however I haven't touched fzfx config for some time.

linrongbin16 commented 7 months ago

hi @savchenko,

It looks like an exception throwed. But I cannot find the _render_theme function in current bat_helpers.lua.

can you check the git commit of the plugin you're using? seems it's not the latest main branch.

And also, please enable the debug mode with:

require('fzfx').setup({
  debug={
    enable=true,
    file_log=true,
  }
})

then upload the log here, and I will check.

linrongbin16 commented 7 months ago

hi @savchenko , this issue could be the same issue with #575 , and I just fixed it in #576 .

Would you please pull main branch and try again? see if this issue still exists.

savchenko commented 7 months ago

Updated again, the error is gone. Further setting $BAT_THEME to one generated by fzfx.nvim results in a reasonably close match:

02-Feb_20-07-35

linrongbin16 commented 7 months ago

Updated again, the error is gone. Further setting $BAT_THEME to one generated by fzfx.nvim results in a reasonably close match:

02-Feb_20-07-35

It's automatically generated, you don't need to specify it in BAT_THEME

linrongbin16 commented 7 months ago

I am trying to improve the converter (from nvim syntax to TextMate theme) again and again, to make it closer.

savchenko commented 7 months ago

The issue with ( breaking the search functionality is still present though.

Attaching fzfx.log: fzfx.log

Content of the _live_grep_last_query_cache:

{"default_provider":"restricted_mode","query":"vim.fn.expand("}
savchenko commented 7 months ago

It's automatically generated, you don't need to specify it in BAT_THEME

I define BAT_THEME in ~/.profile and unless it's set to the generate theme, one in the ~/.profile takes precedence.

linrongbin16 commented 7 months ago

The issue with ( breaking the search functionality is still present though.

Attaching fzfx.log: fzfx.log

Content of the _live_grep_last_query_cache:

{"default_provider":"restricted_mode","query":"vim.fn.expand("}

hi @savchenko ,

image

when you type vim.fn.expand(, the rg command actually executed in the underground is rg --column -n --no-heading --color=always -H -S -- vim.fn.expand(.

If you type above command in your terminal, it's true that there's nothing output from rg.

To solve this issue, you could enter vim.fn.expand( -- -F in this plugin. it will run below commands in the underground:

rg --column -n --no-heading --color=always -H -S -F -- vim.fn.expand(

And it will search vim.fn.expand( for you.

Also type rg --help for more details about -F option.

linrongbin16 commented 7 months ago

591 is merged into main branch, close this ticket for now. I will enable buffer previewer for more and more commands in follow PRs.