@@ -34,14 +34,12 @@ import Data.Aeson hiding (Error)
3434import Data.Bifunctor
3535import qualified Data.ByteString.Base16 as B16
3636import qualified Data.ByteString.Char8 as B
37- import Data.Char (isLower )
3837import Data.Default
3938import Data.Either.Extra
4039import Data.Function
4140import Data.Hashable hiding (hash )
4241import qualified Data.HashMap.Strict as HM
4342import Data.List
44- import Data.List.Extra (dropPrefix , split )
4543import qualified Data.Map.Strict as Map
4644import Data.Maybe
4745import Data.Proxy
@@ -69,7 +67,6 @@ import Development.IDE.Types.Location
6967import Development.IDE.Types.Options
7068import GHC.Check
7169import qualified HIE.Bios as HieBios
72- import qualified HIE.Bios.Cradle as HieBios
7370import HIE.Bios.Environment hiding (getCacheDir )
7471import HIE.Bios.Types hiding (Log )
7572import qualified HIE.Bios.Types as HieBios
@@ -103,6 +100,7 @@ import Data.HashSet (HashSet)
103100import qualified Data.HashSet as Set
104101import Database.SQLite.Simple
105102import Development.IDE.Core.Tracing (withTrace )
103+ import Development.IDE.Session.Diagnostics (renderCradleError )
106104import Development.IDE.Types.Shake (WithHieDb )
107105import HieDb.Create
108106import HieDb.Types
@@ -685,7 +683,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
685683 Left err -> do
686684 dep_info <- getDependencyInfo (maybeToList hieYaml)
687685 let ncfp = toNormalizedFilePath' cfp
688- let res = (map (renderCradleError cradle ncfp) err, Nothing )
686+ let res = (map (\ err' -> renderCradleError err' cradle ncfp) err, Nothing )
689687 void $ modifyVar' fileToFlags $
690688 Map. insertWith HM. union hieYaml (HM. singleton ncfp (res, dep_info))
691689 void $ modifyVar' filesMap $ HM. insert ncfp hieYaml
@@ -924,72 +922,6 @@ setCacheDirs recorder CacheDirs{..} dflags = do
924922 & maybe id setHieDir hieCacheDir
925923 & maybe id setODir oCacheDir
926924
927-
928- renderCradleError :: Cradle a -> NormalizedFilePath -> CradleError -> FileDiagnostic
929- renderCradleError cradle nfp (CradleError _ _ec ms) =
930- ideErrorWithSource (Just " cradle" ) (Just DiagnosticSeverity_Error ) nfp $ T. unlines $ map T. pack userFriendlyMessage
931- where
932-
933- userFriendlyMessage :: [String ]
934- userFriendlyMessage
935- | HieBios. isCabalCradle cradle = fromMaybe ms fileMissingMessage
936- | otherwise = ms
937-
938- fileMissingMessage :: Maybe [String ]
939- fileMissingMessage =
940- multiCradleErrMessage <$> parseMultiCradleErr ms
941-
942- -- | Information included in Multi Cradle error messages
943- data MultiCradleErr = MultiCradleErr
944- { mcPwd :: FilePath
945- , mcFilePath :: FilePath
946- , mcPrefixes :: [(FilePath , String )]
947- } deriving (Show )
948-
949- -- | Attempt to parse a multi-cradle message
950- parseMultiCradleErr :: [String ] -> Maybe MultiCradleErr
951- parseMultiCradleErr ms = do
952- _ <- lineAfter " Multi Cradle: "
953- wd <- lineAfter " pwd: "
954- fp <- lineAfter " filepath: "
955- ps <- prefixes
956- pure $ MultiCradleErr wd fp ps
957-
958- where
959- lineAfter :: String -> Maybe String
960- lineAfter pre = listToMaybe $ mapMaybe (stripPrefix pre) ms
961-
962- prefixes :: Maybe [(FilePath , String )]
963- prefixes = do
964- pure $ mapMaybe tuple ms
965-
966- tuple :: String -> Maybe (String , String )
967- tuple line = do
968- line' <- surround ' (' line ' )'
969- [f, s] <- pure $ split (== ' ,' ) line'
970- pure (f, s)
971-
972- -- extracts the string surrounded by required characters
973- surround :: Char -> String -> Char -> Maybe String
974- surround start s end = do
975- guard (listToMaybe s == Just start)
976- guard (listToMaybe (reverse s) == Just end)
977- pure $ drop 1 $ take (length s - 1 ) s
978-
979- multiCradleErrMessage :: MultiCradleErr -> [String ]
980- multiCradleErrMessage e =
981- [ " Loading the module '" <> moduleFileName <> " ' failed. It may not be listed in your .cabal file!"
982- , " Perhaps you need to add `" <> moduleName <> " ` to other-modules or exposed-modules."
983- , " For more information, visit: https://cabal.readthedocs.io/en/3.4/developing-packages.html#modules-included-in-the-package"
984- , " "
985- ] <> map prefix (mcPrefixes e)
986- where
987- localFilePath f = dropWhile (== pathSeparator) $ dropPrefix (mcPwd e) f
988- moduleFileName = localFilePath $ mcFilePath e
989- moduleName = intercalate " ." $ map dropExtension $ dropWhile isSourceFolder $ splitDirectories moduleFileName
990- isSourceFolder p = all isLower $ take 1 p
991- prefix (f, r) = f <> " - " <> r
992-
993925-- See Note [Multi Cradle Dependency Info]
994926type DependencyInfo = Map. Map FilePath (Maybe UTCTime )
995927type HieMap = Map. Map (Maybe FilePath ) (HscEnv , [RawComponentInfo ])
0 commit comments