Fuzzy matching and compliment-style ranking#56
Closed
bbatsov wants to merge 3 commits into
Closed
Conversation
Completion was prefix-only, while compliment matches fuzzily: `pr-fn` completes `print-function`, `cs` completes `clojure.string`. Since compliment's core doesn't re-match what a source returns, our prefix filter was the hard ceiling on this. candidate-match? now mirrors compliment's per-kind rules via compliment.utils/fuzzy-matches?: `.`-separated fuzzy for namespaces and classes, `-`-separated fuzzy for everything var-like, and plain prefix matching for keywords (which compliment also keeps prefix-only).
compliment attaches a :priority to each candidate (lower sorts first) and its core sorts the pooled candidates by it; ours had none, so every candidate landed in the same bottom bucket and only sorted by length. Candidates now carry the same priorities compliment uses for Clojure: a var in the current ns first (30), then cljs.core (31), then namespaces (50 for cljs.*/clojure.*, 51 otherwise), then classes (60). Keywords and special forms stay unranked, exactly like compliment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #55 - review/merge that one first (the base retargets to master once it lands).
Two steps toward parity with compliment's Clojure completion:
Fuzzy matching. Completion was prefix-only; compliment matches fuzzily, so
pr-fncompletesprint-functionandcscompletesclojure.string. Since compliment's core doesn't re-match what a source returns, our prefix filter was the hard ceiling.candidate-match?now usescompliment.utils/fuzzy-matches?with the same per-kind rules compliment uses:.-separated fuzzy for namespaces/classes,--separated fuzzy for vars/macros/etc., and plain prefix for keywords.Ranking. compliment attaches a
:priorityto each candidate and sorts by it; ours had none, so everything tied at the bottom and only sorted by length. Candidates now carry the same priorities compliment uses - current-ns vars first, thencljs.core, then namespaces, then classes - with keywords and special forms left unranked.Both are covered by new tests in the (now actually running, thanks to #55) static suite, green under CLJS 1.11 and 1.12.