FZF sorter for telescope written in c

Overview

telescope-fzf-native.nvim

fzf-native is a c port of fzf. It only covers the algorithm and implements few functions to support calculating the score.

Installation

To get fzf-native working, you need to run make at the root directory. As of now, we do not ship binaries.

vim-plug

Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }

packer.nvim

use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }

Telescope Setup and Configuration:

require('telescope').setup {
  extensions = {
    fzf = {
      override_generic_sorter = false, -- override the generic sorter
      override_file_sorter = true,     -- override the file sorter
      case_mode = "smart_case",        -- or "ignore_case" or "respect_case"
                                       -- the default case_mode is "smart_case"
    }
  }
}
-- To get fzf loaded and working with telescope, you need to call
-- load_extension, somewhere after setup function:
require('telescope').load_extension('fzf')

Developer Interface

This section is only addressed towards developers who plan to use the library (c or lua bindings). This section is not addressed towards users of the telescope extension.

C Interface

slab_t *slab = make_slab(100 * 1024, 2048);
/* case_mode enum: case_smart = 0, case_ignore, case_respect
 * normalize bool: always set to false because its not implemented yet. This
 *                 is reserved for future use
 * pattern char* : pattern you want to match. e.g. "src | lua !.c$
 */
pattern_t *pattern = parse_pattern(case_smart, false, "src | lua !.c$");

/* you can get the score/position for as many items as you want */
get_score(line, pattern, slab);
get_positions(line, pattern, slab);

free_pattern(pattern);
free_slab(slab);

Lua Interface

local fzf = require('fzf_lib')

local slab = fzf.allocate_slab()
-- pattern: string
-- case_mode: number with 0 = smart_case, 1 = ignore_case, 2 = respect_case
local pattern_obj = fzf.parse_pattern(pattern, case_mode)

-- you can get the score/position for as many items as you want
-- line: string
fzf.get_score(line, pattern_obj, slab)
fzf.get_pos(line, pattern_obj, slab)

fzf.free_pattern(pattern_obj)
fzf.free_slab(slab)

Disclaimer

This project is work in progress and might not be complete compared to fzf. But i think we are at a pretty usable state already.

Another point to mention is that, this will not compare 1:1 with fzf, because telescope handles the sorting, this extension is only handling the calculation of the score. This means that the order of items with the same score might be different in telescope compared to fzf.

Example for this behaivor is this pattern in this repository: src | lua. All files that match this pattern have the same score which results in a slightly different order for telescope compared to fzf.

TODO

