mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-18 13:59:04 -05:00
Lower allowed levenshtein distance for suggestions
And update baselines
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user