Skip to content

Retrie plugin #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pepeiborra opened this issue May 10, 2020 · 10 comments · Fixed by #266
Closed

Retrie plugin #103

pepeiborra opened this issue May 10, 2020 · 10 comments · Fixed by #266
Labels

Comments

@pepeiborra
Copy link
Collaborator

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.

@pepeiborra
Copy link
Collaborator Author

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

@alanz
Copy link
Collaborator

alanz commented May 10, 2020

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

@xich
Copy link

xich commented May 11, 2020

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.

@alanz
Copy link
Collaborator

alanz commented May 11, 2020

ping @ndmitchell

@ndmitchell
Copy link
Collaborator

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.

@xich
Copy link

xich commented May 11, 2020

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.

@pepeiborra
Copy link
Collaborator Author

pepeiborra commented May 24, 2020

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

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

@TomMD
Copy link

TomMD commented Jul 7, 2020

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?

@pepeiborra
Copy link
Collaborator Author

I want to wait until facebookincubator/retrie#10 lands before resuming this work

@xich
Copy link

xich commented Jul 7, 2020

Ah, sorry! Didn’t realize I was blocking you. I’m afk the next couple days, but once I’m back, let’s try to work out the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants