Search code examples
haskellvimcabalghc-mod

why does ghc-mod powered neco-ghc only works on project root directory?


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?


Solution

  • 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.