Skip to content
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

Suggestions for misspelled properties and variables (based on Levenshtein distance for variables/properties in scope) #15333

Closed
artr73 opened this issue Apr 23, 2017 · 5 comments · Fixed by #15507
Assignees
Labels
Committed The team has roadmapped this issue Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@artr73
Copy link

artr73 commented Apr 23, 2017

Consider the following code:

class X {
  public longName = 10;
  public otherName = 11;

  public do(){
    this.lognName = 20;
  }
}

Currently compilation fails with the message:

Property 'lognName' does not exist on the type 'X'.

In case when a variable is misspelled, the error is even less helpful:

public longMethod(){
  let firstVariable = 10;
  let secondVariable = "hello,world";
  
  //lots of code here
  fristVariable = 20;
}
Cannot find name 'fristVariable'.

It could offer variable/property suggestion, like:

Cannot find name 'fristVariable'. Did you mean 'firstVariable'?

For example, Rust compiler (1.16) would suggest an existing variable that most resembles the misspelled one, based on Levenstein distance, if I'm correct.

@artr73 artr73 changed the title Typo suggestions for properties and variables (based on Levenstein distance for variables/properties in scope) Suggestions for misspelled properties and variables (based on Levenstein distance for variables/properties in scope) Apr 23, 2017
@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Apr 24, 2017
@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue and removed In Discussion Not yet reached consensus labels Apr 24, 2017
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.4 milestone Apr 24, 2017
@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Apr 24, 2017

@sandersn notes from backlog slog:

  • Do some sort of limiting to avoid this being too expensive (caching? limit the number of times we do this? etc?)
  • Levensthein / Hamming / Shiveldistance is up to you
  • Have some minimal threshold of "might be close enough"
  • Filter based on the kind of symbol (value / namespace / type) to make sure we only suggest valid stuff
  • Include a quickfix
  • Everyone's gonna 😍 this

@sandersn sandersn changed the title Suggestions for misspelled properties and variables (based on Levenstein distance for variables/properties in scope) Suggestions for misspelled properties and variables (based on Levenshtein distance for variables/properties in scope) Apr 25, 2017
@sandersn
Copy link
Member

You can track the progress of this at the branch sandersn/did-you-mean. It's at a very early stage right now -- the suggested replacement is the first name whose length is no more than 3 different from the misspelled name's length. This works pretty well for property accesses for but lone identifiers tends to suggest NaN and Infinity.

There's a quick fix for property accesses. My next step is to make it work for standalone identifiers as well.

@Igorbek
Copy link
Contributor

Igorbek commented Apr 26, 2017

Should intellisense also suggest something when you misspell?

@sandersn
Copy link
Member

Are you saying that it should provide spelling corrections when the list would otherwise be empty? For example, when the very first letter is misspelled? I think that could work, but I'd have to play around with it to know for sure.

@Igorbek
Copy link
Contributor

Igorbek commented Apr 26, 2017

@sandersn yes, exactly

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label May 9, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Committed The team has roadmapped this issue Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants