Skip to content

Add argument - update use sites & extensions? #4938

Description

@Jashweii

Is your enhancement request related to a problem? Please describe.

No

Describe the solution you'd like

If I define:

fun :: Char -> Int
fun = w

main = print (fun 'c')

and add w as an argument of fun, HLS could possibly:

  1. Look up all direct references to fun, and if there are any
  2. Ask me for something to insert (default _w_fun_123948 which I could just press enter to confirm)
  3. Insert at the appropriate position, parenthesising or expanding lambdas as necessary

Actually resolving those _s is the programmer's job. Indirect references aren't a problem (they reference the direct references, and so on). It's almost never going to be valid to add the argument and not add something at all the use sites (it is possible with whacky class setups), and in some cases there are defaults (e.g. one parameter value corresponds to the prior behaviour).

In the same vein this could be extended further (whichever are the most useful:

  1. Data and type constructor parameters (including record fields). May need two suggestions for DataKinds (type and value if used in both ways). type parameters of terms (TypeApplications, TypeAbstractions)
  2. Removing/replacing entities (not parameters) - likewise you need to say what is added in its place elsewhere, and could reference the parameters in the replacement
    Inlining synonyms or small functions is a special case of this
  3. Removing parameters (at use sites this just deletes expressions, you still need an insert but for inside the function)
  4. Adding (add -> _ cases) and removing data constructors (delete whole cases matching, replace for value uses).

I think it's fairly common in big projects to have to do these sorts of jobs so they could be useful (though admittedly it doesn't help you when a new version of a dependent package has done it, unless you can fake it with a local version temporarily).

Describe alternatives you've considered

Leave HLS as it is

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions