Type-Directed Autocompletion

I had a bit of time to take a look at the Type-Directed Autocomplete project. Basically the goal is, given some type signature (for example List String -> List Int) try to find Elm expressions which have this type (for example List.filterMap String.toInt) I put up a small demo of what I came up with.

Codewise, I guess the most interesting part is the Generator module. It introduces the Generator type and several functions to create these (value, call, cases, addValues, …). One can use these to describe what kind of Elm expressions should be generated, and to modify the set of known values to be searched in.

For example the value : Generator will try to find “exact” matches for a given type; so, if you are looking for something of the type String -> Maybe Int, it could suggest String.toInt. You can also combine these! So, for example the generator call [ value ] will generate function calls with one argument, where this argument is an exact match; so depending on your target type, you might get things like List.filterMap String.toInt, List.foldl String.concat, … . You can also generate record updates and case expressions, so the generator

  { matched = value
  , branch =
      \newValues ->
        recordUpdate (addValues newValues value)

could give you

case msg of
  Tick newPosix ->
    { model | time = newPosix }

  NameChanged newString ->
    { model | name = newString }

given that model : { time : Posix, name : String } and msg : Msg are known values.

I don’t know how much time I will have to continue working on this, but I thought this might still be worth sharing and interesting for other folks thinking about this project. :slight_smile:


That is awesome, thank you for sharing!

Seems like it would be a good base for completion in LSPs and the like.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.