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

Commit 61f9391

Browse files
committed
Show log message early on
1 parent aefdd7d commit 61f9391

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
@@ -157,7 +157,9 @@ run scheduler _origDir plugins captureFp = flip E.catches handlers $ do
157157

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

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

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

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

439442
renv <- ask
440443
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
@@ -71,6 +71,8 @@ startServer :: IO (Scheduler IO, TChan LogVal, ThreadId)
7171
startServer = do
7272
scheduler <- newScheduler plugins testOptions
7373
logChan <- newTChanIO
74+
-- This is correct because we set the working directory to
75+
-- "test/testdata" in the function set-up.
7476
cwd <- getCurrentDirectory
7577
crdl <- Bios.findLocalCradle (cwd </> "File.hs")
7678
dispatcher <- forkIO $ do
@@ -130,6 +132,7 @@ instance ToJSON Cached where
130132

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

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)