Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for fzy lua #599

Merged
merged 16 commits into from
Dec 16, 2020
Merged

Initial support for fzy lua #599

merged 16 commits into from
Dec 16, 2020

Conversation

liuchengxu
Copy link
Owner

@liuchengxu liuchengxu commented Dec 6, 2020

Close #565

Thanks to https://github.com/swarn/fzy-lua, the basic fzy Lua support in clap is much easier. The next step might be adding a user-friendly way to also support your https://github.com/romgrk/fzy-lua-native @romgrk . Let me know if you have any ideas about that.

I have tested this PR against the latest neovim, but not sure I'll spend more time making it work with the older neovim and vim.

Now it works with both latest neovim and vim.

@romgrk
Copy link
Collaborator

romgrk commented Dec 7, 2020

I've added a single export point to fzy-lua-native, so you should be able to use it by simply requiring the file at fzy-lua-native/lua/init.lua. This file will automatically try to load the native version and fallback to the pure-lua one if that fails. So by loading it you can then use fzy.score or fzy.positions.

Eg

local fzy = dofile('.../path/to/fzy-lua-native/lua/init.lua')
if fzy.has_match(...) then
 ...
end

I use dofile instead of require because it's easier to load a file by absolute path that way.

Note that both the original and native implementation expose a fzy.filter(needle, haystacks, case_sensitive) function but its format differs a bit from the fzy.filter that you have implemented here. If you want it can be modified for our usage, I think the folks at telescope are not using fzy.filter (@tjdevries can you confirm 👍 if we can modify that API? Dont wanna break it for you)

One more thing, I was playing with improvements and have added a fzy.filter_many in the native version, what it does is it loops over the haystacks in C rather than in lua. Haven't had time to make it the default but it probably should be because it brings a 100% improvement over the native-but-loop-in-lua version:
Screenshot from 2020-12-07 17-56-57

For including the package, I'd either copy-paste everything or include as a git submodule. I prefer copy-paste to avoid complexifying the install process of vim-clap.

Last thing, fzy-lua-native includes pre-compiled binaries for linux (x64 and arm), macOS (x64) and windows (x64), so it should be good for most users, but we might want to add a build step in Clap install-binary for this. All that is needed is to run make in the root of fzy-lua-native with gcc installed. I can probably add support for clang if it's there.

@tjdevries
Copy link

@romgrk you can break however is best. 😁 I have your thing as submodule, so it's locked to a particular version. I can upgrade and fix differences as you go.

@liuchengxu
Copy link
Owner Author

@romgrk I have added the Lua support for Vim too. I'll leave the fzy-lua-native integration in the feature PR :(. I prefer to use it as a submodule as multiple files including the various prebuilt .so have to be copied and can bloat the clap repo?

@liuchengxu liuchengxu merged commit af939a8 into master Dec 16, 2020
@delete-merged-branch delete-merged-branch bot deleted the fzy-lua branch December 16, 2020 09:36
@romgrk
Copy link
Collaborator

romgrk commented Dec 17, 2020

👍

TBH fzy-lua-native isn't super useful for clap because there is already the rust backend for the heavy-lifting

@liuchengxu
Copy link
Owner Author

I might be just too greedy :)

@ttys3
Copy link
Contributor

ttys3 commented Jan 5, 2021

this is really awesome!

show current filter impl in lightline plugin:

function! ClapFilterImplStatusLine() abort
   let cur_impl = clap#filter#current_impl()
   return 'Clap: ' . get({
         \   'Lua': luaeval("require'nvim-web-devicons'.get_icon('', 'lua')"),
         \   'Python': luaeval("require'nvim-web-devicons'.get_icon('', 'py')"),
         \   'VimL': luaeval("require'nvim-web-devicons'.get_icon('', 'vim')"),
         \}, cur_impl)
endfunction

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support fzy in lua
4 participants