@@ -12,24 +12,30 @@ import Development.IDE.Types.Location
1212import qualified HIE.Bios.Cradle as HieBios
1313import HIE.Bios.Types hiding (Log )
1414import System.FilePath
15+ import Control.Applicative
1516
1617{- | Takes a cradle error, the corresponding cradle and the file path where
1718 the cradle error occurred (of the file we attempted to load).
1819 Depicts the cradle error in a user-friendly way.
1920-}
2021renderCradleError :: CradleError -> Cradle a -> NormalizedFilePath -> FileDiagnostic
2122renderCradleError (CradleError deps _ec ms) cradle nfp
22- | HieBios. isCabalCradle cradle && any (isInfixOf " Error: cabal: Failed extracting script block: " ) ms =
23+ | HieBios. isCabalCradle cradle =
2324 let (fp, showDiag, diag) = ideErrorWithSource (Just " cradle" ) (Just DiagnosticSeverity_Error ) nfp $ T. unlines $ map T. pack userFriendlyMessage in
2425 (fp, showDiag, diag{_data_ = Just (Aeson. Array $ Vector. fromList $ map (Aeson. String . T. pack) absDeps)})
2526 | otherwise = ideErrorWithSource (Just " cradle" ) (Just DiagnosticSeverity_Error ) nfp $ T. unlines $ map T. pack userFriendlyMessage
2627 where
2728 absDeps = fmap (cradleRootDir cradle </> ) deps
2829 userFriendlyMessage :: [String ]
2930 userFriendlyMessage
30- | HieBios. isCabalCradle cradle = fromMaybe ms fileMissingMessage
31+ | HieBios. isCabalCradle cradle = fromMaybe ms $ fileMissingMessage <|> mkUnknownModuleMessage
3132 | otherwise = ms
3233
34+ mkUnknownModuleMessage :: Maybe [String ]
35+ mkUnknownModuleMessage
36+ | any (isInfixOf " Error: cabal: Failed extracting script block:" ) ms = Just $ unknownModuleMessage (fromNormalizedFilePath nfp) Nothing
37+ | otherwise = Nothing
38+
3339 fileMissingMessage :: Maybe [String ]
3440 fileMissingMessage =
3541 multiCradleErrMessage <$> parseMultiCradleErr ms
@@ -73,14 +79,20 @@ parseMultiCradleErr ms = do
7379
7480multiCradleErrMessage :: MultiCradleErr -> [String ]
7581multiCradleErrMessage e =
76- [ " Loading the module '" <> moduleFileName <> " ' failed. It may not be listed in your .cabal file!"
77- , " Perhaps you need to add `" <> moduleName <> " ` to other-modules or exposed-modules."
78- , " For more information, visit: https://cabal.readthedocs.io/en/3.4/developing-packages.html#modules-included-in-the-package"
79- , " "
80- ] <> map prefix (mcPrefixes e)
82+ unknownModuleMessage moduleFileName (Just moduleName)
83+ <> [" " ]
84+ <> map prefix (mcPrefixes e)
8185 where
8286 localFilePath f = dropWhile (== pathSeparator) $ dropPrefix (mcPwd e) f
8387 moduleFileName = localFilePath $ mcFilePath e
8488 moduleName = intercalate " ." $ map dropExtension $ dropWhile isSourceFolder $ splitDirectories moduleFileName
8589 isSourceFolder p = all isLower $ take 1 p
8690 prefix (f, r) = f <> " - " <> r
91+
92+ unknownModuleMessage :: String -> Maybe String -> [String ]
93+ unknownModuleMessage moduleFileName moduleNameM =
94+ [ " Loading the module '" <> moduleFileName <> " ' failed."
95+ , " It may not be listed in your .cabal file!"
96+ , " Perhaps you need to add `" <> fromMaybe (takeFileName moduleFileName) moduleNameM <> " ` to other-modules or exposed-modules."
97+ , " For more information, visit: https://cabal.readthedocs.io/en/3.4/developing-packages.html#modules-included-in-the-package"
98+ ]
0 commit comments