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