(automatically) adding import statements in vim

Are there any tools or vim-plugins that will automatically add import statements? For instance, I have the following code: ... import Data.Maybe (fromJust) import Text.ParserCombinators.Parsec (ParseError) import Text.Printf (printf) ... parseMyString :: String -> Either ParseError String parseMyString stringToParse = parse myParser "(unknown)" stringToParse Here's what I want to have happen. I put my cursor over "parse" and press some keystroke. It automatically adds the parse function to the list of import statements from the Text.ParserCombinators.Parsec module (hopefully sorted alphabetically). So the import statements end up looking like this: ... import Data.Maybe (fromJust) import Text.ParserCombinators.Parsec (ParseError, parse) import Text.Printf (printf) ... The haskellmode vim plugin (https://github.com/lukerandall/haskellmode-vim) has functionality similar to this, but it can only add new import lines. It can't add functions/types to existing import lines. The best it can do is something like this: ... import Data.Maybe (fromJust) import Text.ParserCombinators.Parsec (ParseError) import Text.Printf (printf) import Text.ParserCombinators.Parsec (parse) ... This is alright, but I have to go back and edit it by hand to make it look like the above. Are there any tools or vim-plugins that can do this automatically?

Hi, I've just pushed the first versions of: https://github.com/dan-t/hsimport https://github.com/dan-t/vim-hsimport So there're certainly still some rough edges. Greetings, Daniel

Hi, You may also be interested in Halberd[1][2] which uses hs-gen-iface[3] to do automatically insert missing imports by finding modules with the desired names. It does not have a vim plugin yet, but I imagine a simplistic one should be easy to make. Cheers, Adam [1] https://github.com/haskell-suite/Halberd [2] http://hackage.haskell.org/package/halberd [3] http://hackage.haskell.org/package/hs-gen-iface On Thu, Dec 26, 2013 at 11:38 AM, Daniel Trstenjak < daniel.trstenjak@gmail.com> wrote:
Hi,
I've just pushed the first versions of: https://github.com/dan-t/hsimport https://github.com/dan-t/vim-hsimport
So there're certainly still some rough edges.
Greetings, Daniel _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Adam,
You may also be interested in Halberd[1][2] which uses hs-gen-iface[3] to do automatically insert missing imports by finding modules with the desired names. It does not have a vim plugin yet, but I imagine a simplistic one should be easy to make.
If I'm getting this correctly, than Halberd uses some kind of static database, right? I think the nice approach of 'vim-hsimport' is, that by using 'hdevtools' in conjunction with a 'cabal sandbox', only the modules of the packages are considered, which your project depends on, and this information is dynamically "established" by 'hdevtools' reading the package database of the 'cabal sandbox'. But I have to confess, that hsimport/vim-hsimport are still in a quite early stage. Greetings, Daniel

Hi Daniel,
If I'm getting this correctly, than Halberd uses some kind of static database, right?
Right.
I think the nice approach of 'vim-hsimport' is, that by using 'hdevtools' in conjunction with a 'cabal sandbox', only the modules of the packages are considered, which your project depends on, and this information is dynamically "established" by 'hdevtools' reading the package database of the 'cabal sandbox'.
I recall Erik and others discussing ways of restricting halberd to a sandbox as well, but you'd have to ask him about the progress. Cheers, Adam On Sun, Dec 29, 2013 at 1:30 PM, Daniel Trstenjak < daniel.trstenjak@gmail.com> wrote:
Hi Adam,
You may also be interested in Halberd[1][2] which uses hs-gen-iface[3] to do automatically insert missing imports by finding modules with the desired names. It does not have a vim plugin yet, but I imagine a simplistic one should be easy to make.
If I'm getting this correctly, than Halberd uses some kind of static database, right?
I think the nice approach of 'vim-hsimport' is, that by using 'hdevtools' in conjunction with a 'cabal sandbox', only the modules of the packages are considered, which your project depends on, and this information is dynamically "established" by 'hdevtools' reading the package database of the 'cabal sandbox'.
But I have to confess, that hsimport/vim-hsimport are still in a quite early stage.
Greetings, Daniel _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Fri, Jan 3, 2014 at 2:55 PM, Adam Bergmark
Hi Daniel,
If I'm getting this correctly, than Halberd uses some kind of static database, right?
Right.
To be more clear, it uses the database built by hs-gen-iface [0], which is a compile-like tool that generates an interface database for your packages. You have to make a separate `cabal` call to use it and build the database for each package you compile. Hopefully in the future, cabal will have a way to automatically call compiler-like tools (think haddock as wel). But for now, it's a bit impractical.
I think the nice approach of 'vim-hsimport' is, that by using 'hdevtools' in conjunction with a 'cabal sandbox', only the modules of the packages are considered, which your project depends on, and this information is dynamically "established" by 'hdevtools' reading the package database of the 'cabal sandbox'.
I recall Erik and others discussing ways of restricting halberd to a sandbox as well, but you'd have to ask him about the progress.
Right now halberd uses the global and user database. It should be fairly trivial to add support for cabal sandboxes, although there will probably be some duplication with cabal in the sandbox flags at least. Let me know if you're interested. Regards, Erik [0] http://hackage.haskell.org/package/hs-gen-iface

I wrote fix-imports, which is on hackage. Works for me, but assumes
you use qualified imports.
On Wed, Dec 25, 2013 at 3:45 AM, cdep.illabout@gmail.com
Are there any tools or vim-plugins that will automatically add import statements?
For instance, I have the following code:
... import Data.Maybe (fromJust) import Text.ParserCombinators.Parsec (ParseError) import Text.Printf (printf) ...
parseMyString :: String -> Either ParseError String parseMyString stringToParse = parse myParser "(unknown)" stringToParse
Here's what I want to have happen. I put my cursor over "parse" and press some keystroke. It automatically adds the parse function to the list of import statements from the Text.ParserCombinators.Parsec module (hopefully sorted alphabetically). So the import statements end up looking like this:
... import Data.Maybe (fromJust) import Text.ParserCombinators.Parsec (ParseError, parse) import Text.Printf (printf) ...
The haskellmode vim plugin (https://github.com/lukerandall/haskellmode-vim) has functionality similar to this, but it can only add new import lines. It can't add functions/types to existing import lines.
The best it can do is something like this:
... import Data.Maybe (fromJust) import Text.ParserCombinators.Parsec (ParseError) import Text.Printf (printf) import Text.ParserCombinators.Parsec (parse) ...
This is alright, but I have to go back and edit it by hand to make it look like the above.
Are there any tools or vim-plugins that can do this automatically? _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Adam Bergmark
-
cdep.illabout@gmail.com
-
Daniel Trstenjak
-
Erik Hesselink
-
Evan Laforge