Skip to content
Myr

Reward non-word match at word boundary

Before adoption: this commit came in with the history the project adopted, so no landing records it.

A non-word character (e.g. '.') used to receive a flat bonusNonWord regardless of context. Now it gets bonusBoundaryWhite at the start of input and bonusBoundaryDelimiter right after a delimiter, matching the treatment of word characters at the same boundaries. Without this, '.completion' matching '.completion' lost to 'bash_completion.d/completions/X' because the consecutive chunk anchor in the long path (the 'c' after '/') received bonusBoundaryDelimiter while the exact match's '.' was capped at bonusNonWord. Fix #4795

authored by Junegunn Choi · committed by Junegunn Choi · parent 263eb47 · Browse files · 2 files+10 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−1 removed

  • other:+10 added−1 removed

2 files+10 added−1 removed

modified:src/algo/algo_test.go+9 added
55 unmodified lines
56 assertMatch(t, fn, false, forward, "/man1/zshcompctl.1", "zshc", 6, 10,57 scoreMatch*4+int(bonusBoundaryDelimiter)*bonusFirstCharMultiplier+int(bonusBoundaryDelimiter)*3)58 assertMatch(t, fn, false, forward, "/.oh-my-zsh/cache", "zshc", 8, 13,59 scoreMatch*4+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary*2+scoreGapStart+int(bonusBoundaryDelimiter))60 // Non-word character at start of input is treated as a strong boundary61 assertMatch(t, fn, false, forward, ".vimrc", ".vimrc", 0, 6,62 scoreMatch*6+int(bonusBoundaryWhite)*(bonusFirstCharMultiplier+5))63 // Non-word character right after a delimiter inherits the delimiter boundary64 assertMatch(t, fn, false, forward, "/.vimrc", ".vimrc", 1, 7,65 scoreMatch*6+int(bonusBoundaryDelimiter)*(bonusFirstCharMultiplier+5))66 // Non-word character in the middle of a word stays at bonusNonWord67 assertMatch(t, fn, false, forward, "a.vimrc", ".vimrc", 1, 7,68 scoreMatch*6+bonusBoundary*(bonusFirstCharMultiplier+5))69 assertMatch(t, fn, false, forward, "ab0123 456", "12356", 3, 10,70 scoreMatch*5+bonusConsecutive*3+scoreGapStart+scoreGapExtension)71 assertMatch(t, fn, false, forward, "abc123 456", "12356", 3, 10,72 scoreMatch*5+bonusCamel123*bonusFirstCharMultiplier+bonusCamel123*2+bonusConsecutive+scoreGapStart+scoreGapExtension)
148 unmodified lines
modified:src/algo/algo.go+1 added-1 removed
264 unmodified lines
265 return charClassOfNonAscii(char)266}267268func bonusFor(prevClass charClass, class charClass) int16 {269 if class > charNonWord {269 if class >= charNonWord {270 switch prevClass {271 case charWhite:272 // Word boundary after whitespace273 return bonusBoundaryWhite
757 unmodified lines