fuzzy

package
v1.142.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

pkg/fuzzy

fuzzy.Score is the fuzzy matcher behind search_tool in pkg/tools/builtin/deferred. It wraps a pure-Go extraction of fzf's FuzzyMatchV2, so it builds and runs on every GOOS/GOARCH, including js/wasm where github.com/junegunn/fzf/src/util does not compile (syscall.Exec, Setpgid, unix.Dup2).

The upstream module stays in go.mod: the TUI completion popup and the model picker still import it directly.

Provenance

Extracted by hand from https://github.com/junegunn/fzf at v0.74.4 (module cache github.com/junegunn/fzf@v0.74.4), MIT licensed, Copyright (c) 2013-2026 Junegunn Choi. The license is in LICENSE.fzf. These files are not generated; there is no extraction script.

Here Upstream Notes
fzfalgo/algo.go src/algo/algo.go FuzzyMatchV2, its FuzzyMatchV1 fallback and shared helpers only
fzfalgo/normalize.go src/algo/normalize.go table verbatim; NormalizeRunes dropped
fzfalgo/scan.go src/algo/indexbyte2_other.go, src/algo/runeindex_ref.go portable reference scanners, build tags removed
fzfutil/chars.go src/util/chars.go Chars rewritten without unsafe; matcher-facing API only
fzfutil/slab.go src/util/slab.go verbatim
Deviations from upstream

Behavior-preserving only; fzfalgo tests compare against the upstream package on native platforms (!js).

  • Import path github.com/junegunn/fzf/src/utilpkg/fuzzy/fzfutil.
  • Dropped: ExactMatchNaive, ExactMatchBoundary, PrefixMatch, SuffixMatch, EqualMatch, bonusAt, the Algo type, DEBUG/debugV2, and the disableSingle/disableTwo/disableRunePrefilter test hooks.
  • Dropped: amd64/arm64 assembly and the 386 byte-view rune scanners; the reference implementations are used everywhere.
  • fzfutil.Chars stores bytes/runes in two fields instead of one unsafe-reinterpreted slice, and keeps only ToChars, IsBytes, MayFoldToASCII, Bytes, Runes, Get, Length, CopyRunes.
  • Lint-driven cosmetics: AsciiASCII in identifiers, if/else chains → switch, combined parameter types, posArray(len)posArray(n), indexAt(max)indexAt(length), slices.Backward in lastIndexByteTwo, //nolint:gosec on guarded rune → byte conversions.
Init is not called

Upstream fills its ASCII class and bonus tables in algo.Init(scheme), which fzf calls from option parsing. The callers in this repository never called it, so fuzzy.Score runs fzfalgo uninitialized on purpose to keep scores identical to what they were. fzfalgo.Init is kept so that turning bonuses on is a deliberate one-line change, covered by the Init("default") half of the parity tests.

Updating

Diff src/algo/algo.go, src/algo/normalize.go, src/algo/runeindex_ref.go, src/algo/indexbyte2_other.go and src/util/chars.go between the recorded version and the new one, port the changes, bump the version here and in the file headers, then run:

go test ./pkg/fuzzy/...
GOOS=js GOARCH=wasm go test -exec="$(go env GOROOT)/lib/wasm/go_js_wasm_exec" ./pkg/fuzzy/...

Documentation

Overview

Package fuzzy scores text against a pattern with fzf's FuzzyMatchV2, using a pure-Go extraction of the algorithm (see fzfalgo) so it builds on every platform, js/wasm included.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Score

func Score(text string, pattern []rune) (score int, matched bool)

Score runs a case-insensitive, normalizing, forward FuzzyMatchV2 of pattern over text and reports the score and whether the pattern matched. Callers must lowercase pattern themselves; an empty pattern matches with score 0.

It uses fzfalgo in its uninitialized state, the same state the upstream package was used in before this extraction, so scores are bit-for-bit identical to what github.com/junegunn/fzf/src/algo produced here.

Types

This section is empty.

Directories

Path Synopsis
Package fzfalgo is a pure-Go extraction of fzf's fuzzy matcher, kept so it builds on every GOOS/GOARCH including js/wasm.
Package fzfalgo is a pure-Go extraction of fzf's fuzzy matcher, kept so it builds on every GOOS/GOARCH including js/wasm.
Package fzfutil holds the text container used by fzfalgo.
Package fzfutil holds the text container used by fzfalgo.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL