FuzzyCompletions.jl

Fuzzy completion provider for Julia
Author JunoLab
Popularity
14 Stars
Updated Last
1 Year Ago
Started In
February 2020

FuzzyCompletions.jl

FuzzyCompletions provides fuzzy completions for a Julia runtime session.

Its API is totally compatible with the standard library module REPL.REPLCompletions; so this package can be used as a drop-in replacement for your completion provider.

example

You can make your REPL complete fuzzily with the following code:

using REPL
using REPL.LineEdit
using FuzzyCompletions

struct FuzzyCompletionProvider <: REPL.CompletionProvider
    mod::Module
end

function LineEdit.complete_line(c::FuzzyCompletionProvider, s)
  partial = REPL.beforecursor(s.input_buffer)
  full = LineEdit.input_string(s)

  # module-aware repl backend completions
  comps, range, should_complete = completions(full, lastindex(partial), c.mod)
  filter!(c->score(c)0, comps)
  return unique!(FuzzyCompletions.completion_text.(comps)), partial[range], should_complete
end

Base.active_repl.interface.modes[1].complete = FuzzyCompletionProvider(Main) # or whatever module where you want to get completes from

Then, your REPL will work like

julia> sthing
isnothing something # fuzzy completions

julia> regex<tab>
Regex      RegexMatch # cases doesn't need to match

But I'm sure you will dislike this behavior; we usually want CLI to complete eagerly, not to be an indecisive boy.

consumers

Fuzzy completions can be useful within IDE or somewhere some richer UI for showing/selecting completion suggestions is available:

acknowledgment

The original idea of the implementation came from this patch by @pfitzseb.

license

This package is under MIT License.

Required Packages

No packages found.