Skip to content

Commit ee1edf0

Browse files
committed
Lower allowed levenshtein distance for suggestions
And update baselines
1 parent eb33ba7 commit ee1edf0

20 files changed

+123
-119
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14197,30 +14197,34 @@ namespace ts {
1419714197
* except for candidates:
1419814198
* * With no name
1419914199
* * Whose meaning doesn't match the `meaning` parameter.
14200-
* * Whose length differs from the target name by more than 3.
14201-
* * Whose levenshtein distance is more than 0.7 of the length of the name
14202-
* (0.7 allows identifiers of length 3 to have a distance of 2 to allow for one substitution)
14200+
* * Whose length differs from the target name by more than 0.3 of the length of the name.
14201+
* * Whose levenshtein distance is more than 0.4 of the length of the name
14202+
* (0.4 allows 1 substitution/transposition for every 5 characters,
14203+
* and 1 insertion/deletion at 3 characters)
1420314204
* Names longer than 30 characters don't get suggestions because Levenshtein distance is an n**2 algorithm.
1420414205
*/
1420514206
function getSpellingSuggestionForName(name: string, symbols: Symbol[], meaning: SymbolFlags): Symbol | undefined {
14206-
const worstDistance = name.length * 0.7;
14207+
const worstDistance = name.length * 0.4;
14208+
const maximumLengthDifference = Math.min(4, name.length * 0.34);
1420714209
let bestDistance = Number.MAX_VALUE;
1420814210
let bestCandidate = undefined;
1420914211
if (name.length > 30) {
1421014212
return undefined;
1421114213
}
1421214214
name = name.toLowerCase();
1421314215
for (const candidate of symbols) {
14214-
if (candidate.flags & meaning && candidate.name && Math.abs(candidate.name.length - name.length) < 4) {
14216+
if (candidate.flags & meaning &&
14217+
candidate.name &&
14218+
Math.abs(candidate.name.length - name.length) < maximumLengthDifference) {
1421514219
const candidateName = candidate.name.toLowerCase();
1421614220
if (candidateName === name) {
1421714221
return candidate;
1421814222
}
14219-
if (candidateName.length < 3) {
14223+
if (candidateName.length < 3 || name.length < 3) {
1422014224
continue;
1422114225
}
1422214226
const distance = levenshtein(candidateName, name);
14223-
if (distance < 2) {
14227+
if (distance < 3) {
1422414228
return candidate;
1422514229
}
1422614230
else if (distance < bestDistance && distance < worstDistance) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/compiler/breakInIterationOrSwitchStatement4.ts(1,15): error TS2552: Cannot find name 'something'. Did you mean 'String'?
1+
tests/cases/compiler/breakInIterationOrSwitchStatement4.ts(1,15): error TS2304: Cannot find name 'something'.
22

33

44
==== tests/cases/compiler/breakInIterationOrSwitchStatement4.ts (1 errors) ====
55
for (var i in something) {
66
~~~~~~~~~
7-
!!! error TS2552: Cannot find name 'something'. Did you mean 'String'?
7+
!!! error TS2304: Cannot find name 'something'.
88
break;
99
}

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(254,21): error T
6464
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(254,44): error TS2369: A parameter property is only allowed in a constructor implementation.
6565
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(254,69): error TS1110: Type expected.
6666
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,9): error TS1128: Declaration or statement expected.
67-
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,16): error TS2552: Cannot find name 'Overloads'. Did you mean 'Overloading'?
68-
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,26): error TS2552: Cannot find name 'value'. Did you mean 'eval'?
67+
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,16): error TS2304: Cannot find name 'Overloads'.
68+
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,26): error TS2304: Cannot find name 'value'.
6969
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,31): error TS1005: ',' expected.
7070
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,33): error TS2552: Cannot find name 'string'. Did you mean 'String'?
7171
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,9): error TS1128: Declaration or statement expected.
72-
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,16): error TS2552: Cannot find name 'Overloads'. Did you mean 'Overloading'?
72+
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,16): error TS2304: Cannot find name 'Overloads'.
7373
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error TS1135: Argument expression expected.
7474
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected.
7575
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,35): error TS2552: Cannot find name 'string'. Did you mean 'String'?
@@ -80,7 +80,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error T
8080
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS2304: Cannot find name 'public'.
8181
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS1005: ';' expected.
8282
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS2304: Cannot find name 'DefaultValue'.
83-
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error TS2552: Cannot find name 'value'. Did you mean 'eval'?
83+
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error TS2304: Cannot find name 'value'.
8484
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,35): error TS1109: Expression expected.
8585
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2552: Cannot find name 'string'. Did you mean 'String'?
8686
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,55): error TS1005: ';' expected.
@@ -480,9 +480,9 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
480480
~~~~~~
481481
!!! error TS1128: Declaration or statement expected.
482482
~~~~~~~~~
483-
!!! error TS2552: Cannot find name 'Overloads'. Did you mean 'Overloading'?
483+
!!! error TS2304: Cannot find name 'Overloads'.
484484
~~~~~
485-
!!! error TS2552: Cannot find name 'value'. Did you mean 'eval'?
485+
!!! error TS2304: Cannot find name 'value'.
486486
~
487487
!!! error TS1005: ',' expected.
488488
~~~~~~
@@ -491,7 +491,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
491491
~~~~~~
492492
!!! error TS1128: Declaration or statement expected.
493493
~~~~~~~~~
494-
!!! error TS2552: Cannot find name 'Overloads'. Did you mean 'Overloading'?
494+
!!! error TS2304: Cannot find name 'Overloads'.
495495
~~~~~
496496
!!! error TS1135: Argument expression expected.
497497
~
@@ -515,7 +515,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
515515
~~~~~~~~~~~~
516516
!!! error TS2304: Cannot find name 'DefaultValue'.
517517
~~~~~
518-
!!! error TS2552: Cannot find name 'value'. Did you mean 'eval'?
518+
!!! error TS2304: Cannot find name 'value'.
519519
~
520520
!!! error TS1109: Expression expected.
521521
~~~~~~
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/compiler/continueInIterationStatement4.ts(1,15): error TS2552: Cannot find name 'something'. Did you mean 'String'?
1+
tests/cases/compiler/continueInIterationStatement4.ts(1,15): error TS2304: Cannot find name 'something'.
22