Stuff still missing that is present in fzf.

  • normalize
  • case for unicode (i don't think this works currently)
  • and probably more

Credit

All credit for the algorithm goes to junegunn and his work on fzf. This is merely a c fork distributed under MIT for telescope.

Comments
  •  This extension doesn't exist or is not installed: fzf

    This extension doesn't exist or is not installed: fzf

    I'm getting the following error when I startup neovim:

     This extension doesn't exist or is not installed: fzf
    

    Not sure what is happening here, if I'm correct the binary should be build automatically.

    opened by tamis-laan 18
  • How can I help with Windows support?

    How can I help with Windows support?

    Hey @Conni2461,

    You may remember me when we you helped me with a couple of PRs for telescope a while ago.

    Anyway, I am primarily a Windows user and spend a bunch of my time helping fix Windows issues with the nvim ecosystem. I can see that this plugin here requires "extra" work for Windows users that probably is not needed if we just bundle the dll with. Unlike Linux, this dll will work on Windows unchanged as it's very simple. Probably doesn't need to be built on the user's machine.

    How can I help? I can see a couple of challenges:

    • How to keep the dll updated as you make changes. I can help here of course by providing a latest. But I can see that as being a problem for scaling. Having said that, it seems that you're not making frequent changes to the code really.
    • How do you/anyone trust that the dll I am producing is safe? I can inject randomness in there. Not sure how to help with that.

    Anyway, I am available to help if it's something you need. This plugin seems almost core to Telescope now from a perf point of view. Windows users will probably not use it since compiling it locally requires extra steps. In the meantime, I will see if there's something I can do to help make building it easier?

    Thanks!

    opened by Nazeehe 14
  • seqmentation fault code dumed

    seqmentation fault code dumed

    while i use grep with this plugin with this command :lua require("telescope.builtin").grep_string({previewer = false, only_sort_text = true, cmd = os.getenv("CD"), search = vim.fn.input("Grep For > ")})

    i am testing in the moodle src code for a project with 27k files and i try to search with grep and type html and then in the result window type html and nvim core dumped

    seqmentation fault (code dumed)

    what do you need more ? ps. the src for moodle can be found in https://download.moodle.org/releases/latest

    opened by seocamo 12
  • Failed to install

    Failed to install

    Hi. I have the following packer config:

     use {                                                        
       'nvim-telescope/telescope.nvim',                           
       requires = {                                               
         {'nvim-lua/popup.nvim'},                                 
         {'nvim-lua/plenary.nvim'},                               
         {'nvim-telescope/telescope-fzy-native.nvim', run="make"},
         {'nvim-telescope/telescope-symbols.nvim'},               
       },                                                         
     }                                                            
    

    After adding run="make" clause I get

    ✗ Failed to install nvim-telescope/telescope-fzy-native.nvim
    

    message when trying to install.

    However, the plugin is installed and I can do

    require("telescope").load_extension("fzy_native")
    

    perfectly fine. I still cannot check if it is really working though.

    opened by horseinthesky 8
  • 🔨 Cleanup CMake to remove warnings + fix windows builds + add presets

    🔨 Cleanup CMake to remove warnings + fix windows builds + add presets

    This change brings in several things

    1. The CMakeLists.txt file has been reorganized and brought up to more "modern" CMake code (while still working with CMake 3.2 at a minimum)
    2. A fix has been added for #77, to always set the suffix to .dll, regardless of toolchain
    3. Warnings for _CRT_SECURE and _CRT_NONSTDC are now disabled.
    4. This also adds the most minimal version of a cmake "preset" for CMake 3.19 and later. This adds generators for unix makefiles and ninja, allowing users to simply execute their post-install step as:
      $ cmake --preset <ninja|make>
      $ cmake --build build --target install
      

    Sadly, this couldn't be simplified further unless a hard minimum of CMake 3.20 is set, as that would allow for an install build preset, allowing the steps to turn into cmake --preset <preset> && cmake --build --preset <preset>. I've not changed the readme as I'm probably the only one who will end up using the preset approach anyhow.

    Closes #77

    opened by bruxisma 7
  • bug: items with the same score should consider length

    bug: items with the same score should consider length

    FZF uses string length as a tiebreaker by default when the score is tied between two results. Would it be possible to implement it in telescope-fzf-native too?

    In FZF:

    image

    In telescope-fzf-native:

    image

    Here in junegunn/fzf the tiebreaker logic is implemented.

    bug 
    opened by ajitid 7
  • build system: windows support + stylua style checker

    build system: windows support + stylua style checker

    Close #24

    @luisiacc Can you try if this works now? Out of the box. So checkout branch and make clean && make

    @ryanreno Can you check if OpenBSD still works after that. I need to force CC=gcc for windows. windows doesn't have cc. I only set it if the OS is windows but i still wanted to ask, if you can test it. Thanks :)

    opened by Conni2461 7
  • telescope-fzf-native doesn't work with Apple M1

    telescope-fzf-native doesn't work with Apple M1

    Hey guys, i've been using fzf with telescope for a while but i recently bought a new MBP with Apple Silicon. When i try to follow the installation and setup instructions, it fails with the following error: telescope-fzf-on-m1-error

    opened by jay-dee7 7
  • Can't check is it working

    Can't check is it working

    I am confused by the way the sorter works this is my custom picker: screenshot_20221019105036

    when I use original fzf plugin for vim I see this: screenshot_20221019104850

    but when I try to use my custom picker in same search I see that result: screenshot_20221019104924

    and also this result is weird: screenshot_20221019105001 screenshot_20221019105007

    and I can't checkhealth, but I saw that you implement this screenshot_20221019104938 in my .config/nvim/plugin/telescope-setup.lua I have that configuration

    -- You dont need to set any of these options. These are the default ones. Only
    -- the loading is important
    require('telescope').setup {
      extensions = {
        fzf = {
          fuzzy = true,                    -- false will only do exact matching
          override_generic_sorter = true,  -- override the generic sorter
          override_file_sorter = true,     -- override the file sorter
          case_mode = "smart_case",        -- or "ignore_case" or "respect_case"
                                           -- the default case_mode is "smart_case"
        }
      }
    }
    -- To get fzf loaded and working with telescope, you need to call
    -- load_extension, somewhere after setup function:
    require('telescope').load_extension('fzf')
    

    and this code in packer plugin:

    use {'nvim-telescope/telescope-fzf-native.nvim', run = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }
    

    NVIM v0.8.0 Build type: Release LuaJIT 2.1.0-beta3

    opened by lumpsoid 6
  • :Telescope fzf yields E5108: Error executing lua ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:184: attempt to call a nil value

    :Telescope fzf yields E5108: Error executing lua ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:184: attempt to call a nil value

    After successful :PackerSync and restart, I still cannot run :Telescope fzf. I get the following error:

    E5108: Error executing lua ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:184: attempt to call a nil value 
    

    This is the relevant part of my config (packer-based, obvs)

        use {
          "nvim-telescope/telescope.nvim",
          requires = {
            "sharkdp/fd",
            "nvim-lua/plenary.nvim",
            {"nvim-telescope/telescope-packer.nvim", requires = "wbthomason/packer.nvim"},
            {"nvim-telescope/telescope-fzf-native.nvim", run = "make"}
          },
          config = function()
            local tscope = require("telescope")
            tscope.setup {}
            tscope.load_extension "packer"
            tscope.load_extension "fzf"
          end
        }
    
    
    opened by elmarsto 6
  • Not a valid Win32 application.

    Not a valid Win32 application.

    I am building libfzf.dll like this:

    gcc -O3 -Wall -Werror -fpic -shared src/fzf.c -o build/libfzf.dll

    gcc --version output:

    gcc.exe (MinGW.org GCC-6.3.0-1) 6.3.0
    Copyright (C) 2016 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    gcc -v output:

    Using built-in specs.
    COLLECT_GCC=C:\MinGW\bin\gcc.exe
    COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
    Target: mingw32
    Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
    Thread model: win32
    gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
    
    Error detected while processing C:\Users\samet\AppData\Local\nvim\init.vim:
    line  149:
    E5108: Error executing lua ...lugged\telescope.nvim\lua\telescope\_extensions\init.lua:11: This extension doesn't exist or is not installed: fzf
    ...t\.vim\plugged\telescope-fzf-native.nvim\lua\fzf_lib.lua:11: cannot load module 'C:\Users\samet\.vim\plugged\telescope-fzf-native.nvim\lua\../build/libfzf.dll': %1 is not a valid Win32 application.
    

    I am currently stuck with this issue!

    opened by sametaylak 6
  • feat: provide prebuilt release binaries and installer

    feat: provide prebuilt release binaries and installer

    fixes #69

    • Re-organised workflows into reusable local composite actions
    • Implemented the creation of releases:
      • pushes to main will create or overwrite an existing dev release
      • pushed tags will create their own release, push the tag again to update that release
      • all binaries are uploaded with filenames that reflect the OS and compiler used
    • Adapted the downloader.lua into a requireable postinstall step.
      • uses curl to do the http lifting
      • uses sh to standardise creating an empty build folder for curl to put the download into

    I tried several methods before landing on curl and sh :

    • http.socket looked nice, except that lazy.nvim doesn't support luarocks like packer.nvim does, and vimplug... well yeah.
    • the github cli, not everyone will have this installed, and even then using it requires the user to first run gh auth login. not everyone will have a github account.
    opened by airtonix 7
  • fzf' extension doesn't exist or isn't installed: loop or previous error loading module 'telescope._extensions.fzf'

    fzf' extension doesn't exist or isn't installed: loop or previous error loading module 'telescope._extensions.fzf'

    Just for context I'm trying to set this up on windows

    when I try require('telescope').load_extension('fzf') and try to source the file :so % I get an error

    Error detected while processing :source (no file):
    E5108: Error executing lua ...lugged\telescope.nvim/lua/telescope/_extensions/init.lua:10: 'fzf' extension doesn't exist or isn't installed: loop or previous error loading module 'telescope._extensions.fzf'
    stack traceback:
            [C]: in function 'error'
            ...lugged\telescope.nvim/lua/telescope/_extensions/init.lua:10: in function 'load_extension'
            ...lugged\telescope.nvim/lua/telescope/_extensions/init.lua:62: in function 'load_extension'
            [string ":source (no file)"]:35: in main chunk
    

    I have tried using both cmake and make to re-install telescope-fzf-native.nvim I even tried the make clean && make from this issue

    opened by crazycodestar 8
  • make option under installation doesn't work for m1 without alteration

    make option under installation doesn't work for m1 without alteration

    following use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } didn't work on m1.

    modifying it to use {'nvim-telescope/telescope-fzf-native.nvim', run = ' arch -arm64 make' } worked.

    just wanted to share, maybe adding a small note in documentation for people running into the same situation.

    opened by jakestrahm 3
  • [Feature request] Adding end criterion

    [Feature request] Adding end criterion

    As file name appear at the end of its path, enabling end criterion would result in accurate matches. This feature would also be helpful in the case of :Telescope tags where in the symbols are present at the end of the line.

    PS: I'm aware about this package of not keeping feature parity with original FZF. If you find this too much of a work or if this feature feels out of scope for this plugin, we can close this issue.

    opened by ajitid 1
