atom-haskell / ide-haskell-repl

GHCi REPL in Atom
https://atom.io/packages/ide-haskell-repl
MIT License
26 stars 8 forks source link

.ghci errors on start #60

Closed freeman42x closed 6 years ago

freeman42x commented 6 years ago

When the plugin loads it prints in the IDE-Haskell error tab:

/home/neo/HaskellLearning/IdeTest/home/neo/.ghci.hs: 1, 1
Failed to load interface for `IPPrint'
Use -v to see a list of the files searched for.
/home/neo/HaskellLearning/IdeTest/home/neo/.ghci.hs: 2, 1
Failed to load interface for `Language.Haskell.HsColour'
Use -v to see a list of the files searched for.
/home/neo/HaskellLearning/IdeTest/home/neo/.ghci.hs: 3, 1
Failed to load interface for `Language.Haskell.HsColour.Colourise'
Use -v to see a list of the files searched for.
/home/neo/HaskellLearning/IdeTest/home/neo/.ghci.hs: 4, 1
Failed to load interface for `Language.Haskell.HsColour.Output'
Use -v to see a list of the files searched for.

These happens because in ~/.ghci I have added a custom pretty printer to get colored output in ghci when it is run from a usual terminal:

.ghci

:load ~/.ghci.hs
:set -interactive-print=myPrint

:set prompt "\ESC[33m\STXλ> \ESC[m\STX"
:set prompt-cont "   | "
:set +m

.ghci.hs

import qualified IPPrint
import qualified Language.Haskell.HsColour as HsColour
import qualified Language.Haskell.HsColour.Colourise as HsColour
import qualified Language.Haskell.HsColour.Output as HsColour

myColourPrefs = HsColour.defaultColourPrefs
    { HsColour.conid    = [HsColour.Foreground HsColour.Yellow, HsColour.Bold]
    , HsColour.conop    = [HsColour.Foreground HsColour.Yellow]
    , HsColour.string   = [HsColour.Foreground HsColour.Green]
    , HsColour.char     = [HsColour.Foreground HsColour.Cyan]
    , HsColour.number   = [HsColour.Foreground HsColour.Red, HsColour.Bold]
    , HsColour.layout   = [HsColour.Foreground HsColour.White]
    , HsColour.keyglyph = [HsColour.Foreground HsColour.White]
    , HsColour.comment  = [HsColour.Foreground HsColour.Red, HsColour.Bold] }

myPrint :: (Show a) => a -> IO ()
myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow

Any suggestion of how to make the libraries visible to the plugin (preferably in a global way)?

lierdakil commented 6 years ago

Ehehe. Making libraries visible to the plugin will almost certainly break stuff. I would suggest adding -ignore-dot-ghci to extraArgs setting: image

freeman42x commented 6 years ago

Thank you very much. That worked!

freeman42x commented 6 years ago

@lierdakil Unfortunately this disables using any .ghci file including the one in a project root. I'm looking into what arguments need to be passed to GHCI for it to load those libraries it requires.

freeman42x commented 6 years ago

Adding the global .ghci library dependency to the cabal file fixed the warnings (but not really a solution):

build-depends:
    base >=4.7 && <5,
    time,
    ipprint,
    hscolour

I also tried to tell ghci to load the packages using Extra Args with -package ipprint but that completely crashed the REPL without any error message - the text box for issuing commands dissapeared.

But then it still errord with:

Not in scope: ‘myPrint’

And 2 warnings:

Some flags have not been recognized: prompt-cont,    | 
Some flags have not been recognized: prompt-cont, 

First one is caused by :set prompt-cont " | " from global .ghci, the other warning comes from ide-haskell-repl, related issue: https://github.com/atom-haskell/ide-haskell-repl/issues/58

lierdakil commented 6 years ago

Long story short: use stack repl or cabal repl with an appropriately configured Stack/Cabal project to bring libraries into repl scope.

This package can not support arbitrary .ghci configs. If you want that, consider just running ghci from a terminal (embedded into Atom or not, see f.ex. terminal-plus or atom-domterm packages).

If you still want to make it work somehow, you're on your own.