33

44
==== tests/cases/compiler/continueInIterationStatement4.ts (1 errors) ====
55
for (var i in something) {
66
~~~~~~~~~
7-
!!! error TS2552: Cannot find name 'something'. Did you mean 'String'?
7+
!!! error TS2304: Cannot find name 'something'.
88
continue;
99
}

tests/baselines/reference/fixSignatureCaching.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ tests/cases/conformance/fixSignatureCaching.ts(970,18): error TS2339: Property '
6464
tests/cases/conformance/fixSignatureCaching.ts(975,16): error TS2304: Cannot find name 'module'.
6565
tests/cases/conformance/fixSignatureCaching.ts(975,42): error TS2304: Cannot find name 'module'.
6666
tests/cases/conformance/fixSignatureCaching.ts(976,37): error TS2304: Cannot find name 'module'.
67-
tests/cases/conformance/fixSignatureCaching.ts(977,23): error TS2552: Cannot find name 'define'. Did you mean 'undefined'?
68-
tests/cases/conformance/fixSignatureCaching.ts(977,48): error TS2552: Cannot find name 'define'. Did you mean 'undefined'?
69-
tests/cases/conformance/fixSignatureCaching.ts(978,16): error TS2552: Cannot find name 'define'. Did you mean 'undefined'?
67+
tests/cases/conformance/fixSignatureCaching.ts(977,23): error TS2304: Cannot find name 'define'.
68+
tests/cases/conformance/fixSignatureCaching.ts(977,48): error TS2304: Cannot find name 'define'.
69+
tests/cases/conformance/fixSignatureCaching.ts(978,16): error TS2304: Cannot find name 'define'.
7070
tests/cases/conformance/fixSignatureCaching.ts(979,23): error TS2304: Cannot find name 'window'.
7171
tests/cases/conformance/fixSignatureCaching.ts(980,37): error TS2304: Cannot find name 'window'.
7272

