Skip to content

Provide high-confidence spelling suggestions as suggestion diagnostics #41582

Description

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

Activity

  1. sandersn commented on Feb 8, 2021

    @sandersn
    Member

    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.

  2. sandersn commented on Feb 8, 2021

    @sandersn
    Member

    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.)

  3. sandersn commented on Feb 11, 2021

    @sandersn
    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

Metadata

Metadata

Labels

Domain: JavaScriptThe issue relates to JavaScript specificallyExperimentation NeededSomeone needs to try this out to see what happensFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions