Haskell-language-server: Retrie plugin

Created on 10 May 2020  路  10Comments  路  Source: haskell/haskell-language-server

http://hackage.haskell.org/package/retrie

Retrie is a modern alternative to HaRe, and possibly better maintained as it is used by Facebook.

It can be used to implement refactorings like:

  • Inline functions with --unfold
  • Extract functions, with --fold
  • Inline and extract type synonyms, with --type-forward and --type-backward

It could be also used to implement renames and moves, but those would require custom scripts.

plugins enhancement

Most helpful comment

I have started working on Retrie integration in the branch https://github.com/pepeiborra/ide/tree/retrie

The branch relies on some upstream changes (https://github.com/facebookincubator/retrie/pull/9) and therefore cannot be merged until those changes are accepted and released.

All 10 comments

/cc @xich in case he is already working on this

Yes, I have been wanting to get to this. And also wondering if it should not be used to make the changes from hlint.

I'm not working on it myself, but happy to support anyone who does. I would love to see this happen!

@alanz Funny you mention hlint. That was the initial motivation for retrie, but I never got back around to doing the integration. I probably will at some point, if someone doesn't beat me to it.

ping @ndmitchell

HLint uses the refactor data types - https://hackage.haskell.org/package/refact-0.3.0.2/docs/Refact-Types.html - so all that is required is someone to have those supported in retrie. Note that recently @zliu41 has been working to improve these, and there are some known bugs in apply-refact that we currently use to execute these replacements.

The Replace constructor from Refact.Types would be quite easy to generate from retrie's writer type:

https://github.com/facebookincubator/retrie/blob/f54706a1c8e4f16ae39e540059cf4e2b33498d18/Retrie/Replace.hs#L86-L90

That is essentially how I do replacements in CPP files already:

https://github.com/facebookincubator/retrie/blob/99256ce6f97c40bb4f3211302a3381eed099ad5e/Retrie/Run.hs#L113

(printCPP splices them into the actual file)

The API for actually running retrie with a custom handler for Replacements is to call run with a custom WriteFn:

https://github.com/facebookincubator/retrie/blob/master/Retrie/Run.hs#L77

See examples of various WriteFns in Retrie.Run module.

I have started working on Retrie integration in the branch https://github.com/pepeiborra/ide/tree/retrie

The branch relies on some upstream changes (https://github.com/facebookincubator/retrie/pull/9) and therefore cannot be merged until those changes are accepted and released.

Looks like retrie has included @pepeiborra 's changes. From the linked PR:

Just released this as part of retrie-0.1.1.1

So... LGTM?

I want to wait until https://github.com/facebookincubator/retrie/issues/10 lands before resuming this work

Ah, sorry! Didn鈥檛 realize I was blocking you. I鈥檓 afk the next couple days, but once I鈥檓 back, let鈥檚 try to work out the details.

Was this page helpful?
0 / 5 - 0 ratings