@@ -1182,12 +1182,12 @@ tests/cases/conformance/fixSignatureCaching.ts(980,37): error TS2304: Cannot fin
11821182
!!! error TS2304: Cannot find name 'module'.
11831183
} else if (typeof define === 'function' && define.amd) {
11841184
~~~~~~
1185-
!!! error TS2552: Cannot find name 'define'. Did you mean 'undefined'?
1185+
!!! error TS2304: Cannot find name 'define'.
11861186
~~~~~~
1187-
!!! error TS2552: Cannot find name 'define'. Did you mean 'undefined'?
1187+
!!! error TS2304: Cannot find name 'define'.
11881188
return define;
11891189
~~~~~~
1190-
!!! error TS2552: Cannot find name 'define'. Did you mean 'undefined'?
1190+
!!! error TS2304: Cannot find name 'define'.
11911191
} else if (typeof window !== 'undefined') {
11921192
~~~~~~
11931193
!!! error TS2304: Cannot find name 'window'.

tests/baselines/reference/letDeclarations-scopes2.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/letDeclarations-scopes2.ts(8,5): error TS2552: Cannot find name 'local2'. Did you mean 'local'?
22
tests/cases/compiler/letDeclarations-scopes2.ts(20,5): error TS2552: Cannot find name 'local2'. Did you mean 'local'?
3-
tests/cases/compiler/letDeclarations-scopes2.ts(23,1): error TS2552: Cannot find name 'local'. Did you mean 'global'?
4-
tests/cases/compiler/letDeclarations-scopes2.ts(25,1): error TS2552: Cannot find name 'local2'. Did you mean 'global'?
3+
tests/cases/compiler/letDeclarations-scopes2.ts(23,1): error TS2304: Cannot find name 'local'.
4+
tests/cases/compiler/letDeclarations-scopes2.ts(25,1): error TS2304: Cannot find name 'local2'.
55

66

77
==== tests/cases/compiler/letDeclarations-scopes2.ts (4 errors) ====
@@ -33,9 +33,9 @@ tests/cases/compiler/letDeclarations-scopes2.ts(25,1): error TS2552: Cannot find
3333

3434
local; // Error
3535
~~~~~
36-
!!! error TS2552: Cannot find name 'local'. Did you mean 'global'?
36+
!!! error TS2304: Cannot find name 'local'.
3737
global; // OK
3838
local2; // Error
3939
~~~~~~
40-
!!! error TS2552: Cannot find name 'local2'. Did you mean 'global'?
40+
!!! error TS2304: Cannot find name 'local2'.
4141

tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(4,18): error TS2339: Property 'from' does not exist on type 'ArrayConstructor'.
22
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(10,13): error TS2304: Cannot find name 'Map'.
33
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(17,5): error TS2339: Property 'name' does not exist on type '() => void'.
4-
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(20,6): error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
4+
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(20,6): error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'asin'?
55
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(25,6): error TS2304: Cannot find name 'Symbol'.
66
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(29,18): error TS2304: Cannot find name 'Symbol'.
77
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(33,13): error TS2304: Cannot find name 'Proxy'.
@@ -40,7 +40,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.t
4040
// Using ES6 math
4141
Math.sign(1);
4242
~~~~
43-
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
43+
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'asin'?
4444

4545
// Using ES6 object
4646
var o = {

tests/baselines/reference/parser10.1.1-8gs.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(16,7): error TS2552: Cannot find name 'NotEarlyError'. Did you mean 'SyntaxError'?
1+
tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(16,7): error TS2304: Cannot find name 'NotEarlyError'.
22
tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(17,5): error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
33

44

@@ -20,7 +20,7 @@ tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(17,5): error TS12
2020
"use strict";
2121
throw NotEarlyError;
2222
~~~~~~~~~~~~~
23-
!!! error TS2552: Cannot find name 'NotEarlyError'. Did you mean 'SyntaxError'?
23+
!!! error TS2304: Cannot find name 'NotEarlyError'.
2424
var public = 1;
2525
~~~~~~
2626
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode.

0 commit comments

Comments
 (0)