Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit bb361f6

Browse files
committed
Show log message early on
1 parent a947058 commit bb361f6

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/Haskell/Ide/Engine/Server.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ run scheduler _origDir plugins captureFp = flip E.catches handlers $ do
158158

159159
-- Check for mismatching GHC versions
160160
-- Ignore hie.yaml parse errors. They get reported in ModuleCache.hs
161-
let parseErrorHandler (_ :: Yaml.ParseException) = return Nothing
161+
let parseErrorHandler (_ :: Yaml.ParseException) = do
162+
logm "Caught a yaml parse exception"
163+
return Nothing
162164
dummyCradleFile = fromMaybe currentDir lspRootDir </> "File.hs"
163165
logm $ "Dummy Cradle File: " ++ dummyCradleFile
164166
mcradle <- liftIO $ E.catch (Just <$> findLocalCradle dummyCradleFile) parseErrorHandler
@@ -412,13 +414,12 @@ reactor inp diagIn = do
412414
currentDir <- liftIO getCurrentDirectory
413415

414416
-- Check for mismatching GHC versions
415-
-- Ignore hie.yaml parse errors. They get reported in ModuleCache.hs
416-
let parseErrorHandler (_ :: Yaml.ParseException) = return Nothing
417-
dummyCradleFile = (fromMaybe currentDir lspRootDir) </> "File.hs"
418-
cradleRes <- liftIO $ E.catch (Just <$> findLocalCradle dummyCradleFile) parseErrorHandler
417+
let dummyCradleFile = (fromMaybe currentDir lspRootDir) </> "File.hs"
418+
logm $ "Dummy Cradle file result: " ++ dummyCradleFile
419+
cradleRes <- liftIO $ E.try (findLocalCradle dummyCradleFile)
419420

420421
case cradleRes of
421-
Just cradle -> do
422+
Right cradle -> do
422423
projGhcVersion <- liftIO $ getProjectGhcVersion cradle
423424
when (projGhcVersion /= hieGhcVersion) $ do
424425
let msg = T.pack $ "Mismatching GHC versions: " ++ cradleDisplay cradle ++
@@ -435,7 +436,9 @@ reactor inp diagIn = do
435436
reactorSend $ NotShowMessage $ fmServerShowMessageNotification J.MtWarning cabalMsg
436437
reactorSend $ NotLogMessage $ fmServerLogMessageNotification J.MtWarning cabalMsg
437438

438-
Nothing -> return ()
439+
Left (_ :: Yaml.ParseException) -> do
440+
logm "Failed to parse it"
441+
reactorSend $ NotShowMessage $ fmServerShowMessageNotification J.MtError "Couldn't parse hie.yaml"
439442

440443
renv <- ask
441444
let hreq = GReq tn "init-hoogle" Nothing Nothing Nothing callback Nothing $ IdeResultOk <$> Hoogle.initializeHoogleDb

test/dispatcher/Main.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ startServer :: IO (Scheduler IO, TChan LogVal, ThreadId)
7272
startServer = do
7373
scheduler <- newScheduler plugins testOptions
7474
logChan <- newTChanIO
75+
-- This is correct because we set the working directory to
76+
-- "test/testdata" in the function set-up.
7577
cwd <- getCurrentDirectory
7678
crdl <- Bios.findLocalCradle (cwd </> "File.hs")
7779
dispatcher <- forkIO $ do
@@ -131,6 +133,7 @@ instance ToJSON Cached where
131133

132134
funcSpec :: Spec
133135
funcSpec = describe "functional dispatch" $ do
136+
-- required to not kill the 'findLocalCradle' logic in 'startServer'.
134137
runIO $ setCurrentDirectory "test/testdata"
135138
(scheduler, logChan, dispatcher) <- runIO startServer
136139

test/functional/HieBiosSpec.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Language.Haskell.LSP.Messages
99
import System.FilePath ((</>))
1010
import Test.Hspec
1111
import TestUtils
12+
import Debug.Trace ( trace )
1213

1314
spec :: Spec
1415
-- Create an empty hie.yaml to trigger the parse error
@@ -20,15 +21,14 @@ spec = beforeAll_ (writeFile (hieBiosErrorPath </> "hie.yaml") "") $ do
2021
_ <- openDoc "Main.hs" "haskell"
2122
_ <- count 2 waitForDiagnostics
2223
return ()
23-
24+
2425
it "reports errors in hie.yaml" $ runSession hieCommand fullCaps hieBiosErrorPath $ do
2526
_ <- openDoc "Foo.hs" "haskell"
2627
_ <- skipManyTill loggingNotification (satisfy isMessage)
2728
return ()
28-
29+
2930
where hieBiosErrorPath = "test/testdata/hieBiosError"
30-
31+
3132
isMessage (NotShowMessage (NotificationMessage _ _ (ShowMessageParams MtError s))) =
3233
"Couldn't parse hie.yaml" `T.isInfixOf` s
33-
isMessage _ = False
34-
34+
isMessage m = trace ("Message: " ++ show m) $ False

0 commit comments

Comments
 (0)