ghc-mod
ghc-mod copied to clipboard
Function signature insertion with M-t doesn't work
I've created a test project with stack new new-template
. In the automatically generated src/Lib.hs
I added the following line:
bar a = a + 2
With the point on the beginning of that line, typing M-t
tells me there's "Nothing to be done". According to http://www.mew.org/~kazu/proj/ghc-mod/en/emacs.html however,
On the function without signature, inferred type is inserted.
I have started emacs from the directory ghc-20150915.2030
(this is the latest update I use in my normal emacs from melpa) with the command emacs -Q -L . -l ghc-autoloads.el -L ../haskell-mode-20150920.858 -l ../haskell-mode-20150920.858/haskell-mode-autoloads.el
and called ghc-init
once after opening the file Lib.hs
.
This is the output of ghc-debug
:
Path: check if you are using intended programs. ghc.el path: /home/wieland/.emacs.d/elpa/ghc-20150915.2030/ghc.el ghc-mod path: /home/wieland/.cabal/bin/ghc-mod ghc path: /usr/bin/ghc
Version: all GHC versions must be the same. ghc.el version 5.4.0.0 ghc-mod version 5.4.0.0 compiled by GHC 7.10.2 The Glorious Glasgow Haskell Compilation System, version 7.10.2
Environment variables: PATH=/home/wieland/.local/bin:/home/wieland/.cabal/bin:/opt/java/jre/bin:/home/wieland/dev/bin:/home/wieland/dev/mpdstuff:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/wieland/dev/go/bin
The result of "ghc-mod debug": Root directory: /home/wieland/dev/ghc-mod-test/new-template Current directory: /home/wieland/dev/ghc-mod-test/new-template GHC Package flags: -fbuilding-cabal-package -O -outputdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -odir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -hidir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -stubdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -hide-all-packages -no-user-package-db -package-db /home/wieland/.stack/snapshots/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-db /home/wieland/dev/ghc-mod-test/new-template/.stack-work/install/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011 -XHaskell2010 GHC System libraries: /usr/lib/ghc-7.10.2 GHC user options:
Stack ghc executable: Just "/usr/bin/ghc" Stack ghc-pkg executable:Just "/usr/bin/ghc-pkg" Cabal file: Just "/home/wieland/dev/ghc-mod-test/new-template/new-template.cabal" Project: StackProject (StackEnv {seDistDir = ".stack-work/dist/x86_64-linux/Cabal-1.22.4.0", seBinPath = ["/home/wieland/.stack/snapshots/x86_64-linux/lts-3.5/7.10.2/bin","/home/wieland/.local/bin","/home/wieland/.cabal/bin","/opt/java/jre/bin","/home/wieland/dev/bin","/home/wieland/dev/mpdstuff","/usr/local/sbin","/usr/local/bin","/usr/bin","/usr/lib/jvm/default/bin","/usr/bin/site_perl","/usr/bin/vendor_perl","/usr/bin/core_perl","/home/wieland/dev/go/bin"], seSnapshotPkgDb = "/home/wieland/.stack/snapshots/x86_64-linux/lts-3.5/7.10.2/pkgdb", seLocalPkgDb = "/home/wieland/dev/ghc-mod-test/new-template/.stack-work/install/x86_64-linux/lts-3.5/7.10.2/pkgdb"}) Cabal entrypoints: Setup.hs Main (/home/wieland/dev/ghc-mod-test/new-template/Setup.hs) library Lib (/home/wieland/dev/ghc-mod-test/new-template/src/Lib.hs) exe:new-template-exe Main (/home/wieland/dev/ghc-mod-test/new-template/app/Main.hs) test:new-template-test Main (/home/wieland/dev/ghc-mod-test/new-template/test/Spec.hs) Cabal components: Setup.hs Main (/home/wieland/dev/ghc-mod-test/new-template/Setup.hs) library Lib (/home/wieland/dev/ghc-mod-test/new-template/src/Lib.hs) exe:new-template-exe Main (/home/wieland/dev/ghc-mod-test/new-template/app/Main.hs) test:new-template-test Main (/home/wieland/dev/ghc-mod-test/new-template/test/Spec.hs) GHC Cabal options: Setup.hs library -fbuilding-cabal-package -O -outputdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -odir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -hidir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -stubdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -hide-all-packages -no-user-package-db -package-db /home/wieland/.stack/snapshots/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-db /home/wieland/dev/ghc-mod-test/new-template/.stack-work/install/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011 -XHaskell2010 exe:new-template-exe -fbuilding-cabal-package -O -outputdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -odir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -hidir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -stubdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-exe/new-template-exe-tmp -iapp -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-exe/new-template-exe-tmp -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -hide-all-packages -no-user-package-db -package-db /home/wieland/.stack/snapshots/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-db /home/wieland/dev/ghc-mod-test/new-template/.stack-work/install/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011 -XHaskell2010 -threaded -rtsopts -with-rtsopts=-N test:new-template-test -fbuilding-cabal-package -O -outputdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -odir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -hidir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -stubdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-test/new-template-test-tmp -itest -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-test/new-template-test-tmp -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -hide-all-packages -no-user-package-db -package-db /home/wieland/.stack/snapshots/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-db /home/wieland/dev/ghc-mod-test/new-template/.stack-work/install/x86_64-linux/lts-3.5/7.10.2/pkgdb/ -package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011 -XHaskell2010 -threaded -rtsopts -with-rtsopts=-N GHC search path options: Setup.hs library -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h exe:new-template-exe -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-exe/new-template-exe-tmp -iapp -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-exe/new-template-exe-tmp -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h test:new-template-test -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-test/new-template-test-tmp -itest -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/new-template-test/new-template-test-tmp -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h
:+1:
M-t
does not add the function signature for me either. I am also using stack so that might be related.
I am using the latest master e278e1414ded that I have built using stack
.
Extra info:
-
c-c c-t
(ghc-show-type) does work fine -
M-t
does insert "module Foo where" on a brand new file.
:+1: the same here
What about dropping the function from ghc-mod
if there is no care at all about fixing it ?
Is any work being done with this issue? After debugging for a bit it appears that the problem lies in incorrect overlays. Ghc-mod expects ghc-annotated overlays but the overlays don't have the expected properties.
@liarokapisv well it seems you're working on it :)
Can you link to some code maybe?
The relevant call sequence is
ghc-insert-template-or-signature ->
ghc-insert-template
at this point there is a cond expression:
(cond ..
((ghc-check-overlay-at (point))
(or (ghc-check-insert-from-warning)
....
ghc-check-insert-from-warning
is where the extraction is supposed to happen, however
ghc-check-overlay-at
always fails. Internally it filters overlays using the ghc-overlay-p
predicate which matches overlays with the ghc-check
property. The overlays are there but have flycheck properties instead of ghc properties so ghc-check-p
fails.
ghc-check-insert-from-warning
also expects a ghc-msg
property which is replaced by a flycheck property.
I would definitely like to see this work.
This may or may not be a problem with spacemacs, and not ghc-mod itself. There is this line in the spacemacs haskell layer funcs file:
(when (configuration-layer/package-usedp 'flycheck)
;; remove overlays from ghc-check.el if flycheck is enabled
(set-face-attribute 'ghc-face-error nil :underline nil)
(set-face-attribute 'ghc-face-warn nil :underline nil)))
In which case it's obvious why there are no ghc properties in overlays and why the insertions fail. Removing this line doesn't seem to do much, I will have to investigate further.