@@ -42,7 +42,7 @@ import Data.Hashable
42
42
import qualified Data.HashMap.Strict as HM
43
43
import Data.IORef
44
44
import Data.List
45
- import Data.List.Extra (dropPrefix , replace )
45
+ import Data.List.Extra (dropPrefix , split )
46
46
import qualified Data.Map.Strict as Map
47
47
import Data.Maybe
48
48
import Data.Proxy
@@ -77,6 +77,7 @@ import Development.IDE.Types.Logger (Pretty (pretty),
77
77
import Development.IDE.Types.Options
78
78
import GHC.Check
79
79
import qualified HIE.Bios as HieBios
80
+ import qualified HIE.Bios.Cradle as HieBios
80
81
import HIE.Bios.Environment hiding (getCacheDir )
81
82
import HIE.Bios.Types hiding (Log )
82
83
import qualified HIE.Bios.Types as HieBios
@@ -664,7 +665,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
664
665
Left err -> do
665
666
dep_info <- getDependencyInfo (maybeToList hieYaml)
666
667
let ncfp = toNormalizedFilePath' cfp
667
- let res = (map (renderCradleError ncfp) err, Nothing )
668
+ let res = (map (renderCradleError cradle ncfp) err, Nothing )
668
669
void $ modifyVar' fileToFlags $
669
670
Map. insertWith HM. union hieYaml (HM. singleton ncfp (res, dep_info))
670
671
void $ modifyVar' filesMap $ HM. insert ncfp hieYaml
@@ -907,46 +908,75 @@ setCacheDirs recorder CacheDirs{..} dflags = do
907
908
& maybe id setODir oCacheDir
908
909
909
910
910
- renderCradleError :: NormalizedFilePath -> CradleError -> FileDiagnostic
911
- renderCradleError nfp (CradleError _ _ec ms) =
912
- ideErrorWithSource (Just " cradle" ) (Just DiagnosticSeverity_Error ) nfp $ T. unlines $ map T. pack $ fromMaybe ms fileMissingMessage
911
+ renderCradleError :: Cradle a -> NormalizedFilePath -> CradleError -> FileDiagnostic
912
+ renderCradleError cradle nfp (CradleError _ _ec ms) =
913
+ ideErrorWithSource (Just " cradle" ) (Just DiagnosticSeverity_Error ) nfp $ T. unlines $ map T. pack userFriendlyMessage
913
914
where
914
915
916
+ userFriendlyMessage :: [String ]
917
+ userFriendlyMessage
918
+ | HieBios. isCabalCradle cradle = fromMaybe ms fileMissingMessage
919
+ | otherwise = ms
920
+
915
921
fileMissingMessage :: Maybe [String ]
916
922
fileMissingMessage =
917
923
multiCradleErrMessage <$> parseMultiCradleErr ms
918
924
919
925
-- | Information included in Multi Cradle error messages
920
926
data MultiCradleErr = MultiCradleErr
921
- { multiCradlePwd :: FilePath
922
- , multiCradleFilePath :: FilePath
923
- -- , multiCradlePrefixes :: [Prefix ]
927
+ { mcPwd :: FilePath
928
+ , mcFilePath :: FilePath
929
+ , mcPrefixes :: [( FilePath , String ) ]
924
930
} deriving (Show )
925
931
926
932
-- | Attempt to parse a multi-cradle message
927
933
parseMultiCradleErr :: [String ] -> Maybe MultiCradleErr
928
934
parseMultiCradleErr ms = do
929
- _ <- prefix " Multi Cradle"
930
- wd <- prefix " pwd"
931
- fp <- prefix " filepath"
932
- pure $ MultiCradleErr wd fp
935
+ _ <- lineAfter " Multi Cradle: "
936
+ wd <- lineAfter " pwd: "
937
+ fp <- lineAfter " filepath: "
938
+ ps <- prefixes
939
+ pure $ MultiCradleErr wd fp ps
933
940
934
941
where
935
- -- Extract the string after any line starting with "prefix: "
936
- prefix :: String -> Maybe String
937
- prefix pre = listToMaybe $ mapMaybe (stripPrefix (pre ++ " : " )) ms
942
+ lineAfter :: String -> Maybe String
943
+ lineAfter pre = listToMaybe $ mapMaybe (stripPrefix pre) ms
944
+
945
+ prefixes :: Maybe [(FilePath , String )]
946
+ prefixes = do
947
+ pure $ mapMaybe tuple ms
948
+
949
+ tuple :: String -> Maybe (String , String )
950
+ tuple line = do
951
+ line' <- surround ' (' line ' )'
952
+ [f, s] <- pure $ split (== ' ,' ) line'
953
+ pure (f, s)
954
+
955
+ -- extracts the string surrounded by required characters
956
+ surround :: Char -> String -> Char -> Maybe String
957
+ surround start s end = do
958
+ guard (listToMaybe s == Just start)
959
+ guard (listToMaybe (reverse s) == Just end)
960
+ pure $ drop 1 $ take (length s - 1 ) s
961
+
962
+
963
+
964
+
965
+
938
966
939
967
multiCradleErrMessage :: MultiCradleErr -> [String ]
940
968
multiCradleErrMessage e =
941
969
[ " Loading the module '" <> moduleFileName <> " ' failed. It seems that it is not listed in your .cabal file!"
942
970
, " Perhaps you need to add `" <> moduleName <> " ` to other-modules or exposed-modules" -- named 'example' in example.cabal."
943
971
, " For more information, visit: https://cabal.readthedocs.io/en/3.4/developing-packages.html#modules-included-in-the-package"
944
- ]
972
+ , " "
973
+ ] <> map prefix (mcPrefixes e)
945
974
where
946
- localFilePath f = dropWhile (== pathSeparator) $ dropPrefix (multiCradlePwd e) f
947
- moduleFileName = localFilePath $ multiCradleFilePath e
975
+ localFilePath f = dropWhile (== pathSeparator) $ dropPrefix (mcPwd e) f
976
+ moduleFileName = localFilePath $ mcFilePath e
948
977
moduleName = intercalate " ." $ map dropExtension $ dropWhile isSourceFolder $ splitDirectories moduleFileName
949
978
isSourceFolder p = all isLower $ take 1 p
979
+ prefix (f, r) = f <> " - " <> r
950
980
951
981
952
982
0 commit comments