haskell / haskell/haskell-language-server

Add argument - update use sites & extensions?

Open
#4,938 1 comment 1 reaction 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
2d 19h
Merged PRs (30d)
11

Description

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

No

## Describe the solution you'd like

If I define:
```Haskell
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.