[Haskell-cafe] vim-hsimport: only consider modules of direct dependencies

Daniel Trstenjak daniel.trstenjak at gmail.com
Sat Apr 5 19:34:35 UTC 2014


Hi all,

vim-hsimport[1] is a vim plugin that is able to automatically extend the
import list of a haskell source file for the symbol under the cursor.

It uses hdevtools[2] for finding the symbol in the modules of the
installed packages and hsimport[3] for extending the import list.


Until now vim-hsimport did consider all packages a project depends on,
even if the package was only an indirect dependecy, not listed in
the 'build-depends' field.

So e.g. if a project directly and indirectly depends on the packages:
base, containers, bytestring, binary, text and vector, and the modules 
for symbol 'foldl' have been requested, then the list of found modules
might have been:

   Data.IntMap
   Data.IntMap.Lazy
   Data.IntMap.Strict
   Data.IntSet
   Data.Map
   Data.Map.Lazy
   Data.Map.Strict
   Data.Set
   Data.ByteString
   Data.ByteString.Char8
   Data.ByteString.Lazy
   Data.ByteString.Lazy.Char8
   Codec.Binary.UTF8.Generic
   Data.String.UTF8
   Data.ByteString.UTF8
   Data.ByteString.Lazy.UTF8
   Data.Text
   Data.Text.Internal.Fusion.Common
   Data.Text.Lazy
   GHC.List
   Data.Foldable
   Data.List
   Prelude
   Data.Vector.Fusion.Stream.Monadic
   Data.Vector.Fusion.Stream
   Data.Vector.Generic
   Data.Vector.Primitive
   Data.Vector.Storable
   Data.Vector.Unboxed
   Data.Vector

But if the project depends directly only on the packages: base and text,
then only these modules are really relevant:

   Data.Text
   Data.Text.Internal.Fusion.Common
   Data.Text.Lazy
   GHC.List
   Data.Foldable
   Data.List
   Prelude

This can be now achieved by using cabal-cargs[4] (>= 0.4) for the configuration
of hdevtools. Please read the README[5] for detailed instructions.

(One might argue, that even the modules Data.Text.Internal.Fusion.Common,
GHC.List and Prelude might be left out, but that's another issue.)


You might be also interested in a new feature of the 0.3 versions of
hsimport and vim-hsimport.

Before that version types have been always imported like:

   import SomeModule (Type)

Now there's the option to choose between importing only the type
or also importing all constructors/functions of the type:

   import SomeModule (Type(..))


If you're using hdevtools with the vim plugin syntastic[6] and have
projects containing multiple sections (library/executable/testsuite ...)
and each section has a separate 'hs-source-dirs', then you might get a
more robust hdevtools behaviour by using this little change[7].

Happy Haskell hacking! :)


Greetings,
Daniel


[1] https://github.com/dan-t/vim-hsimport
[2] https://github.com/bitc/hdevtools
[3] https://github.com/dan-t/hsimport
[4] https://github.com/dan-t/cabal-cargs
[5] https://github.com/dan-t/vim-hsimport/blob/master/README.md
[6] https://github.com/scrooloose/syntastic
[7] https://github.com/dan-t/syntastic/commit/7bd9b98342c93b7c7b06ddea19949233190106ce


More information about the Haskell-Cafe mailing list