Lower allowed levenshtein distance for suggestions

And update baselines
This commit is contained in:
Nathan Shively-Sanders
2017-05-03 09:42:19 -07:00
parent eb33ba7d97
commit ee1edf0421
20 changed files with 123 additions and 119 deletions

View File

@@ -14197,13 +14197,15 @@ namespace ts {
* except for candidates:
* * With no name
* * Whose meaning doesn't match the `meaning` parameter.
* * Whose length differs from the target name by more than 3.
* * Whose levenshtein distance is more than 0.7 of the length of the name
* (0.7 allows identifiers of length 3 to have a distance of 2 to allow for one substitution)
* * Whose length differs from the target name by more than 0.3 of the length of the name.
* * Whose levenshtein distance is more than 0.4 of the length of the name
* (0.4 allows 1 substitution/transposition for every 5 characters,
* and 1 insertion/deletion at 3 characters)
* Names longer than 30 characters don't get suggestions because Levenshtein distance is an n**2 algorithm.
*/
function getSpellingSuggestionForName(name: string, symbols: Symbol[], meaning: SymbolFlags): Symbol | undefined {
const worstDistance = name.length * 0.7;
const worstDistance = name.length * 0.4;
const maximumLengthDifference = Math.min(4, name.length * 0.34);
let bestDistance = Number.MAX_VALUE;
let bestCandidate = undefined;
if (name.length > 30) {
@@ -14211,16 +14213,18 @@ namespace ts {
}
name = name.toLowerCase();
for (const candidate of symbols) {
if (candidate.flags & meaning && candidate.name && Math.abs(candidate.name.length - name.length) < 4) {
if (candidate.flags & meaning &&
candidate.name &&
Math.abs(candidate.name.length - name.length) < maximumLengthDifference) {
const candidateName = candidate.name.toLowerCase();
if (candidateName === name) {
return candidate;
}
if (candidateName.length < 3) {
if (candidateName.length < 3 || name.length < 3) {
continue;
}
const distance = levenshtein(candidateName, name);
if (distance < 2) {
if (distance < 3) {
return candidate;
}
else if (distance < bestDistance && distance < worstDistance) {