Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Remove length limit on spelling suggestions; use levenshteinWithMax for performance#19937

Merged
4 commits merged into
mastermicrosoft/TypeScript:masterfrom
levenshteinWithMaxmicrosoft/TypeScript:levenshteinWithMaxCopy head branch name to clipboard
Nov 28, 2017
Merged

Remove length limit on spelling suggestions; use levenshteinWithMax for performance#19937
4 commits merged into
mastermicrosoft/TypeScript:masterfrom
levenshteinWithMaxmicrosoft/TypeScript:levenshteinWithMaxCopy head branch name to clipboard

Conversation

@ghost

@ghost ghost commented Nov 11, 2017

Copy link
Copy Markdown

Removes the length limit so we can get spelling suggestions for Diagnostics.new_T_cannot_be_used_to_create_an_aray_Use_new_Array_T_instead.
Algorithm is roughly based on https://www.lemoda.net/c/edit-distance-with-max/. I fixed a bug where they set col_min = INT_MAX when they should have set it to i (which is the value at the 0th element in the column).

@ghost ghost requested a review from sandersn November 11, 2017 04:19
Comment thread src/compiler/utilities.ts Outdated
nameLowerCase.length < 3 ||
candidateNameLowerCase === "eval" ||
candidateNameLowerCase === "intl" ||
candidateNameLowerCase === "undefined" ||

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these excluded? I'd really like to be able to automatically fix undefnied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestions were not good at one point. That might have changed during final tweaks to the numbers, because I ended up less likely to give suggestions for short identifiers than when I was mid-development. That's specifically why the 3-4 character identifiers are here. Maybe undefined is no longer affected.

Coverage is pretty good at this point, so if you remove items from this list, you should see what bad suggestions happen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If any; it may be fine to suggest undefined now)

@sandersn

Copy link
Copy Markdown
Member

Why move this? It makes reading the diff unnecessarily difficult, and I think it's only used in the checker anyway.

@@ -1,4 +1,4 @@
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(28,13): error TS2339: Property 'fn2' does not exist on type 'typeof A'.
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(28,13): error TS2551: Property 'fn2' does not exist on type 'typeof A'. Did you mean 'fn'?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not have changed. The lower-bound cutoff was specifically designed to leave deletions from 3-character identifiers alone since they are really hard to miss visually.

(The same is almost as true of 4-character identifiers, as on the next line, but I remember coming up with a couple of convincing counterexamples.)

Comment thread src/compiler/checker.ts
continue;
}
if (distance < 3) {
justCheckExactMatches = true;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, why have this? Why shouldn't we look for result with a distance of 1 even after one with a distance of 2 is available?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of these fast paths exist because originally this function was called on all unknown identifiers, which usually results in running Levenshtein distance on over 1000 identifiers from the global scope, plus any lexical scopes. Currently this only happens until 10 suggestions have been found, which could still be a significant fraction of the unknown identifiers in a program if no good candidates are found.

Also, this function is called for unknown property accesses and unknown imports (I may be misremembering since I didn’t write that one), both of which have smaller search spaces. Future uses could result in larger search spaces though.

@ghost ghost force-pushed the levenshteinWithMax branch from 5dac325 to 5d4240c Compare November 17, 2017 15:18
@ghost ghost merged commit 6df0575 into master Nov 28, 2017
@ghost ghost deleted the levenshteinWithMax branch November 28, 2017 17:37
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.