-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hinting similiar commands #151 #152
base: master
Are you sure you want to change the base?
Conversation
Looks really good! Could you add in some tests? I would be interested to see the relative results based on different sets of registered commands. 4 seems like a really high edit distance. For example, if you have the commands |
I've just run
Do you have any idea ? If you set maximum distance to 4, it still works for your example because leven distance between |
Node gives that warning when more than 10 (?) listeners are attached to the same emitter. Try The cleaner solution would be to set the maximum for the particular event emitter objects. I was just lazy and copy-pasted that snippet from here. Vorpal should probably do this itself, the threshold doesn't make sense for vorpal anyways. |
Haven't looked far into it, but are you sure we aren't ignoring some problem? Is this because the test instantiates at least 10 instances of Vorpal? While developing it I only got this error when I messed something up on the prompt, and had to fix it. I'm willing to believe the problem is in the repeated use of: mute();
var fixture = '\n fo is an invalid command. Maybe you mean:\n\n foo\n fooz\n bar\n';
help.execSync('fo');
unmute(); |
Let me check again.
When I type |
Yeah, that's all considered one word, and those have a huge edit distance from |
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be greatly simplified with es6 syntax.
eg (untested!):
if (invalidString !== ''){
let catchCmd = this.commands.find(cmd => cmd._catch);
if (!catchCmd){
let hints = this.commands.reduce((foundHints, cmd) => {
if (leven(command, cmd._name) < 4) {
foundHints.push(cmd._name);
}
return foundHints;
}, []);
if (hints.length){
return `\n ${command} is an invalid command. Maybe you mean:\n\n ${hints.join('\n ')}`;
}
}
}
Using
leven
package to calculate the difference between two strings. And displays similiar commands which have leven point smaller than 4.@dthree please check if I'm doing wrong.