Draco-lang / Language-suggestions

Collecting ideas for a new .NET language that could replace C#
75 stars 5 forks source link

Help the user with "undefined identifier" #46

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

Problem

In scripting, interactive environment (including notebooks), in editors without intellisense (e. g. when you want to quickly edit a file and you don't open it from IDE) people often misspell an identifier or forget to include the namespace. Trying to compile, they get a very unhelpful error about undefined identifier.

Solution

The idea here is to help the user with suggesting what should be there instead. Two ways:

  1. First, let's check if there's a type or function with a similar identifier in the opened namespaces and suggest that
  2. Then, crawl down the opened namespaces to check if the type needs another namespace imported

Details

To determine close identifiers we could use something like Levenstein's algorithm, doesn't look like a problem. However, in the latter case it is more complicated:

  1. The compiler will need to store all BCL types' names in RAM? Then it could quickly search over them
  2. It should also crawl down over 3rd party packages. Then again, there's no mapping namespace-assembly, so at most we can do is to load those types too and search over them.

Examples

2.

open System.Collections.Generic
val list = new Listt<T>()
- No "Listt<T>" found. Maybe you meant List<T>?

2.

open System.Collections
val list = new List<T>()
- No "List<T>" found. Maybe forgot to open System.Collections.Generic?