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

Provide high-confidence spelling suggestions as suggestion diagnostics #41582

Closed
DanielRosenwasser opened this issue Nov 18, 2020 · 3 comments · Fixed by #44271
Closed

Provide high-confidence spelling suggestions as suggestion diagnostics #41582

DanielRosenwasser opened this issue Nov 18, 2020 · 3 comments · Fixed by #44271
Assignees
Labels
Domain: JavaScript The issue relates to JavaScript specifically Experimentation Needed Someone needs to try this out to see what happens Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Nov 18, 2020

When JavaScript users don't have type-checking turned on, there are often some good suggestions left on the table that go to waste.

Obviously we can't just provide all the errors that checkJs would issue, but there are a few good ones. Specifically, spelling suggestions could be provided if we were more confident in how useful they are, where confidence is determined by some rules.

Some of the following rules might be worth investigating:

  • the suggestion occurs in a module file
  • the "misspelled" identifier occurs nowhere else in the program
  • the "misspelled" identifier is not a commonly-used identifier in well-known libraries
  • the suggestion's edit distance is lower than the usual threshold
@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Experimentation Needed Someone needs to try this out to see what happens labels Nov 18, 2020
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.2.0 milestone Nov 18, 2020
@DanielRosenwasser DanielRosenwasser added the Domain: JavaScript The issue relates to JavaScript specifically label Nov 19, 2020
@sandersn
Copy link
Member

sandersn commented Feb 8, 2021

This is a new feature so I'm going to move it to 4.3.

Aside: I don't know that the suggestion would have to be any more accurate than a TS suggestion -- JS is a best-effort environment, where completions over-generate rather than under-generate. I think it would be fine for spelling suggestions to do the same, especially since the suggestion UI is unobtrusive in VS Code at least.

Filtering out identifiers used elsewhere and commonly used identifiers is a good idea, though.

@sandersn
Copy link
Member

sandersn commented Feb 8, 2021

However, since there are likely to be a lot of unresolved identifiers in JS files, it does make sense to limit the number of suggestions. Instead of starting from improving accuracy, I think it would work better to generate all the suggestions but only show the most valuable ones. (This would probably be harder and more expensive to implement, though.)

@sandersn
Copy link
Member

Few more thoughts:

  1. To reduce the number of suggestions, suggest only on property accesses. Object types have implicit index signatures outside strict, so that'll have to change.
  2. To reduce the number of non-property-access suggestions, suggest only from local scope. (I'm not sure how easy this is to do.)
  3. Note that the suggestion wording might need to change if we're not sure that the identifier in question really isn't found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: JavaScript The issue relates to JavaScript specifically Experimentation Needed Someone needs to try this out to see what happens Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants