RefactoringTools / HaRe

The Haskell Refactoring Tool
http://www.cs.kent.ac.uk/projects/refactor-fp/
Other
139 stars 32 forks source link

Resuscitate / provide VIM support #1

Open alanz opened 8 years ago

alanz commented 8 years ago

Possibly based on https://github.com/alanz/HaRe/tree/master/old/editors/Vim

cc @gibiansky

Originally https://github.com/alanz/HaRe/issues/40

glittershark commented 8 years ago

Hey @alanz! I've been toying around with making this happen as a weekend / new years' holiday project. I've got passable support for ghc-hare rename and ghc-hare liftToTopLevel up at https://github.com/glittershark/vim-hare, and things are moving along pretty well.

The one big issue that I've run into is parsing the elisp output of ghc-hare - currently I have this disgusting mess of tr, regular expressions, and eval, which is obviously far less than optimal. From what I can read, haskell-ide-engine seems to have decided on using JSON as an interface - would there be any support for providing that as an option over here?

Furthermore (and I know I really should open a new issue for this, but hey), I can see a fair amount of cleanup to be done in some of the haskell backend source itself - this block, as an example, could use when instead of several nested if/then/else blocks - is that the kind of thing you'd be willing to accept patches for?

alanz commented 8 years ago

Just a quick comment without looking properly as I am going to bed.

I would definitely recommend going the haskell-ide-engine route, as it already exposes Hare, and you will be able to access other plugins too. See https://cocreature.github.io/haskell-ide-engine/plugins/hare.html

alanz commented 8 years ago

As far as PR's to clean up the code, they are welcome for bits that are already stable (such as renaming)

I am going through a process of porting code from the earlier implementation, and there is a surprising amount of subtlety/detail in it, so I tend to preserve the original as much as possible initially.

And of course a lot of the code is just horrible as I have been learning haskell as I go along. A lifelong experience.

There are some options for your plugin

I am obviously biased toward the latter, but will change format if you prefer/accept a PR for a different format

glittershark commented 8 years ago

I'm definitely with you on integrating with haskell-ide-engine - the only problem is since that's a background process with an HTTP interface (a decision which I support, for the record) dealing with it from pure vimscript becomes all but impossible. That being said, there are plenty of popular vim plugins that do the rpc/ipc + background process approach to great success with things like Python/Lua/what have you.

I think I'd like to go forward with trying to do vim bindings for ghc-hare as a standalone for now, since the shell-out approach is really easy to deal with. In the future, however, I'm super interested in putting the work in to try and get haskell-ide-engine working well with vim

alanz commented 8 years ago

hie also has a stdio/JSON transport, which the emacs integration uses. And is open to others, if required.

cocreature commented 8 years ago

In fact I would probably call the stdio transport the main transport atm, simply because that’s what emacs and I think also leksah use it and those are the only integrations we have so far. I’d be happy to help you with the vim integration where I can (I’m not a vim user). If stdio is not convenient for you just tell us what you need and we’ll try to provide that.

glittershark commented 8 years ago

by stdio do you mean I can pipe JSON to an invocation of hie? like echo {"some:"stuff"} | hie?

alanz commented 8 years ago

@cocreature That sounds like an interesting way of doing it. hie expects to run as a daemon, so we should maybe add base:exit to ask hie to exit when done

cocreature commented 8 years ago

Or we could add an --one-shot option which causes it to only process one command at a time and then exit. However you have to be aware that obviously spawning a new process each time will be slower, especially if you have a plugin which caches things like type info.

glittershark commented 8 years ago

@cocreature that's totally fair. There comes a point where you're sacrificing too much just to get around vim's subpar process management support

alanz commented 8 years ago

See https://github.com/haskell/haskell-ide-engine/issues/154

alanz commented 8 years ago

And if you can't wait: https://github.com/haskell/haskell-ide-engine/pull/158