autocomplete: replace Fuse.js with liblevenshtein

This commit is contained in:
Aviral Dasgupta 2016-12-01 12:06:57 +05:30
parent edd5903ed7
commit 78641a80dd
No known key found for this signature in database
GPG key ID: 5FD1E9F4FFD3DA80
7 changed files with 92 additions and 20 deletions

View file

@ -1,6 +1,6 @@
import React from 'react';
import AutocompleteProvider from './AutocompleteProvider';
import Fuse from 'fuse.js';
import FuzzyMatcher from './FuzzyMatcher';
import {TextualCompletion} from './Components';
const COMMANDS = [
@ -53,7 +53,7 @@ let instance = null;
export default class CommandProvider extends AutocompleteProvider {
constructor() {
super(COMMAND_RE);
this.fuse = new Fuse(COMMANDS, {
this.matcher = new FuzzyMatcher(COMMANDS, {
keys: ['command', 'args', 'description'],
});
}
@ -62,7 +62,7 @@ export default class CommandProvider extends AutocompleteProvider {
let completions = [];
let {command, range} = this.getCurrentCommand(query, selection);
if (command) {
completions = this.fuse.search(command[0]).map(result => {
completions = this.matcher.match(command[0]).map(result => {
return {
completion: result.command + ' ',
component: (<TextualCompletion