Owner
nvim-telescope
An organization to help foster a community around telescope.nvim
nvim-telescope
Parallel bitonic sorter with limited enclave page cache (default 80MB).

Parallel Oblivious Sorter with SGX Parallel bitonic sorter with limited Intel SGX enclave page cache (default 80MB). Compile and Run Compile make clea

ZHENG Leqian 3 Dec 28, 2022
Connect 4 clone written with c++ with the RSGL library. Based on my connect 4 clone written in python/pygame and my SDL port of that same repo. Along with 3DS support by SaCode

RSGL-Connect-4 Building linux git clone https://github.com/RSGL-Org/RSGL-Connect-4.git cd RSGL-Connect-4 make ./Connect4 Bulding 3ds (3ds support

RSGL 1 Dec 28, 2022
KoanLogic 400 Dec 25, 2022
Single file audio playback and capture library written in C.

A single file library for audio playback and capture. Example - Documentation - Supported Platforms - Backends - Major Features - Building - Unofficia

David Reid 2.6k Jan 8, 2023
A hybrid thread / fiber task scheduler written in C++ 11

Marl Marl is a hybrid thread / fiber task scheduler written in C++ 11. About Marl is a C++ 11 library that provides a fluent interface for running tas

Google 1.5k Jan 4, 2023
A lightweight game engine written in modern C++

