1

I'm new to haskell so I don't have deep understanding about how ghc-mod works and how cabal-install-like build tools of haskell worlds move under the hood.

But I somehow found vim haskell plugins from github, including neco-ghc auto completion plugin powered by ghc-mod which seemed very attractive to me.

The problem was that it only works on project-level haskell source codes of cabal-install initialized projects while it doesn't work at all on stack-initialized projects.

My directory structure is generated by following commands:

~ $ mkdir my_project && cd my_project
~/my_project $ cabal init
~/my_project $ cabal sandbox init

which yields

my_project  
|-- Setup.hs  
|-- cabal.sandbox.config  
|-- src / Lib.hs

Autocompletion works (it suggests Prelude module's keywords) when I edit Setup.hs but I suggests nothing when I try edit src/Lib.hs.

My :NecoGhcDiagnotics command outputs

Current filetype: haskell                                                                                                                                                                                                    
ghc-mod is executable: 1                                                                                                                                                                                                     
omnifunc: necoghc#omnifunc                                                                                                                                                                                                   
neocomplete.vim: 0                                                                                                                                                                                                           
neocomplcache.vim: 2                                                                                                                                                                                                         
YouCompleteMe: 0                                                                                                                                                                                                             
vimproc.vim: 900                                                                                                                                                                                                             
ghc-mod: 5.4.0.0                                                                                                                                                                                                             
Imported modules: Prelude                                                                                                                                                                                                    
Number of symbols in Prelude: 0     

when I edit src/Lib.hs while

Current filetype: haskell                                                                                                                                                                                                    
ghc-mod is executable: 1                                                                                                                                                                                                     
omnifunc: necoghc#omnifunc                                                                                                                                                                                                   
neocomplete.vim: 0                                                                                                                                                                                                           
neocomplcache.vim: 2                                                                                                                                                                                                         
YouCompleteMe: 0                                                                                                                                                                                                             
vimproc.vim: 900                                                                                                                                                                                                             
ghc-mod: 5.4.0.0                                                                                                                                                                                                             
Imported modules: Distribution.Simple, Prelude                                                                                                                                                                               
Number of symbols in Prelude: 235   

is the output of the command when I'm editing Setup.hs.

It clearly looks like ghc-mod is not detecting any symbols when I'm editing src/Lib.hs.. why is this happening?

June
  • 2,107
  • 4
  • 22
  • 33
  • 5
    Because `ghc-mod` 5.4.0 insists to be [run from the project's root directory](https://hackage.haskell.org/package/ghc-mod-5.4.0.0/changelog). It isn't that it doesn't know how to find the root directory and `chdir()` to it: it specifically wants you to do it beforehand. Some day, `ghc-mod` authors might begin to grasp the concept of backwards compatibility, and why some people make such a big fuss about it. That day seem pretty far away for now. – lcd047 Oct 19 '15 at 15:00
  • 1
    Upgrading `neco-ghc` [should help](https://github.com/eagletmt/neco-ghc/pull/56). – lcd047 Oct 19 '15 at 15:07
  • @lcd047 Jesus you are my life saver! Why don't you leave those comments as an answer so that I can accept it? – June Oct 19 '15 at 15:14

1 Answers1

4

Posting an answer as requested: ghc-mod 5.4.0 insists to be run from the project's root directory. This breaks various third-party programs that depend on ghc-mod. The neco-ghc plugin has been updated to cope with that, other programs are dropping support for ghc-mod.

lcd047
  • 5,731
  • 2
  • 28
  • 38