Halley Game Engine A lightweight game engine written in C++17. It has been used to ship Wargroove, a turn-based strategy game, on Windows, Mac (experi

Rodrigo Braz Monteiro 3.2k Dec 30, 2022
Horde3D is a small 3D rendering and animation engine. It is written in an effort to create an engine being as lightweight and conceptually clean as possible.

Horde3D Horde3D is a 3D rendering engine written in C++ with an effort being as lightweight and conceptually clean as possible. Horde3D requires a ful

Volker Vogelhuber 1.3k Dec 31, 2022
Very low footprint JSON parser written in portable ANSI C

Very low footprint JSON parser written in portable ANSI C. BSD licensed with no dependencies (i.e. just drop the C file into your project) Never recur

James McLaughlin 1.2k Jan 5, 2023
Lightweight JSON library written in C.

About Parson is a lightweight json library written in C. Features Full JSON support Lightweight (only 2 files) Simple API Addressing json values with

Krzysztof Gabis 1.2k Dec 31, 2022
LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C.

libtommath This is the git repository for LibTomMath, a free open source portable number theoretic multiple-precision integer (MPI) library written en

libtom 543 Dec 27, 2022
SymEngine is a fast symbolic manipulation library, written in C++

SymEngine SymEngine is a standalone fast C++ symbolic manipulation library. Optional thin wrappers allow usage of the library from other languages, e.

null 926 Dec 24, 2022
tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)

PicoHTTPParser Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, Shigeo Mitsunari PicoHTTPParser is a tiny, primitive, fast HTTP r

H2O 1.6k Jan 1, 2023
:hocho: Strictly RFC 3986 compliant URI parsing and handling library written in C89; moved from SourceForge to GitHub

uriparser uriparser is a strictly RFC 3986 compliant URI parsing and handling library written in C89 ("ANSI C"). uriparser is cross-platform, fast, su

uriparser 260 Dec 28, 2022
SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.

SWIG (Simplified Wrapper and Interface Generator) Version: 4.1.0 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages

SWIG 4.8k Jan 5, 2023
Vireo is a lightweight and versatile video processing library written in C++11

Overview Vireo is a lightweight and versatile video processing library that powers our video transcoding service, deep learning recognition systems an

Twitter 875 Jan 2, 2023
TinyVM is a small, fast, lightweight virtual machine written in pure ANSI C.

TinyVM is a virtual machine with the goal of having a small footprint. Low memory usage, a small amount of code, and a small binary. Building can be

Joseph Kogut 3k Dec 27, 2022
Semantic version library written in ANSI C

semver.c Semantic version v2.0 parser and render written in ANSI C with zero dependencies. Features Standard compliant (otherwise, open an issue) Vers

Tom 170 Nov 28, 2022
Cross-platform, Serial Port library written in C++

Serial Communication Library (Linux and OS X) (Windows) This is a cross-platform library for interfacing with rs-232 serial like ports written in C++.

William Woodall 1.7k Dec 30, 2022
A portable, simple zip library written in C

A portable (OSX/Linux/Windows), simple zip library written in C This is done by hacking awesome miniz library and layering functions on top of the min

Kuba Podgórski 1.1k Dec 29, 2022
A library for high-performance, modern 2D graphics with SDL written in C.

SDL_gpu, a library for making hardware-accelerated 2D graphics easy. by Jonathan Dearborn SDL_gpu is licensed under the terms of the MIT License. See

Jonathan Dearborn 1.1k Dec 29, 2022