git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
[psc-ide] Switches to the Protolude
8063c4dChristoph Hegemann
psc-ide-server/Main.hs+17−25
@@ -17,21 +17,14 @@
17{-# LANGUAGE OverloadedStrings #-}
17{-# LANGUAGE OverloadedStrings #-}
18{-# LANGUAGE PackageImports #-}
18{-# LANGUAGE PackageImports #-}
19{-# LANGUAGE TemplateHaskell #-}
19{-# LANGUAGE TemplateHaskell #-}
20+{-# LANGUAGE NoImplicitPrelude #-}
20
21
21module Main where
22module Main where
22
23
23−import Prelude ()
24+import Protolude
24−import Prelude.Compat
25
25
26−import Control.Concurrent (forkFinally)
27import Control.Concurrent.STM
26import Control.Concurrent.STM
28−import Control.Exception (bracketOnError, catchJust)
29−import Control.Monad
30−import Control.Monad.Error.Class
31import "monad-logger" Control.Monad.Logger
27import "monad-logger" Control.Monad.Logger
32−import Control.Monad.Reader
33−import Control.Monad.Trans.Except
34−import qualified Data.Text as T
35import qualified Data.Text.IO as T
28import qualified Data.Text.IO as T
36import Data.Version (showVersion)
29import Data.Version (showVersion)
37import Language.PureScript.Ide
30import Language.PureScript.Ide
@@ -43,10 +36,10 @@ import Network hiding (socketPort, accept)
43import Network.BSD (getProtocolNumber)
36import Network.BSD (getProtocolNumber)
44import Network.Socket hiding (PortNumber, Type,
37import Network.Socket hiding (PortNumber, Type,
45 sClose)
38 sClose)
46−import Options.Applicative
39+import Options.Applicative hiding ((<>))
47import System.Directory
40import System.Directory
48import System.FilePath
41import System.FilePath
49−import System.IO
42+import System.IO hiding (putStrLn, print)
50import System.IO.Error (isEOFError)
43import System.IO.Error (isEOFError)
51
44
52import qualified Paths_purescript as Paths
45import qualified Paths_purescript as Paths
@@ -54,8 +47,8 @@ import qualified Paths_purescript as Paths
54-- "Borrowed" from the Idris Compiler
47-- "Borrowed" from the Idris Compiler
55-- Copied from upstream impl of listenOn
48-- Copied from upstream impl of listenOn
56-- bound to localhost interface instead of iNADDR_ANY
49-- bound to localhost interface instead of iNADDR_ANY
57−listenOnLocalhost :: PortID -> IO Socket
50+listenOnLocalhost :: PortNumber -> IO Socket
58−listenOnLocalhost (PortNumber port) = do
51+listenOnLocalhost port = do
59 proto <- getProtocolNumber "tcp"
52 proto <- getProtocolNumber "tcp"
60 localhost <- inet_addr "127.0.0.1"
53 localhost <- inet_addr "127.0.0.1"
61 bracketOnError
54 bracketOnError
@@ -66,12 +59,11 @@ listenOnLocalhost (PortNumber port) = do
66 bindSocket sock (SockAddrInet port localhost)
59 bindSocket sock (SockAddrInet port localhost)
67 listen sock maxListenQueue
60 listen sock maxListenQueue
68 pure sock)
61 pure sock)
69−listenOnLocalhost _ = error "Wrong Porttype"
70
62
71data Options = Options
63data Options = Options
72 { optionsDirectory :: Maybe FilePath
64 { optionsDirectory :: Maybe FilePath
73 , optionsOutputPath :: FilePath
65 , optionsOutputPath :: FilePath
74− , optionsPort :: PortID
66+ , optionsPort :: PortNumber
75 , optionsNoWatch :: Bool
67 , optionsNoWatch :: Bool
76 , optionsDebug :: Bool
68 , optionsDebug :: Bool
77 }
69 }
@@ -88,8 +80,8 @@ main = do
88 unlessM (doesDirectoryExist fullOutputPath) $ do
80 unlessM (doesDirectoryExist fullOutputPath) $ do
89 putStrLn ("Your output directory didn't exist. I'll create it at: " <> fullOutputPath)
81 putStrLn ("Your output directory didn't exist. I'll create it at: " <> fullOutputPath)
90 createDirectory fullOutputPath
82 createDirectory fullOutputPath
91− putStrLn "This usually means you didn't compile your project yet."
83+ putText "This usually means you didn't compile your project yet."
92− putStrLn "psc-ide needs you to compile your project (for example by running pulp build)"
84+ putText "psc-ide needs you to compile your project (for example by running pulp build)"
93
85
94 unless noWatch $
86 unless noWatch $
95 void (forkFinally (watcher ideState fullOutputPath) print)
87 void (forkFinally (watcher ideState fullOutputPath) print)
@@ -100,18 +92,18 @@ main = do
100 where
92 where
101 parser =
93 parser =
102 Options
94 Options
103− <$> optional (strOption (long "directory" <> short 'd'))
95+ <$> optional (strOption (long "directory" `mappend` short 'd'))
104− <*> strOption (long "output-directory" <> value "output/")
96+ <*> strOption (long "output-directory" `mappend` value "output/")
105− <*> (PortNumber . fromIntegral <$>
97+ <*> (fromIntegral <$>
106− option auto (long "port" <> short 'p' <> value (4242 :: Integer)))
98+ option auto (long "port" `mappend` short 'p' `mappend` value (4242 :: Integer)))
107 <*> switch (long "no-watch")
99 <*> switch (long "no-watch")
108 <*> switch (long "debug")
100 <*> switch (long "debug")
109 opts = info (version <*> helper <*> parser) mempty
101 opts = info (version <*> helper <*> parser) mempty
110 version = abortOption
102 version = abortOption
111 (InfoMsg (showVersion Paths.version))
103 (InfoMsg (showVersion Paths.version))
112− (long "version" <> help "Show the version number")
104+ (long "version" `mappend` help "Show the version number")
113
105
114−startServer :: PortID -> IdeEnvironment -> IO ()
106+startServer :: PortNumber -> IdeEnvironment -> IO ()
115startServer port env = withSocketsDo $ do
107startServer port env = withSocketsDo $ do
116 sock <- listenOnLocalhost port
108 sock <- listenOnLocalhost port
117 runLogger (runReaderT (forever (loop sock)) env)
109 runLogger (runReaderT (forever (loop sock)) env)
@@ -141,8 +133,8 @@ startServer port env = withSocketsDo $ do
141 liftIO (hClose h)
133 liftIO (hClose h)
142
134
143
135
144−acceptCommand :: (MonadIO m, MonadLogger m, MonadError T.Text m)
136+acceptCommand :: (MonadIO m, MonadLogger m, MonadError Text m)
145− => Socket -> m (T.Text, Handle)
137+ => Socket -> m (Text, Handle)
146acceptCommand sock = do
138acceptCommand sock = do
147 h <- acceptConnection
139 h <- acceptConnection
148 $(logDebug) "Accepted a connection"
140 $(logDebug) "Accepted a connection"
purescript.cabal+3−1
@@ -101,7 +101,6 @@ library
101 aeson >= 0.8 && < 0.12,
101 aeson >= 0.8 && < 0.12,
102 aeson-better-errors >= 0.8,
102 aeson-better-errors >= 0.8,
103 ansi-terminal >= 0.6.2 && < 0.7,
103 ansi-terminal >= 0.6.2 && < 0.7,
104− async,
105 base-compat >=0.6.0,
104 base-compat >=0.6.0,
106 bower-json >= 0.8,
105 bower-json >= 0.8,
107 boxes >= 0.1.4 && < 0.2.0,
106 boxes >= 0.1.4 && < 0.2.0,
@@ -126,6 +125,7 @@ library
126 pipes >= 4.0.0 && < 4.2.0,
125 pipes >= 4.0.0 && < 4.2.0,
127 pipes-http -any,
126 pipes-http -any,
128 process >= 1.2.0 && < 1.5,
127 process >= 1.2.0 && < 1.5,
128+ protolude >= 0.1.5,
129 regex-tdfa -any,
129 regex-tdfa -any,
130 safe >= 0.3.9 && < 0.4,
130 safe >= 0.3.9 && < 0.4,
131 semigroups >= 0.16.2 && < 0.19,
131 semigroups >= 0.16.2 && < 0.19,
@@ -435,6 +435,7 @@ executable psc-ide-server
435 mtl -any,
435 mtl -any,
436 network -any,
436 network -any,
437 optparse-applicative >= 0.12.1,
437 optparse-applicative >= 0.12.1,
438+ protolude >= 0.1.5,
438 stm -any,
439 stm -any,
439 text -any,
440 text -any,
440 transformers -any,
441 transformers -any,
@@ -475,6 +476,7 @@ test-suite tests
475 optparse-applicative -any,
476 optparse-applicative -any,
476 parsec -any,
477 parsec -any,
477 process -any,
478 process -any,
479+ protolude >= 0.1.5,
478 silently -any,
480 silently -any,
479 stm -any,
481 stm -any,
480 text -any,
482 text -any,
src/Language/PureScript/Ide.hs+3−14
@@ -21,19 +21,9 @@ module Language.PureScript.Ide
21 , printModules
21 , printModules
22 ) where
22 ) where
23
23
24−import Prelude ()
24+import Protolude
25−import Prelude.Compat
26
25
27−import Control.Concurrent.Async
28−import Control.Monad.Error.Class
29−import Control.Monad.IO.Class
30import "monad-logger" Control.Monad.Logger
26import "monad-logger" Control.Monad.Logger
31−import Control.Monad.Reader
32−import Data.Foldable
33−import Data.Maybe (catMaybes)
34−import Data.Monoid
35−import Data.Text (Text)
36−import qualified Data.Text as T
37import qualified Language.PureScript as P
27import qualified Language.PureScript as P
38import qualified Language.PureScript.Ide.CaseSplit as CS
28import qualified Language.PureScript.Ide.CaseSplit as CS
39import Language.PureScript.Ide.Command
29import Language.PureScript.Ide.Command
@@ -50,7 +40,6 @@ import Language.PureScript.Ide.State
50import Language.PureScript.Ide.Types
40import Language.PureScript.Ide.Types
51import Language.PureScript.Ide.Util
41import Language.PureScript.Ide.Util
52import System.Directory
42import System.Directory
53−import System.Exit
54import System.FilePath
43import System.FilePath
55
44
56handleCommand :: (Ide m, MonadLogger m, MonadError PscIdeError m) =>
45handleCommand :: (Ide m, MonadLogger m, MonadError PscIdeError m) =>
@@ -86,7 +75,7 @@ handleCommand (Import fp outfp filters (AddImportForIdentifier ident)) = do
86handleCommand (Rebuild file) =
75handleCommand (Rebuild file) =
87 rebuildFile file
76 rebuildFile file
88handleCommand Cwd =
77handleCommand Cwd =
89− TextResult . T.pack <$> liftIO getCurrentDirectory
78+ TextResult . toS <$> liftIO getCurrentDirectory
90handleCommand Reset = resetIdeState *> pure (TextResult "State has been reset.")
79handleCommand Reset = resetIdeState *> pure (TextResult "State has been reset.")
91handleCommand Quit = liftIO exitSuccess
80handleCommand Quit = liftIO exitSuccess
92
81
@@ -127,7 +116,7 @@ listAvailableModules = do
127 liftIO $ do
116 liftIO $ do
128 contents <- getDirectoryContents oDir
117 contents <- getDirectoryContents oDir
129 let cleaned = filter (`notElem` [".", ".."]) contents
118 let cleaned = filter (`notElem` [".", ".."]) contents
130− return (ModuleList (map T.pack cleaned))
119+ return (ModuleList (map toS cleaned))
131
120
132caseSplit :: (Ide m, MonadError PscIdeError m) =>
121caseSplit :: (Ide m, MonadError PscIdeError m) =>
133 Text -> Int -> Int -> CS.WildcardAnnotations -> Text -> m Success
122 Text -> Int -> Int -> CS.WildcardAnnotations -> Text -> m Success
src/Language/PureScript/Ide/CaseSplit.hs+14−21
@@ -23,14 +23,8 @@ module Language.PureScript.Ide.CaseSplit
23 , caseSplit
23 , caseSplit
24 ) where
24 ) where
25
25
26−import Prelude ()
26+import Protolude hiding (Constructor)
27−import Prelude.Compat hiding (lex)
27+
28−
29−import Control.Arrow (second)
30−import Control.Monad.Error.Class
31−import Data.List (find)
32−import Data.Monoid
33−import Data.Text (Text)
34import qualified Data.Text as T
28import qualified Data.Text as T
35import qualified Language.PureScript as P
29import qualified Language.PureScript as P
36
30
@@ -56,7 +50,7 @@ noAnnotations = WildcardAnnotations False
56caseSplit :: (Ide m, MonadError PscIdeError m) =>
50caseSplit :: (Ide m, MonadError PscIdeError m) =>
57 Text -> m [Constructor]
51 Text -> m [Constructor]
58caseSplit q = do
52caseSplit q = do
59− type' <- parseType' (T.unpack q)
53+ type' <- parseType' q
60 (tc, args) <- splitTypeConstructor type'
54 (tc, args) <- splitTypeConstructor type'
61 (EDType _ _ (P.DataType typeVars ctors)) <- findTypeDeclaration tc
55 (EDType _ _ (P.DataType typeVars ctors)) <- findTypeDeclaration tc
62 let applyTypeVars = P.everywhereOnTypes (P.replaceAllTypeVars (zip (map fst typeVars) args))
56 let applyTypeVars = P.everywhereOnTypes (P.replaceAllTypeVars (zip (map fst typeVars) args))
@@ -115,26 +109,26 @@ makePattern t x y wsa = makePattern' (T.take x t) (T.drop y t)
115
109
116addClause :: (MonadError PscIdeError m) => Text -> WildcardAnnotations -> m [Text]
110addClause :: (MonadError PscIdeError m) => Text -> WildcardAnnotations -> m [Text]
117addClause s wca = do
111addClause s wca = do
118− (fName, fType) <- parseTypeDeclaration' (T.unpack s)
112+ (fName, fType) <- parseTypeDeclaration' s
119− let (args, _) = splitFunctionType fType
113+ let args = splitFunctionType fType
120 template = runIdentT fName <> " " <>
114 template = runIdentT fName <> " " <>
121 T.unwords (map (prettyPrintWildcard wca) args) <>
115 T.unwords (map (prettyPrintWildcard wca) args) <>
122 " = ?" <> (T.strip . runIdentT $ fName)
116 " = ?" <> (T.strip . runIdentT $ fName)
123 pure [s, template]
117 pure [s, template]
124
118
125parseType' :: (MonadError PscIdeError m) =>
119parseType' :: (MonadError PscIdeError m) =>
126− String -> m P.Type
120+ Text -> m P.Type
127parseType' s =
121parseType' s =
128− case P.lex "<psc-ide>" s >>= P.runTokenParser "<psc-ide>" (P.parseType <* Parsec.eof) of
122+ case P.lex "<psc-ide>" (toS s) >>= P.runTokenParser "<psc-ide>" (P.parseType <* Parsec.eof) of
129 Right type' -> pure type'
123 Right type' -> pure type'
130 Left err ->
124 Left err ->
131 throwError (GeneralError ("Parsing the splittype failed with:"
125 throwError (GeneralError ("Parsing the splittype failed with:"
132− ++ show err))
126+ <> show err))
133
127
134−parseTypeDeclaration' :: (MonadError PscIdeError m) => String -> m (P.Ident, P.Type)
128+parseTypeDeclaration' :: (MonadError PscIdeError m) => Text -> m (P.Ident, P.Type)
135parseTypeDeclaration' s =
129parseTypeDeclaration' s =
136 let x = do
130 let x = do
137− ts <- P.lex "" s
131+ ts <- P.lex "" (toS s)
138 P.runTokenParser "" (P.parseDeclaration <* Parsec.eof) ts
132 P.runTokenParser "" (P.parseDeclaration <* Parsec.eof) ts
139 in
133 in
140 case unwrapPositioned <$> x of
134 case unwrapPositioned <$> x of
@@ -142,13 +136,12 @@ parseTypeDeclaration' s =
142 Right _ -> throwError (GeneralError "Found a non-type-declaration")
136 Right _ -> throwError (GeneralError "Found a non-type-declaration")
143 Left err ->
137 Left err ->
144 throwError (GeneralError ("Parsing the typesignature failed with: "
138 throwError (GeneralError ("Parsing the typesignature failed with: "
145− ++ show err))
139+ <> show err))
146
140
147−splitFunctionType :: P.Type -> ([P.Type], P.Type)
141+splitFunctionType :: P.Type -> [P.Type]
148−splitFunctionType t = (arguments, returns)
142+splitFunctionType t = fromMaybe [] arguments
149 where
143 where
150− returns = last splitted
151− arguments = init splitted
144+ arguments = initMay splitted
152 splitted = splitType' t
145 splitted = splitType' t
153 splitType' (P.ForAll _ t' _) = splitType' t'
146 splitType' (P.ForAll _ t' _) = splitType' t'
154 splitType' (P.ConstrainedType _ t') = splitType' t'
147 splitType' (P.ConstrainedType _ t') = splitType' t'
src/Language/PureScript/Ide/Command.hs+5−7
@@ -16,17 +16,15 @@
16
16
17module Language.PureScript.Ide.Command where
17module Language.PureScript.Ide.Command where
18
18
19−import Prelude ()
19+import Protolude
20−import Prelude.Compat
21
20
22−import Control.Monad
23import Data.Aeson
21import Data.Aeson
24−import Data.Text (Text)
25import qualified Language.PureScript as P
22import qualified Language.PureScript as P
26import Language.PureScript.Ide.CaseSplit
23import Language.PureScript.Ide.CaseSplit
27import Language.PureScript.Ide.Filter
24import Language.PureScript.Ide.Filter
28import Language.PureScript.Ide.Matcher
25import Language.PureScript.Ide.Matcher
29import Language.PureScript.Ide.Types
26import Language.PureScript.Ide.Types
27+import System.FilePath
30
28
31data Command
29data Command
32 = Load [P.ModuleName]
30 = Load [P.ModuleName]
@@ -70,7 +68,7 @@ data ImportCommand
70
68
71instance FromJSON ImportCommand where
69instance FromJSON ImportCommand where
72 parseJSON = withObject "ImportCommand" $ \o -> do
70 parseJSON = withObject "ImportCommand" $ \o -> do
73− (command :: String) <- o .: "importCommand"
71+ (command :: Text) <- o .: "importCommand"
74 case command of
72 case command of
75 "addImplicitImport" ->
73 "addImplicitImport" ->
76 AddImplicitImport <$> (P.moduleNameFromString <$> o .: "module")
74 AddImplicitImport <$> (P.moduleNameFromString <$> o .: "module")
@@ -82,7 +80,7 @@ data ListType = LoadedModules | Imports FilePath | AvailableModules
82
80
83instance FromJSON ListType where
81instance FromJSON ListType where
84 parseJSON = withObject "ListType" $ \o -> do
82 parseJSON = withObject "ListType" $ \o -> do
85− (listType' :: String) <- o .: "type"
83+ (listType' :: Text) <- o .: "type"
86 case listType' of
84 case listType' of
87 "import" -> Imports <$> o .: "file"
85 "import" -> Imports <$> o .: "file"
88 "loadedModules" -> pure LoadedModules
86 "loadedModules" -> pure LoadedModules
@@ -91,7 +89,7 @@ instance FromJSON ListType where
91
89
92instance FromJSON Command where
90instance FromJSON Command where
93 parseJSON = withObject "command" $ \o -> do
91 parseJSON = withObject "command" $ \o -> do
94− (command :: String) <- o .: "command"
92+ (command :: Text) <- o .: "command"
95 case command of
93 case command of
96 "list" -> List <$> o .:? "params" .!= LoadedModules
94 "list" -> List <$> o .:? "params" .!= LoadedModules
97 "cwd" -> pure Cwd
95 "cwd" -> pure Cwd
src/Language/PureScript/Ide/Completion.hs+6−8
@@ -1,12 +1,11 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Language.PureScript.Ide.Completion
2module Language.PureScript.Ide.Completion
3+ ( getCompletions
3− (getCompletions, getExactMatches)
4+ , getExactMatches
4− where
5+ ) where
5
6
6−import Prelude ()
7+import Protolude
7−import Prelude.Compat
8
8
9−import Data.Text (Text)
10import Language.PureScript.Ide.Filter
9import Language.PureScript.Ide.Filter
11import Language.PureScript.Ide.Matcher
10import Language.PureScript.Ide.Matcher
12import Language.PureScript.Ide.Types
11import Language.PureScript.Ide.Types
@@ -15,12 +14,11 @@ import Language.PureScript.Ide.Types
15-- and sorts the found Completions according to the Matching Score
14-- and sorts the found Completions according to the Matching Score
16getCompletions :: [Filter] -> Matcher -> [Module] -> [Match]
15getCompletions :: [Filter] -> Matcher -> [Module] -> [Match]
17getCompletions filters matcher modules =
16getCompletions filters matcher modules =
18− runMatcher matcher $ completionsFromModules (applyFilters filters modules)
17+ runMatcher matcher (completionsFromModules (applyFilters filters modules))
19
18
20getExactMatches :: Text -> [Filter] -> [Module] -> [Match]
19getExactMatches :: Text -> [Filter] -> [Module] -> [Match]
21getExactMatches search filters modules =
20getExactMatches search filters modules =
22− completionsFromModules $
23− applyFilters (equalityFilter search : filters) modules
21+ completionsFromModules (applyFilters (equalityFilter search : filters) modules)
24
22
25completionsFromModules :: [Module] -> [Match]
23completionsFromModules :: [Module] -> [Match]
26completionsFromModules = foldMap completionFromModule
24completionsFromModules = foldMap completionFromModule
src/Language/PureScript/Ide/Conversions.hs+7−8
@@ -14,23 +14,22 @@
14
14
15module Language.PureScript.Ide.Conversions where
15module Language.PureScript.Ide.Conversions where
16
16
17−import Prelude.Compat
17+import Protolude
18−import Data.Text (Text)
18+import Data.Text (unwords, lines, strip)
19−import qualified Data.Text as T
20import qualified Language.PureScript as P
19import qualified Language.PureScript as P
21
20
22runProperNameT :: P.ProperName a -> Text
21runProperNameT :: P.ProperName a -> Text
23−runProperNameT = T.pack . P.runProperName
22+runProperNameT = toS . P.runProperName
24
23
25runIdentT :: P.Ident -> Text
24runIdentT :: P.Ident -> Text
26−runIdentT = T.pack . P.runIdent
25+runIdentT = toS . P.runIdent
27
26
28runOpNameT :: P.OpName a -> Text
27runOpNameT :: P.OpName a -> Text
29−runOpNameT = T.pack . P.runOpName
28+runOpNameT = toS . P.runOpName
30
29
31runModuleNameT :: P.ModuleName -> Text
30runModuleNameT :: P.ModuleName -> Text
32−runModuleNameT = T.pack . P.runModuleName
31+runModuleNameT = toS . P.runModuleName
33
32
34prettyTypeT :: P.Type -> Text
33prettyTypeT :: P.Type -> Text
35−prettyTypeT = T.unwords . fmap T.strip . T.lines . T.pack . P.prettyPrintType
34+prettyTypeT = unwords . map strip . lines . toS . P.prettyPrintType
36
35
src/Language/PureScript/Ide/Error.hs+9−12
@@ -14,25 +14,22 @@
14
14
15{-# LANGUAGE OverloadedStrings #-}
15{-# LANGUAGE OverloadedStrings #-}
16module Language.PureScript.Ide.Error
16module Language.PureScript.Ide.Error
17− (ErrorMsg, PscIdeError(..), textError)
17+ ( PscIdeError(..)
18+ , textError
18− where
19+ ) where
19
20
20−import Prelude.Compat
21+import Protolude
21import Data.Aeson
22import Data.Aeson
22−import Data.Monoid
23−import Data.Text (Text, pack)
24import Language.PureScript.Errors.JSON
23import Language.PureScript.Errors.JSON
25import Language.PureScript.Ide.Types (ModuleIdent)
24import Language.PureScript.Ide.Types (ModuleIdent)
26import qualified Text.Parsec.Error as P
25import qualified Text.Parsec.Error as P
27
26
28−type ErrorMsg = String
29−
30data PscIdeError
27data PscIdeError
31− = GeneralError ErrorMsg
28+ = GeneralError Text
32 | NotFound Text
29 | NotFound Text
33 | ModuleNotFound ModuleIdent
30 | ModuleNotFound ModuleIdent
34 | ModuleFileNotFound ModuleIdent
31 | ModuleFileNotFound ModuleIdent
35− | ParseError P.ParseError ErrorMsg
32+ | ParseError P.ParseError Text
36 | RebuildError [JSONError]
33 | RebuildError [JSONError]
37
34
38instance ToJSON PscIdeError where
35instance ToJSON PscIdeError where
@@ -46,7 +43,7 @@ instance ToJSON PscIdeError where
46 ]
43 ]
47
44
48textError :: PscIdeError -> Text
45textError :: PscIdeError -> Text
49−textError (GeneralError msg) = pack msg
46+textError (GeneralError msg) = msg
50textError (NotFound ident) = "Symbol '" <> ident <> "' not found."
47textError (NotFound ident) = "Symbol '" <> ident <> "' not found."
51textError (ModuleNotFound ident) = "Module '" <> ident <> "' not found."
48textError (ModuleNotFound ident) = "Module '" <> ident <> "' not found."
52textError (ModuleFileNotFound ident) = "Extern file for module " <> ident <>" could not be found"
49textError (ModuleFileNotFound ident) = "Extern file for module " <> ident <>" could not be found"
@@ -54,5 +51,5 @@ textError (ParseError parseError msg) = let escape = show
54 -- escape newlines and other special
51 -- escape newlines and other special
55 -- chars so we can send the error
52 -- chars so we can send the error
56 -- over the socket as a single line
53 -- over the socket as a single line
57− in pack $ msg <> ": " <> show (escape parseError)
54+ in msg <> ": " <> escape parseError
58−textError (RebuildError err) = pack (show err)
55+textError (RebuildError err) = show err
src/Language/PureScript/Ide/Externs.hs+8−16
@@ -26,17 +26,10 @@ module Language.PureScript.Ide.Externs
26 unwrapPositionedRef
26 unwrapPositionedRef
27 ) where
27 ) where
28
28
29−import Prelude ()
29+import Protolude
30−import Prelude.Compat
31
30
32−import Control.Monad.Error.Class
33−import Control.Monad.IO.Class
34import Data.Aeson (decodeStrict)
31import Data.Aeson (decodeStrict)
35import Data.List (nub)
32import Data.List (nub)
36−import Data.Maybe (mapMaybe)
37−import Data.Monoid
38−import Data.Text (Text)
39−import qualified Data.Text as T
40import qualified Data.ByteString as BS
33import qualified Data.ByteString as BS
41import Language.PureScript.Ide.Error (PscIdeError (..))
34import Language.PureScript.Ide.Error (PscIdeError (..))
42import Language.PureScript.Ide.Types
35import Language.PureScript.Ide.Types
@@ -44,17 +37,16 @@ import Language.PureScript.Ide.Util
44
37
45import qualified Language.PureScript as P
38import qualified Language.PureScript as P
46
39
40+import System.FilePath
41+
47readExternFile :: (MonadIO m, MonadError PscIdeError m) =>
42readExternFile :: (MonadIO m, MonadError PscIdeError m) =>
48 FilePath -> m P.ExternsFile
43 FilePath -> m P.ExternsFile
49readExternFile fp = do
44readExternFile fp = do
50 parseResult <- liftIO (decodeStrict <$> BS.readFile fp)
45 parseResult <- liftIO (decodeStrict <$> BS.readFile fp)
51 case parseResult of
46 case parseResult of
52− Nothing -> throwError . GeneralError $ "Parsing the extern at: " ++ fp ++ " failed"
47+ Nothing -> throwError . GeneralError $ "Parsing the extern at: " <> toS fp <> " failed"
53 Just externs -> pure externs
48 Just externs -> pure externs
54
49
55−identToText :: P.Ident -> Text
56−identToText = T.pack . P.runIdent
57−
58convertExterns :: P.ExternsFile -> ModuleOld
50convertExterns :: P.ExternsFile -> ModuleOld
59convertExterns ef = (runModuleNameT moduleName, exportDecls ++ importDecls ++ decls ++ operatorDecls ++ tyOperatorDecls)
51convertExterns ef = (runModuleNameT moduleName, exportDecls ++ importDecls ++ decls ++ operatorDecls ++ tyOperatorDecls)
60 where
52 where
@@ -96,7 +88,7 @@ convertDecl P.EDTypeSynonym{..} = Just $
96convertDecl P.EDDataConstructor{..} = Just $
88convertDecl P.EDDataConstructor{..} = Just $
97 DataConstructor (runProperNameT edDataCtorName) edDataCtorTypeCtor edDataCtorType
89 DataConstructor (runProperNameT edDataCtorName) edDataCtorTypeCtor edDataCtorType
98convertDecl P.EDValue{..} = Just $
90convertDecl P.EDValue{..} = Just $
99− ValueDeclaration (identToText edValueName) edValueType
91+ ValueDeclaration (runIdentT edValueName) edValueType
100convertDecl P.EDClass{..} = Just $ TypeClassDeclaration edClassName
92convertDecl P.EDClass{..} = Just $ TypeClassDeclaration edClassName
101convertDecl P.EDInstance{} = Nothing
93convertDecl P.EDInstance{} = Nothing
102
94
@@ -104,7 +96,7 @@ convertOperator :: P.ExternsFixity -> ExternDecl
104convertOperator P.ExternsFixity{..} =
96convertOperator P.ExternsFixity{..} =
105 ValueOperator
97 ValueOperator
106 efOperator
98 efOperator
107− (T.pack (P.showQualified (either P.runIdent P.runProperName) efAlias))
99+ (toS (P.showQualified (either P.runIdent P.runProperName) efAlias))
108 efPrecedence
100 efPrecedence
109 efAssociativity
101 efAssociativity
110
102
@@ -112,7 +104,7 @@ convertTypeOperator :: P.ExternsTypeFixity -> ExternDecl
112convertTypeOperator P.ExternsTypeFixity{..} =
104convertTypeOperator P.ExternsTypeFixity{..} =
113 TypeOperator
105 TypeOperator
114 efTypeOperator
106 efTypeOperator
115− (T.pack (P.showQualified P.runProperName efTypeAlias))
107+ (toS (P.showQualified P.runProperName efTypeAlias))
116 efTypePrecedence
108 efTypePrecedence
117 efTypeAssociativity
109 efTypeAssociativity
118
110
@@ -125,7 +117,7 @@ unwrapPositionedRef (P.PositionedDeclarationRef _ _ x) = x
125unwrapPositionedRef x = x
117unwrapPositionedRef x = x
126
118
127convertModule :: ModuleOld -> Module
119convertModule :: ModuleOld -> Module
128−convertModule (mn, decls) = (P.moduleNameFromString (T.unpack mn), mapMaybe convertDeclaration decls)
120+convertModule (mn, decls) = (P.moduleNameFromString (toS mn), mapMaybe convertDeclaration decls)
129 where convertDeclaration :: ExternDecl -> Maybe IdeDeclaration
121 where convertDeclaration :: ExternDecl -> Maybe IdeDeclaration
130 convertDeclaration d = case d of
122 convertDeclaration d = case d of
131 ValueDeclaration i t -> Just (IdeValue i t)
123 ValueDeclaration i t -> Just (IdeValue i t)
src/Language/PureScript/Ide/Filter.hs+4−8
@@ -24,14 +24,10 @@ module Language.PureScript.Ide.Filter
24 , applyFilters
24 , applyFilters
25 ) where
25 ) where
26
26
27−import Prelude ()
27+import Protolude hiding (isPrefixOf)
28−import Prelude.Compat
29
28
30−import Control.Monad
31import Data.Aeson
29import Data.Aeson
32−import Data.Foldable
33−import Data.Monoid
34−import Data.Text (Text, isPrefixOf)
30+import Data.Text (isPrefixOf)
35import Language.PureScript.Ide.Types
31import Language.PureScript.Ide.Types
36import Language.PureScript.Ide.Util
32import Language.PureScript.Ide.Util
37import qualified Language.PureScript as P
33import qualified Language.PureScript as P
@@ -51,7 +47,7 @@ moduleFilter' moduleIdents = filter (flip elem moduleIdents . fst)
51
47
52-- | Only keeps Identifiers that start with the given prefix
48-- | Only keeps Identifiers that start with the given prefix
53prefixFilter :: Text -> Filter
49prefixFilter :: Text -> Filter
54−prefixFilter "" = mkFilter id
50+prefixFilter "" = mkFilter identity
55prefixFilter t = mkFilter $ identFilter prefix t
51prefixFilter t = mkFilter $ identFilter prefix t
56 where
52 where
57 prefix :: IdeDeclaration -> Text -> Bool
53 prefix :: IdeDeclaration -> Text -> Bool
@@ -80,7 +76,7 @@ applyFilters = runFilter . fold
80
76
81instance FromJSON Filter where
77instance FromJSON Filter where
82 parseJSON = withObject "filter" $ \o -> do
78 parseJSON = withObject "filter" $ \o -> do
83− (filter' :: String) <- o .: "filter"
79+ (filter' :: Text) <- o .: "filter"
84 case filter' of
80 case filter' of
85 "exact" -> do
81 "exact" -> do
86 params <- o .: "params"
82 params <- o .: "params"
src/Language/PureScript/Ide/Imports.hs+13−20
@@ -29,17 +29,9 @@ module Language.PureScript.Ide.Imports
29 )
29 )
30 where
30 where
31
31
32−import Prelude.Compat
32+import Protolude
33−import Control.Applicative ((<|>))
34−import Control.Monad.Error.Class
35−import Control.Monad.IO.Class
36−import Data.Bifunctor (first, second)
37−import Data.Function (on)
38−import qualified Data.List as List
39−import Data.Maybe (isNothing)
40−import Data.Monoid ((<>))
41−import Data.Text (Text)
42import qualified Data.Text as T
33import qualified Data.Text as T
34+import Data.List (nubBy, findIndex)
43import qualified Data.Text.IO as TIO
35import qualified Data.Text.IO as TIO
44import qualified Language.PureScript as P
36import qualified Language.PureScript as P
45import Language.PureScript.Ide.Completion
37import Language.PureScript.Ide.Completion
@@ -50,6 +42,7 @@ import Language.PureScript.Ide.Filter
50import Language.PureScript.Ide.State
42import Language.PureScript.Ide.State
51import Language.PureScript.Ide.Types
43import Language.PureScript.Ide.Types
52import Language.PureScript.Ide.Util
44import Language.PureScript.Ide.Util
45+import System.FilePath
53
46
54data Import = Import P.ModuleName P.ImportDeclarationType (Maybe P.ModuleName)
47data Import = Import P.ModuleName P.ImportDeclarationType (Maybe P.ModuleName)
55 deriving (Eq, Show)
48 deriving (Eq, Show)
@@ -85,7 +78,7 @@ parseImportsFromFile fp = do
85 Right res -> pure res
78 Right res -> pure res
86 Left err -> throwError (GeneralError err)
79 Left err -> throwError (GeneralError err)
87
80
88−parseImportsWithModuleName :: [Text] -> Either String (P.ModuleName, [Import])
81+parseImportsWithModuleName :: [Text] -> Either Text (P.ModuleName, [Import])
89parseImportsWithModuleName ls = do
82parseImportsWithModuleName ls = do
90 (P.Module _ _ mn decls _) <- moduleParse ls
83 (P.Module _ _ mn decls _) <- moduleParse ls
91 pure (mn, concatMap mkImport (unwrapPositioned <$> decls))
84 pure (mn, concatMap mkImport (unwrapPositioned <$> decls))
@@ -95,13 +88,13 @@ parseImportsWithModuleName ls = do
95 mkImport (P.ImportDeclaration mn it qual) = [Import mn it qual]
88 mkImport (P.ImportDeclaration mn it qual) = [Import mn it qual]
96 mkImport _ = []
89 mkImport _ = []
97
90
98−sliceImportSection :: [Text] -> Either String (P.ModuleName, [Text], [Import], [Text])
91+sliceImportSection :: [Text] -> Either Text (P.ModuleName, [Text], [Import], [Text])
99sliceImportSection ts =
92sliceImportSection ts =
100 case foldl step (ModuleHeader 0) (zip [0..] ts) of
93 case foldl step (ModuleHeader 0) (zip [0..] ts) of
101 Res start end ->
94 Res start end ->
102 let
95 let
103 (moduleHeader, (importSection, remainingFile)) =
96 (moduleHeader, (importSection, remainingFile)) =
104− List.splitAt (succ (end - start)) `second` List.splitAt start ts
97+ splitAt (succ (end - start)) `second` splitAt start ts
105 in
98 in
106 (\(mn, is) -> (mn, moduleHeader, is, remainingFile)) <$>
99 (\(mn, is) -> (mn, moduleHeader, is, remainingFile)) <$>
107 parseImportsWithModuleName (moduleHeader <> importSection)
100 parseImportsWithModuleName (moduleHeader <> importSection)
@@ -109,7 +102,7 @@ sliceImportSection ts =
109 -- If we don't find any imports, we insert a newline after the module
102 -- If we don't find any imports, we insert a newline after the module
110 -- declaration and begin a new importsection
103 -- declaration and begin a new importsection
111 ModuleHeader ix ->
104 ModuleHeader ix ->
112− let (moduleHeader, remainingFile) = List.splitAt (succ ix) ts
105+ let (moduleHeader, remainingFile) = splitAt (succ ix) ts
113 in
106 in
114 (\(mn, is) -> (mn, moduleHeader ++ [""], is, remainingFile)) <$>
107 (\(mn, is) -> (mn, moduleHeader ++ [""], is, remainingFile)) <$>
115 parseImportsWithModuleName moduleHeader
108 parseImportsWithModuleName moduleHeader
@@ -151,7 +144,7 @@ step (ImportSection start lastImportLine) (ix, l)
151 | otherwise = Res start lastImportLine
144 | otherwise = Res start lastImportLine
152step (Res start end) _ = Res start end
145step (Res start end) _ = Res start end
153
146
154−moduleParse :: [Text] -> Either String P.Module
147+moduleParse :: [Text] -> Either Text P.Module
155moduleParse t = first show $ do
148moduleParse t = first show $ do
156 tokens <- (P.lex "" . T.unpack . T.unlines) t
149 tokens <- (P.lex "" . T.unpack . T.unlines) t
157 P.runTokenParser "<psc-ide>" P.parseModule tokens
150 P.runTokenParser "<psc-ide>" P.parseModule tokens
@@ -233,11 +226,11 @@ addExplicitImport' decl moduleName imports =
233 dtor' = P.ProperName (T.unpack dtor)
226 dtor' = P.ProperName (T.unpack dtor)
234 in
227 in
235 updateAtFirstOrPrepend (matchType tn) (insertDtor dtor') (P.TypeRef tn (Just [dtor'])) refs
228 updateAtFirstOrPrepend (matchType tn) (insertDtor dtor') (P.TypeRef tn (Just [dtor'])) refs
236− insertDeclIntoRefs dr refs = List.nubBy ((==) `on` P.prettyPrintRef) (refFromDeclaration dr : refs)
229+ insertDeclIntoRefs dr refs = nubBy ((==) `on` P.prettyPrintRef) (refFromDeclaration dr : refs)
237
230
238 insertDtor dtor (P.TypeRef tn' dtors) =
231 insertDtor dtor (P.TypeRef tn' dtors) =
239 case dtors of
232 case dtors of
240− Just dtors' -> P.TypeRef tn' (Just (List.nub (dtor : dtors')))
233+ Just dtors' -> P.TypeRef tn' (Just (ordNub (dtor : dtors')))
241 -- This means the import was opened. We don't add anything in this case
234 -- This means the import was opened. We don't add anything in this case
242 -- import Data.Maybe (Maybe(..)) -> import Data.Maybe (Maybe(Just))
235 -- import Data.Maybe (Maybe(..)) -> import Data.Maybe (Maybe(Just))
243 Nothing -> P.TypeRef tn' Nothing
236 Nothing -> P.TypeRef tn' Nothing
@@ -249,10 +242,10 @@ addExplicitImport' decl moduleName imports =
249
242
250updateAtFirstOrPrepend :: (a -> Bool) -> (a -> a) -> a -> [a] -> [a]
243updateAtFirstOrPrepend :: (a -> Bool) -> (a -> a) -> a -> [a] -> [a]
251updateAtFirstOrPrepend p t d l =
244updateAtFirstOrPrepend p t d l =
252− case List.findIndex p l of
245+ case findIndex p l of
253 Nothing -> d : l
246 Nothing -> d : l
254 Just ix ->
247 Just ix ->
255− let (x, a : y) = List.splitAt ix l
248+ let (x, a : y) = splitAt ix l
256 in x ++ [t a] ++ y
249 in x ++ [t a] ++ y
257
250
258-- | Looks up the given identifier in the currently loaded modules.
251-- | Looks up the given identifier in the currently loaded modules.
@@ -321,7 +314,7 @@ prettyPrintImport' (Import mn idt qual) =
321 T.pack $ "import " ++ P.prettyPrintImport mn idt qual
314 T.pack $ "import " ++ P.prettyPrintImport mn idt qual
322
315
323prettyPrintImportSection :: [Import] -> [Text]
316prettyPrintImportSection :: [Import] -> [Text]
324−prettyPrintImportSection imports = map prettyPrintImport' (List.sort imports)
317+prettyPrintImportSection imports = map prettyPrintImport' (sort imports)
325
318
326-- | Writes a list of lines to @Just filepath@ and responds with a @TextResult@,
319-- | Writes a list of lines to @Just filepath@ and responds with a @TextResult@,
327-- or returns the lines as a @MultilineTextResult@ if @Nothing@ was given as the
320-- or returns the lines as a @MultilineTextResult@ if @Nothing@ was given as the
src/Language/PureScript/Ide/Matcher.hs+5−12
@@ -21,16 +21,9 @@ module Language.PureScript.Ide.Matcher
21 , runMatcher
21 , runMatcher
22 ) where
22 ) where
23
23
24−import Prelude ()
24+import Protolude
25−import Prelude.Compat
26
25
27−import Control.Monad
28import Data.Aeson
26import Data.Aeson
29−import Data.Function (on)
30−import Data.List (sortBy)
31−import Data.Maybe (mapMaybe)
32−import Data.Monoid
33−import Data.Text (Text)
34import qualified Data.Text as T
27import qualified Data.Text as T
35import qualified Data.Text.Encoding as TE
28import qualified Data.Text.Encoding as TE
36import Language.PureScript.Ide.Types
29import Language.PureScript.Ide.Types
@@ -45,7 +38,7 @@ newtype Matcher = Matcher (Endo [Match]) deriving (Monoid)
45
38
46instance FromJSON Matcher where
39instance FromJSON Matcher where
47 parseJSON = withObject "matcher" $ \o -> do
40 parseJSON = withObject "matcher" $ \o -> do
48− (matcher :: Maybe String) <- o .:? "matcher"
41+ (matcher :: Maybe Text) <- o .:? "matcher"
49 case matcher of
42 case matcher of
50 Just "flex" -> do
43 Just "flex" -> do
51 params <- o .: "params"
44 params <- o .: "params"
@@ -109,7 +102,7 @@ flexScore :: Text -> Text -> Maybe Double
109flexScore pat str =
102flexScore pat str =
110 case T.uncons pat of
103 case T.uncons pat of
111 Nothing -> Nothing
104 Nothing -> Nothing
112− Just (first, p) ->
105+ Just (first', p) ->
113 case TE.encodeUtf8 str =~ TE.encodeUtf8 pat' :: (Int, Int) of
106 case TE.encodeUtf8 str =~ TE.encodeUtf8 pat' :: (Int, Int) of
114 (-1,0) -> Nothing
107 (-1,0) -> Nothing
115 (start,len) -> Just $ calcScore start (start + len)
108 (start,len) -> Just $ calcScore start (start + len)
@@ -120,11 +113,11 @@ flexScore pat str =
120 -- escape prepends a backslash to "regexy" characters to prevent the
113 -- escape prepends a backslash to "regexy" characters to prevent the
121 -- matcher from crashing when trying to build the regex
114 -- matcher from crashing when trying to build the regex
122 escape :: Char -> Text
115 escape :: Char -> Text
123− escape c = if c `elem` ("[\\^$.|?*+(){}" :: String)
116+ escape c = if c `elem` T.unpack "[\\^$.|?*+(){}"
124 then T.pack ['\\', c]
117 then T.pack ['\\', c]
125 else T.singleton c
118 else T.singleton c
126 -- This just interleaves the search pattern with .*
119 -- This just interleaves the search pattern with .*
127 -- abcd[*] -> a.*b.*c.*d.*[*]
120 -- abcd[*] -> a.*b.*c.*d.*[*]
128− pat' = escape first <> foldMap (<> ".*") escapedPattern
121+ pat' = escape first' <> foldMap (<> ".*") escapedPattern
129 calcScore start end =
122 calcScore start end =
130 100.0 / fromIntegral ((1 + start) * (end - start + 1))
123 100.0 / fromIntegral ((1 + start) * (end - start + 1))
src/Language/PureScript/Ide/Pursuit.hs+5−11
@@ -16,18 +16,12 @@
16
16
17module Language.PureScript.Ide.Pursuit where
17module Language.PureScript.Ide.Pursuit where
18
18
19−import Prelude ()
19+import Protolude
20−import Prelude.Compat
21
20
22import qualified Control.Exception as E
21import qualified Control.Exception as E
23import Data.Aeson
22import Data.Aeson
24−import Data.ByteString (ByteString)
25import Data.ByteString.Lazy (fromStrict)
23import Data.ByteString.Lazy (fromStrict)
26−import Data.Foldable (toList)
27−import Data.Maybe (mapMaybe)
28−import Data.Monoid ((<>))
29import Data.String
24import Data.String
30−import Data.Text (Text)
31import qualified Data.Text as T
25import qualified Data.Text as T
32import Language.PureScript.Ide.Types
26import Language.PureScript.Ide.Types
33import Network.HTTP.Types.Header (hAccept)
27import Network.HTTP.Types.Header (hAccept)
@@ -41,12 +35,12 @@ queryPursuit q = do
41 let qClean = T.dropWhileEnd (== '.') q
35 let qClean = T.dropWhileEnd (== '.') q
42 req' <- parseUrl "http://pursuit.purescript.org/search"
36 req' <- parseUrl "http://pursuit.purescript.org/search"
43 let req = req'
37 let req = req'
44− { queryString=("q=" <> (fromString . T.unpack) qClean)
38+ { queryString= "q=" <> (fromString . T.unpack) qClean
45 , requestHeaders=[(hAccept, "application/json")]
39 , requestHeaders=[(hAccept, "application/json")]
46 }
40 }
47 m <- newManager tlsManagerSettings
41 m <- newManager tlsManagerSettings
48 withHTTP req m $ \resp ->
42 withHTTP req m $ \resp ->
49− P.fold (<>) "" id $ responseBody resp
43+ P.fold (<>) "" identity (responseBody resp)
50
44
51
45
52handler :: HttpException -> IO [a]
46handler :: HttpException -> IO [a]
@@ -59,7 +53,7 @@ searchPursuitForDeclarations query =
59 let results' = decode (fromStrict r) :: Maybe Array
53 let results' = decode (fromStrict r) :: Maybe Array
60 case results' of
54 case results' of
61 Nothing -> pure []
55 Nothing -> pure []
62− Just results -> pure (mapMaybe isDeclarationResponse (map fromJSON (toList results)))) `E.catch`
56+ Just results -> pure (mapMaybe (isDeclarationResponse . fromJSON) (toList results))) `E.catch`
63 handler
57 handler
64 where
58 where
65 isDeclarationResponse (Success a@DeclarationResponse{}) = Just a
59 isDeclarationResponse (Success a@DeclarationResponse{}) = Just a
@@ -71,7 +65,7 @@ findPackagesForModuleIdent query =
71 let results' = decode (fromStrict r) :: Maybe Array
65 let results' = decode (fromStrict r) :: Maybe Array
72 case results' of
66 case results' of
73 Nothing -> pure []
67 Nothing -> pure []
74− Just results -> pure (mapMaybe isModuleResponse (map fromJSON (toList results)))) `E.catch`
68+ Just results -> pure (mapMaybe (isModuleResponse . fromJSON) (toList results))) `E.catch`
75 handler
69 handler
76 where
70 where
77 isModuleResponse (Success a@ModuleResponse{}) = Just a
71 isModuleResponse (Success a@ModuleResponse{}) = Just a
src/Language/PureScript/Ide/Rebuild.hs+11−13
@@ -8,14 +8,12 @@ module Language.PureScript.Ide.Rebuild
8 ( rebuildFile
8 ( rebuildFile
9 ) where
9 ) where
10
10
11−import Control.Monad.Error.Class
11+import Protolude
12−import Control.Monad.IO.Class
12+
13import "monad-logger" Control.Monad.Logger
13import "monad-logger" Control.Monad.Logger
14−import Control.Monad.Reader
14+import qualified Data.List as List
15−import Control.Monad.Trans.Except
16import qualified Data.Map.Lazy as M
15import qualified Data.Map.Lazy as M
17−import Data.Maybe (fromJust, mapMaybe)
16+import Data.Maybe (fromJust)
18−import Data.Monoid ((<>))
19import qualified Data.Set as S
17import qualified Data.Set as S
20import qualified Language.PureScript as P
18import qualified Language.PureScript as P
21import Language.PureScript.Errors.JSON
19import Language.PureScript.Errors.JSON
@@ -23,8 +21,8 @@ import Language.PureScript.Ide.Error
23import Language.PureScript.Ide.State
21import Language.PureScript.Ide.State
24import Language.PureScript.Ide.Types
22import Language.PureScript.Ide.Types
25import Language.PureScript.Ide.Util
23import Language.PureScript.Ide.Util
26−import Prelude.Compat
27import System.IO.UTF8 (readUTF8File)
24import System.IO.UTF8 (readUTF8File)
25+import System.FilePath
28
26
29-- | Given a filepath performs the following steps:
27-- | Given a filepath performs the following steps:
30--
28--
@@ -49,7 +47,7 @@ rebuildFile path = do
49
47
50 input <- liftIO (readUTF8File path)
48 input <- liftIO (readUTF8File path)
51
49
52− m <- case snd <$> P.parseModuleFromFile id (path, input) of
50+ m <- case snd <$> P.parseModuleFromFile identity (path, input) of
53 Left parseError -> throwError
51 Left parseError -> throwError
54 . RebuildError
52 . RebuildError
55 . toJSONErrors False P.Error
53 . toJSONErrors False P.Error
@@ -106,8 +104,8 @@ rebuildModuleOpen makeEnv externs m = do
106data MakeActionsEnv =
104data MakeActionsEnv =
107 MakeActionsEnv
105 MakeActionsEnv
108 { maeOutputDirectory :: FilePath
106 { maeOutputDirectory :: FilePath
109− , maeFilePathMap :: M.Map P.ModuleName (Either P.RebuildPolicy FilePath)
107+ , maeFilePathMap :: Map P.ModuleName (Either P.RebuildPolicy FilePath)
110− , maeForeignPathMap :: M.Map P.ModuleName FilePath
108+ , maeForeignPathMap :: Map P.ModuleName FilePath
111 , maePrefixComment :: Bool
109 , maePrefixComment :: Bool
112 }
110 }
113
111
@@ -137,7 +135,7 @@ shushCodegen ma MakeActionsEnv{..} =
137sortExterns
135sortExterns
138 :: (Ide m, MonadError PscIdeError m)
136 :: (Ide m, MonadError PscIdeError m)
139 => P.Module
137 => P.Module
140− -> M.Map P.ModuleName P.ExternsFile
138+ -> Map P.ModuleName P.ExternsFile
141 -> m [P.ExternsFile]
139 -> m [P.ExternsFile]
142sortExterns m ex = do
140sortExterns m ex = do
143 sorted' <- runExceptT
141 sorted' <- runExceptT
@@ -149,11 +147,11 @@ sortExterns m ex = do
149 case sorted' of
147 case sorted' of
150 Left _ -> throwError (GeneralError "There was a cycle in the dependencies")
148 Left _ -> throwError (GeneralError "There was a cycle in the dependencies")
151 Right (sorted, graph) -> do
149 Right (sorted, graph) -> do
152− let deps = fromJust (lookup (P.getModuleName m) graph)
150+ let deps = fromJust (List.lookup (P.getModuleName m) graph)
153 pure $ mapMaybe getExtern (deps `inOrderOf` map P.getModuleName sorted)
151 pure $ mapMaybe getExtern (deps `inOrderOf` map P.getModuleName sorted)
154 where
152 where
155 mkShallowModule P.ExternsFile{..} =
153 mkShallowModule P.ExternsFile{..} =
156− P.Module undefined [] efModuleName (map mkImport efImports) Nothing
154+ P.Module (P.internalModuleSourceSpan "<rebuild>") [] efModuleName (map mkImport efImports) Nothing
157 mkImport (P.ExternsImport mn it iq) =
155 mkImport (P.ExternsImport mn it iq) =
158 P.ImportDeclaration mn it iq
156 P.ImportDeclaration mn it iq
159 getExtern mn = M.lookup mn ex
157 getExtern mn = M.lookup mn ex
src/Language/PureScript/Ide/Reexports.hs+4−6
@@ -24,16 +24,14 @@ module Language.PureScript.Ide.Reexports
24 ) where
24 ) where
25
25
26
26
27−import Prelude ()
27+import Protolude
28−import Prelude.Compat
29
28
30import Data.List (union)
29import Data.List (union)
31−import Data.Map (Map)
32import qualified Data.Map as Map
30import qualified Data.Map as Map
33−import Data.Maybe
34import qualified Data.Text as T
31import qualified Data.Text as T
35import Language.PureScript.Ide.Types
32import Language.PureScript.Ide.Types
36import Language.PureScript.Ide.Externs
33import Language.PureScript.Ide.Externs
34+import qualified Language.PureScript as P
37
35
38getReexports :: ModuleOld -> [ExternDecl]
36getReexports :: ModuleOld -> [ExternDecl]
39getReexports (mn, decls)= concatMap getExport decls
37getReexports (mn, decls)= concatMap getExport decls
@@ -59,7 +57,7 @@ replaceExportWithAliases decls ident =
59replaceReexport :: ExternDecl -> ModuleOld -> ModuleOld -> ModuleOld
57replaceReexport :: ExternDecl -> ModuleOld -> ModuleOld -> ModuleOld
60replaceReexport e@(Export _) (m, decls) (_, newDecls) =
58replaceReexport e@(Export _) (m, decls) (_, newDecls) =
61 (m, filter (/= e) decls `union` newDecls)
59 (m, filter (/= e) decls `union` newDecls)
62−replaceReexport _ _ _ = error "Should only get Exports here."
60+replaceReexport _ _ _ = P.internalError "Should only get Exports here"
63
61
64emptyModule :: ModuleOld
62emptyModule :: ModuleOld
65emptyModule = ("Empty", [])
63emptyModule = ("Empty", [])
@@ -79,7 +77,7 @@ replaceReexports m db = result
79
77
80 go :: ModuleOld -> ExternDecl -> ModuleOld
78 go :: ModuleOld -> ExternDecl -> ModuleOld
81 go m' re@(Export name) = replaceReexport re m' (getModule name)
79 go m' re@(Export name) = replaceReexport re m' (getModule name)
82− go _ _ = error "partiality! woohoo"
80+ go _ _ = P.internalError "Should only get Exports here"
83
81
84 getModule :: ModuleIdent -> ModuleOld
82 getModule :: ModuleIdent -> ModuleOld
85 getModule name = clean res
83 getModule name = clean res
src/Language/PureScript/Ide/SourceFile.hs+34−44
@@ -16,27 +16,20 @@
16
16
17module Language.PureScript.Ide.SourceFile where
17module Language.PureScript.Ide.SourceFile where
18
18
19−import Prelude
19+import Protolude
20
20
21−import Control.Monad.Error.Class
22−import Control.Monad.IO.Class
23−import Control.Monad.Trans.Except
24−import Data.Maybe (mapMaybe)
25−import Data.Monoid
26−import qualified Data.Text as T
27−import qualified Language.PureScript.AST.Declarations as D
21+import qualified Language.PureScript as P
28−import qualified Language.PureScript.AST.SourcePos as SP
29import Language.PureScript.Ide.Error
22import Language.PureScript.Ide.Error
23+import Language.PureScript.Ide.Util
30import Language.PureScript.Ide.Externs (unwrapPositioned,
24import Language.PureScript.Ide.Externs (unwrapPositioned,
31 unwrapPositionedRef)
25 unwrapPositionedRef)
32import Language.PureScript.Ide.Types
26import Language.PureScript.Ide.Types
33−import qualified Language.PureScript.Names as N
34−import qualified Language.PureScript.Parser as P
35import System.Directory
27import System.Directory
28+import System.FilePath
36import System.IO.UTF8 (readUTF8File)
29import System.IO.UTF8 (readUTF8File)
37
30
38parseModuleFromFile :: (MonadIO m, MonadError PscIdeError m) =>
31parseModuleFromFile :: (MonadIO m, MonadError PscIdeError m) =>
39− FilePath -> m D.Module
32+ FilePath -> m P.Module
40parseModuleFromFile fp = do
33parseModuleFromFile fp = do
41 exists <- liftIO (doesFileExist fp)
34 exists <- liftIO (doesFileExist fp)
42 if exists
35 if exists
@@ -49,14 +42,14 @@ parseModuleFromFile fp = do
49
42
50-- data Module = Module SourceSpan [Comment] ModuleName [Declaration] (Maybe [DeclarationRef])
43-- data Module = Module SourceSpan [Comment] ModuleName [Declaration] (Maybe [DeclarationRef])
51
44
52−getDeclarations :: D.Module -> [D.Declaration]
45+getDeclarations :: P.Module -> [P.Declaration]
53−getDeclarations (D.Module _ _ _ declarations _) = declarations
46+getDeclarations (P.Module _ _ _ declarations _) = declarations
54
47
55−getImports :: D.Module -> [D.Declaration]
48+getImports :: P.Module -> [(P.ModuleName, P.ImportDeclarationType, Maybe P.ModuleName)]
56−getImports (D.Module _ _ _ declarations _) =
49+getImports (P.Module _ _ _ declarations _) =
57 mapMaybe isImport declarations
50 mapMaybe isImport declarations
58 where
51 where
59− isImport (D.PositionedDeclaration _ _ (i@D.ImportDeclaration{})) = Just i
52+ isImport (P.PositionedDeclaration _ _ (P.ImportDeclaration a b c)) = Just (a, b, c)
60 isImport _ = Nothing
53 isImport _ = Nothing
61
54
62getImportsForFile :: (MonadIO m, MonadError PscIdeError m) =>
55getImportsForFile :: (MonadIO m, MonadError PscIdeError m) =>
@@ -66,53 +59,50 @@ getImportsForFile fp = do
66 let imports = getImports module'
59 let imports = getImports module'
67 pure (mkModuleImport . unwrapPositionedImport <$> imports)
60 pure (mkModuleImport . unwrapPositionedImport <$> imports)
68 where
61 where
69− mkModuleImport (D.ImportDeclaration mn importType' qualifier) =
62+ mkModuleImport (mn, importType', qualifier) =
70 ModuleImport
63 ModuleImport
71− (T.pack (N.runModuleName mn))
64+ (runModuleNameT mn)
72 importType'
65 importType'
73− (T.pack . N.runModuleName <$> qualifier)
66+ (runModuleNameT <$> qualifier)
74− mkModuleImport _ = error "Shouldn't have gotten anything but Imports here"
75− unwrapPositionedImport (D.ImportDeclaration mn importType' qualifier) =
67+ unwrapPositionedImport (mn, it, q) = (mn, unwrapImportType it, q)
76− D.ImportDeclaration mn (unwrapImportType importType') qualifier
77− unwrapPositionedImport x = x
78− unwrapImportType (D.Explicit decls) = D.Explicit (map unwrapPositionedRef decls)
68+ unwrapImportType (P.Explicit decls) = P.Explicit (map unwrapPositionedRef decls)
79− unwrapImportType (D.Hiding decls) = D.Hiding (map unwrapPositionedRef decls)
69+ unwrapImportType (P.Hiding decls) = P.Hiding (map unwrapPositionedRef decls)
80− unwrapImportType D.Implicit = D.Implicit
70+ unwrapImportType P.Implicit = P.Implicit
81
71
82−getPositionedImports :: D.Module -> [D.Declaration]
72+getPositionedImports :: P.Module -> [P.Declaration]
83−getPositionedImports (D.Module _ _ _ declarations _) =
73+getPositionedImports (P.Module _ _ _ declarations _) =
84 mapMaybe isImport declarations
74 mapMaybe isImport declarations
85 where
75 where
86− isImport i@(D.PositionedDeclaration _ _ D.ImportDeclaration{}) = Just i
76+ isImport i@(P.PositionedDeclaration _ _ P.ImportDeclaration{}) = Just i
87 isImport _ = Nothing
77 isImport _ = Nothing
88
78
89−getDeclPosition :: D.Module -> String -> Maybe SP.SourceSpan
79+getDeclPosition :: P.Module -> Text -> Maybe P.SourceSpan
90getDeclPosition m ident = getFirst (foldMap (match ident) decls)
80getDeclPosition m ident = getFirst (foldMap (match ident) decls)
91 where
81 where
92 decls = getDeclarations m
82 decls = getDeclarations m
93− match q (D.PositionedDeclaration ss _ decl) = First (if go q decl
83+ match q (P.PositionedDeclaration ss _ decl) = First (if go q decl
94 then Just ss
84 then Just ss
95 else Nothing)
85 else Nothing)
96 match _ _ = First Nothing
86 match _ _ = First Nothing
97
87
98− go q (D.DataDeclaration _ name _ constructors) =
88+ go q (P.DataDeclaration _ name _ constructors) =
99 properEqual name q || any (\(x,_) -> properEqual x q) constructors
89 properEqual name q || any (\(x,_) -> properEqual x q) constructors
100− go q (D.DataBindingGroupDeclaration decls') = any (go q) decls'
90+ go q (P.DataBindingGroupDeclaration decls') = any (go q) decls'
101− go q (D.TypeSynonymDeclaration name _ _) = properEqual name q
91+ go q (P.TypeSynonymDeclaration name _ _) = properEqual name q
102− go q (D.TypeDeclaration ident' _) = identEqual ident' q
92+ go q (P.TypeDeclaration ident' _) = identEqual ident' q
103− go q (D.ValueDeclaration ident' _ _ _) = identEqual ident' q
93+ go q (P.ValueDeclaration ident' _ _ _) = identEqual ident' q
104− go q (D.ExternDeclaration ident' _) = identEqual ident' q
94+ go q (P.ExternDeclaration ident' _) = identEqual ident' q
105− go q (D.ExternDataDeclaration name _) = properEqual name q
95+ go q (P.ExternDataDeclaration name _) = properEqual name q
106− go q (D.TypeClassDeclaration name _ _ members) =
96+ go q (P.TypeClassDeclaration name _ _ members) =
107 properEqual name q || any (go q . unwrapPositioned) members
97 properEqual name q || any (go q . unwrapPositioned) members
108− go q (D.TypeInstanceDeclaration ident' _ _ _ _) =
98+ go q (P.TypeInstanceDeclaration ident' _ _ _ _) =
109 identEqual ident' q
99 identEqual ident' q
110 go _ _ = False
100 go _ _ = False
111
101
112− properEqual x q = N.runProperName x == q
102+ properEqual x q = runProperNameT x == q
113− identEqual x q = N.runIdent x == q
103+ identEqual x q = runIdentT x == q
114
104
115−goToDefinition :: String -> FilePath -> IO (Maybe SP.SourceSpan)
105+goToDefinition :: Text -> FilePath -> IO (Maybe P.SourceSpan)
116goToDefinition q fp = do
106goToDefinition q fp = do
117 m <- runExceptT (parseModuleFromFile fp)
107 m <- runExceptT (parseModuleFromFile fp)
118 case m of
108 case m of
src/Language/PureScript/Ide/State.hs+1−5
@@ -33,15 +33,11 @@ module Language.PureScript.Ide.State
33 , populateStage2STM
33 , populateStage2STM
34 ) where
34 ) where
35
35
36−import Prelude ()
36+import Protolude
37−import Prelude.Compat
38
37
39import Control.Concurrent.STM
38import Control.Concurrent.STM
40−import Control.Monad.IO.Class
41import "monad-logger" Control.Monad.Logger
39import "monad-logger" Control.Monad.Logger
42−import Control.Monad.Reader.Class
43import qualified Data.Map.Lazy as M
40import qualified Data.Map.Lazy as M
44−import Data.Monoid
45import qualified Data.Text as T
41import qualified Data.Text as T
46import Data.Time (getCurrentTime, diffUTCTime)
42import Data.Time (getCurrentTime, diffUTCTime)
47import Language.PureScript.Externs
43import Language.PureScript.Externs
src/Language/PureScript/Ide/Types.hs+10−16
@@ -16,22 +16,16 @@
16
16
17module Language.PureScript.Ide.Types where
17module Language.PureScript.Ide.Types where
18
18
19−import Prelude ()
19+import Protolude
20−import Prelude.Compat
21
20
22import Control.Concurrent.STM
21import Control.Concurrent.STM
23−import Control.Monad
24−import Control.Monad.Reader.Class
25−import Control.Monad.Trans
26import Data.Aeson
22import Data.Aeson
27import Data.Map.Lazy as M
23import Data.Map.Lazy as M
28−import Data.Maybe (maybeToList)
29−import Data.Text (Text, pack, unpack)
30import qualified Language.PureScript.Errors.JSON as P
24import qualified Language.PureScript.Errors.JSON as P
31import qualified Language.PureScript as P
25import qualified Language.PureScript as P
32import Language.PureScript.Ide.Conversions
26import Language.PureScript.Ide.Conversions
33−
27+import System.FilePath
34−import Text.Parsec
28+import Text.Parsec as Parsec
35import Text.Parsec.Text
29import Text.Parsec.Text
36
30
37type Ident = Text
31type Ident = Text
@@ -219,7 +213,7 @@ instance FromJSON PursuitResponse where
219 parseJSON (Object o) = do
213 parseJSON (Object o) = do
220 package <- o .: "package"
214 package <- o .: "package"
221 info <- o .: "info"
215 info <- o .: "info"
222− (type' :: String) <- info .: "type"
216+ (type' :: Text) <- info .: "type"
223 case type' of
217 case type' of
224 "module" -> do
218 "module" -> do
225 name <- info .: "module"
219 name <- info .: "module"
@@ -234,26 +228,26 @@ instance FromJSON PursuitResponse where
234
228
235typeParse :: Text -> Either Text (Text, Text)
229typeParse :: Text -> Either Text (Text, Text)
236typeParse t = case parse parseType "" t of
230typeParse t = case parse parseType "" t of
237− Right (x,y) -> Right (pack x, pack y)
231+ Right (x,y) -> Right (x, y)
238− Left err -> Left (pack (show err))
232+ Left err -> Left (show err)
239 where
233 where
240− parseType :: Parser (String, String)
234+ parseType :: Parser (Text, Text)
241 parseType = do
235 parseType = do
242 name <- identifier
236 name <- identifier
243 _ <- string "::"
237 _ <- string "::"
244 spaces
238 spaces
245 type' <- many1 anyChar
239 type' <- many1 anyChar
246− pure (unpack name, type')
240+ pure (name, toS type')
247
241
248 identifier :: Parser Text
242 identifier :: Parser Text
249 identifier = do
243 identifier = do
250 spaces
244 spaces
251 ident <-
245 ident <-
252 -- necessary for being able to parse the following ((++), concat)
246 -- necessary for being able to parse the following ((++), concat)
253− between (char '(') (char ')') (many1 (noneOf ", )")) <|>
247+ between (char '(') (char ')') (many1 (noneOf ", )")) Parsec.<|>
254 many1 (noneOf ", )")
248 many1 (noneOf ", )")
255 spaces
249 spaces
256− pure (pack ident)
250+ pure (toS ident)
257
251
258instance ToJSON PursuitResponse where
252instance ToJSON PursuitResponse where
259 toJSON (ModuleResponse name package) =
253 toJSON (ModuleResponse name package) =
src/Language/PureScript/Ide/Util.hs+5−12
@@ -20,16 +20,12 @@ module Language.PureScript.Ide.Util
20 , completionFromMatch
20 , completionFromMatch
21 , encodeT
21 , encodeT
22 , decodeT
22 , decodeT
23− , unlessM
24 , module Language.PureScript.Ide.Conversions
23 , module Language.PureScript.Ide.Conversions
25 ) where
24 ) where
26
25
27−import Prelude.Compat
26+import Protolude
28−import Control.Monad (unless)
29import Data.Aeson
27import Data.Aeson
30−import Data.Text (Text)
31import qualified Data.Text as T
28import qualified Data.Text as T
32−import Data.Text.Lazy (fromStrict, toStrict)
33import Data.Text.Lazy.Encoding (decodeUtf8, encodeUtf8)
29import Data.Text.Lazy.Encoding (decodeUtf8, encodeUtf8)
34import qualified Language.PureScript as P
30import qualified Language.PureScript as P
35import Language.PureScript.Ide.Types
31import Language.PureScript.Ide.Types
@@ -51,7 +47,7 @@ identifierFromMatch (Match _ ed) = identifierFromIdeDeclaration ed
51completionFromMatch :: Match -> Completion
47completionFromMatch :: Match -> Completion
52completionFromMatch (Match m' d) = case d of
48completionFromMatch (Match m' d) = case d of
53 IdeValue name type' -> Completion (m, name, prettyTypeT type')
49 IdeValue name type' -> Completion (m, name, prettyTypeT type')
54− IdeType name kind -> Completion (m, runProperNameT name, T.pack $ P.prettyPrintKind kind)
50+ IdeType name kind -> Completion (m, runProperNameT name, toS (P.prettyPrintKind kind))
55 IdeTypeSynonym name kind -> Completion (m, runProperNameT name, prettyTypeT kind)
51 IdeTypeSynonym name kind -> Completion (m, runProperNameT name, prettyTypeT kind)
56 IdeDataConstructor name _ type' -> Completion (m, name, prettyTypeT type')
52 IdeDataConstructor name _ type' -> Completion (m, name, prettyTypeT type')
57 IdeTypeClass name -> Completion (m, runProperNameT name, "class")
53 IdeTypeClass name -> Completion (m, runProperNameT name, "class")
@@ -64,13 +60,10 @@ completionFromMatch (Match m' d) = case d of
64 P.Infix -> "infix"
60 P.Infix -> "infix"
65 P.Infixl -> "infixl"
61 P.Infixl -> "infixl"
66 P.Infixr -> "infixr"
62 P.Infixr -> "infixr"
67− in T.unwords [asso, T.pack (show p), r, "as", runOpNameT o]
63+ in T.unwords [asso, show p, r, "as", runOpNameT o]
68
64
69encodeT :: (ToJSON a) => a -> Text
65encodeT :: (ToJSON a) => a -> Text
70−encodeT = toStrict . decodeUtf8 . encode
66+encodeT = toS . decodeUtf8 . encode
71
67
72decodeT :: (FromJSON a) => Text -> Maybe a
68decodeT :: (FromJSON a) => Text -> Maybe a
73−decodeT = decode . encodeUtf8 . fromStrict
69+decodeT = decode . encodeUtf8 . toS
74−
75−unlessM :: Monad m => m Bool -> m () -> m ()
76−unlessM cond act = cond >>= flip unless act
src/Language/PureScript/Ide/Watcher.hs+2−4
@@ -14,14 +14,12 @@
14
14
15module Language.PureScript.Ide.Watcher where
15module Language.PureScript.Ide.Watcher where
16
16
17−import Control.Concurrent (threadDelay)
17+import Protolude
18+
18import Control.Concurrent.STM
19import Control.Concurrent.STM
19−import Control.Monad
20−import Control.Monad.Trans.Except
21import Language.PureScript.Ide.Externs
20import Language.PureScript.Ide.Externs
22import Language.PureScript.Ide.State
21import Language.PureScript.Ide.State
23import Language.PureScript.Ide.Types
22import Language.PureScript.Ide.Types
24−import Prelude
25import System.FilePath
23import System.FilePath
26import System.FSNotify
24import System.FSNotify
27
25
tests/Language/PureScript/Ide/FilterSpec.hs+13−11
@@ -1,7 +1,8 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE NoImplicitPrelude #-}
2module Language.PureScript.Ide.FilterSpec where
3module Language.PureScript.Ide.FilterSpec where
3
4
4−import Data.Text (Text)
5+import Protolude
5import Language.PureScript.Ide.Filter
6import Language.PureScript.Ide.Filter
6import Language.PureScript.Ide.Types
7import Language.PureScript.Ide.Types
7import qualified Language.PureScript as P
8import qualified Language.PureScript as P
@@ -10,11 +11,12 @@ import Test.Hspec
10value :: Text -> IdeDeclaration
11value :: Text -> IdeDeclaration
11value s = IdeValue s $ P.TypeWildcard $ P.SourceSpan "" (P.SourcePos 0 0) (P.SourcePos 0 0)
12value s = IdeValue s $ P.TypeWildcard $ P.SourceSpan "" (P.SourcePos 0 0) (P.SourcePos 0 0)
12
13
14+moduleA, moduleB :: Module
15+moduleA = (P.moduleNameFromString "Module.A", [value "function1"])
16+moduleB = (P.moduleNameFromString "Module.B", [value "data1"])
17+
13modules :: [Module]
18modules :: [Module]
14−modules =
19+modules = [moduleA, moduleB]
15− [ (P.moduleNameFromString "Module.A", [value "function1"])
16− , (P.moduleNameFromString "Module.B", [value "data1"])
17− ]
18
20
19runEq :: Text -> [Module]
21runEq :: Text -> [Module]
20runEq s = runFilter (equalityFilter s) modules
22runEq s = runFilter (equalityFilter s) modules
@@ -31,20 +33,20 @@ spec = do
31 it "removes empty modules" $
33 it "removes empty modules" $
32 runEq "test" `shouldBe` []
34 runEq "test" `shouldBe` []
33 it "keeps function declarations that are equal" $
35 it "keeps function declarations that are equal" $
34− runEq "function1" `shouldBe` [head modules]
36+ runEq "function1" `shouldBe` [moduleA]
35 it "keeps data declarations that are equal" $
37 it "keeps data declarations that are equal" $
36− runEq "data1" `shouldBe` [modules !! 1]
38+ runEq "data1" `shouldBe` [moduleB]
37 describe "prefixFilter" $ do
39 describe "prefixFilter" $ do
38 it "keeps everything on empty string" $
40 it "keeps everything on empty string" $
39 runPrefix "" `shouldBe` modules
41 runPrefix "" `shouldBe` modules
40 it "keeps functionname prefix matches" $
42 it "keeps functionname prefix matches" $
41− runPrefix "fun" `shouldBe` [head modules]
43+ runPrefix "fun" `shouldBe` [moduleA]
42 it "keeps data decls prefix matches" $
44 it "keeps data decls prefix matches" $
43− runPrefix "dat" `shouldBe` [modules !! 1]
45+ runPrefix "dat" `shouldBe` [moduleB]
44 describe "moduleFilter" $ do
46 describe "moduleFilter" $ do
45 it "removes everything on empty input" $
47 it "removes everything on empty input" $
46 runModule [] `shouldBe` []
48 runModule [] `shouldBe` []
47 it "only keeps the specified modules" $
49 it "only keeps the specified modules" $
48− runModule [P.moduleNameFromString "Module.A"] `shouldBe` [head modules]
50+ runModule [P.moduleNameFromString "Module.A"] `shouldBe` [moduleA]
49 it "ignores modules that are not in scope" $
51 it "ignores modules that are not in scope" $
50− runModule (P.moduleNameFromString <$> ["Module.A", "Unknown"]) `shouldBe` [head modules]
52+ runModule (P.moduleNameFromString <$> ["Module.A", "Unknown"]) `shouldBe` [moduleA]
tests/Language/PureScript/Ide/Imports/IntegrationSpec.hs+4−2
@@ -1,8 +1,10 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE NoImplicitPrelude #-}
2module Language.PureScript.Ide.Imports.IntegrationSpec where
3module Language.PureScript.Ide.Imports.IntegrationSpec where
3
4
4−import Control.Monad (void)
5+
5−import Data.Text (Text)
6+import Protolude
7+
6import qualified Data.Text as T
8import qualified Data.Text as T
7import qualified Data.Text.IO as TIO
9import qualified Data.Text.IO as TIO
8import qualified Language.PureScript.Ide.Integration as Integration
10import qualified Language.PureScript.Ide.Integration as Integration
tests/Language/PureScript/Ide/ImportsSpec.hs+6−6
@@ -1,8 +1,10 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE NoImplicitPrelude #-}
2module Language.PureScript.Ide.ImportsSpec where
3module Language.PureScript.Ide.ImportsSpec where
3
4
4−import Data.Maybe (fromJust)
5+import Protolude
5−import Data.Text (Text)
6+import Unsafe (fromJust)
7+
6import qualified Language.PureScript as P
8import qualified Language.PureScript as P
7import Language.PureScript.Ide.Imports
9import Language.PureScript.Ide.Imports
8import Language.PureScript.Ide.Types
10import Language.PureScript.Ide.Types
@@ -17,11 +19,9 @@ simpleFile =
17 ]
19 ]
18
20
19splitSimpleFile :: (P.ModuleName, [Text], [Import], [Text])
21splitSimpleFile :: (P.ModuleName, [Text], [Import], [Text])
20−splitSimpleFile = fromRight $ sliceImportSection simpleFile
22+splitSimpleFile = fromRight (sliceImportSection simpleFile)
21 where
23 where
22− fromRight (Right r) = r
24+ fromRight = fromJust . rightToMaybe
23− fromRight (Left _) = error "fromRight"
24−
25withImports :: [Text] -> [Text]
25withImports :: [Text] -> [Text]
26withImports is =
26withImports is =
27 take 2 simpleFile ++ is ++ drop 2 simpleFile
27 take 2 simpleFile ++ is ++ drop 2 simpleFile
tests/Language/PureScript/Ide/Integration.hs+53−72
@@ -14,6 +14,7 @@
14
14
15{-# LANGUAGE OverloadedStrings #-}
15{-# LANGUAGE OverloadedStrings #-}
16{-# LANGUAGE ScopedTypeVariables #-}
16{-# LANGUAGE ScopedTypeVariables #-}
17+{-# LANGUAGE NoImplicitPrelude #-}
17module Language.PureScript.Ide.Integration
18module Language.PureScript.Ide.Integration
18 (
19 (
19 -- managing the server process
20 -- managing the server process
@@ -44,19 +45,15 @@ module Language.PureScript.Ide.Integration
44 , parseTextResult
45 , parseTextResult
45 ) where
46 ) where
46
47
47−import Control.Concurrent (threadDelay)
48+import Protolude
48−import Control.Exception
49+import Unsafe (fromJust)
49−import Control.Monad (join, when)
50+
50import Data.Aeson
51import Data.Aeson
51import Data.Aeson.Types
52import Data.Aeson.Types
52−import qualified Data.ByteString.Lazy.UTF8 as BSL
53−import Data.Either (isRight)
54−import Data.Maybe (fromJust, isNothing, fromMaybe)
55import qualified Data.Text as T
53import qualified Data.Text as T
56import qualified Data.Vector as V
54import qualified Data.Vector as V
57import Language.PureScript.Ide.Util
55import Language.PureScript.Ide.Util
58import System.Directory
56import System.Directory
59−import System.Exit
60import System.FilePath
57import System.FilePath
61import System.IO.Error (mkIOError, userErrorType)
58import System.IO.Error (mkIOError, userErrorType)
62import System.Process
59import System.Process
@@ -81,26 +78,23 @@ stopServer = terminateProcess
81withServer :: IO a -> IO a
78withServer :: IO a -> IO a
82withServer s = do
79withServer s = do
83 _ <- startServer
80 _ <- startServer
84− started <- tryNTimes 5 (shush <$> (try getCwd :: IO (Either SomeException String)))
81+ started <- tryNTimes 5 (rightToMaybe <$> (try getCwd :: IO (Either SomeException Text)))
85 when (isNothing started) $
82 when (isNothing started) $
86 throwIO (mkIOError userErrorType "psc-ide-server didn't start in time" Nothing Nothing)
83 throwIO (mkIOError userErrorType "psc-ide-server didn't start in time" Nothing Nothing)
87 r <- s
84 r <- s
88 quitServer
85 quitServer
89 pure r
86 pure r
90
87
91−shush :: Either a b -> Maybe b
92−shush = either (const Nothing) Just
93−
94-- project management utils
88-- project management utils
95
89
96compileTestProject :: IO Bool
90compileTestProject :: IO Bool
97compileTestProject = do
91compileTestProject = do
98 pdir <- projectDirectory
92 pdir <- projectDirectory
99 (_, _, _, procHandle) <- createProcess $
93 (_, _, _, procHandle) <- createProcess $
100− (shell $ "psc " ++ fileGlob) { cwd = Just pdir
94+ (shell . toS $ "psc " <> fileGlob) { cwd = Just pdir
101− , std_out = CreatePipe
95+ , std_out = CreatePipe
102− , std_err = CreatePipe
96+ , std_err = CreatePipe
103− }
97+ }
104 r <- tryNTimes 5 (getProcessExitCode procHandle)
98 r <- tryNTimes 5 (getProcessExitCode procHandle)
105 pure (fromMaybe False (isSuccess <$> r))
99 pure (fromMaybe False (isSuccess <$> r))
106
100
@@ -122,24 +116,17 @@ deleteOutputFolder = do
122deleteFileIfExists :: FilePath -> IO ()
116deleteFileIfExists :: FilePath -> IO ()
123deleteFileIfExists fp = whenM (doesFileExist fp) (removeFile fp)
117deleteFileIfExists fp = whenM (doesFileExist fp) (removeFile fp)
124
118
125−whenM :: Monad m => m Bool -> m () -> m ()
126−whenM p f = do
127− x <- p
128− when x f
129−
130isSuccess :: ExitCode -> Bool
119isSuccess :: ExitCode -> Bool
131isSuccess ExitSuccess = True
120isSuccess ExitSuccess = True
132isSuccess (ExitFailure _) = False
121isSuccess (ExitFailure _) = False
133
122
134−fileGlob :: String
123+fileGlob :: Text
135−fileGlob = unwords
136− [ "\"src/**/*.purs\""
124+fileGlob = "\"src/**/*.purs\""
137− ]
138
125
139-- Integration Testing API
126-- Integration Testing API
140
127
141−sendCommand :: Value -> IO String
128+sendCommand :: Value -> IO Text
142−sendCommand v = readCreateProcess
129+sendCommand v = toS <$> readCreateProcess
143 ((shell "psc-ide-client") { std_out=CreatePipe
130 ((shell "psc-ide-client") { std_out=CreatePipe
144 , std_err=CreatePipe
131 , std_err=CreatePipe
145 })
132 })
@@ -147,68 +134,68 @@ sendCommand v = readCreateProcess
147
134
148quitServer :: IO ()
135quitServer :: IO ()
149quitServer = do
136quitServer = do
150− let quitCommand = object ["command" .= ("quit" :: String)]
137+ let quitCommand = object ["command" .= ("quit" :: Text)]
151− _ <- try $ sendCommand quitCommand :: IO (Either SomeException String)
138+ _ <- try $ sendCommand quitCommand :: IO (Either SomeException Text)
152 return ()
139 return ()
153
140
154reset :: IO ()
141reset :: IO ()
155reset = do
142reset = do
156− let resetCommand = object ["command" .= ("reset" :: String)]
143+ let resetCommand = object ["command" .= ("reset" :: Text)]
157− _ <- try $ sendCommand resetCommand :: IO (Either SomeException String)
144+ _ <- try $ sendCommand resetCommand :: IO (Either SomeException Text)
158 return ()
145 return ()
159
146
160−getCwd :: IO String
147+getCwd :: IO Text
161getCwd = do
148getCwd = do
162− let cwdCommand = object ["command" .= ("cwd" :: String)]
149+ let cwdCommand = object ["command" .= ("cwd" :: Text)]
163 sendCommand cwdCommand
150 sendCommand cwdCommand
164
151
165−loadModule :: String -> IO String
152+loadModule :: Text -> IO Text
166loadModule m = loadModules [m]
153loadModule m = loadModules [m]
167
154
168−loadModules :: [String] -> IO String
155+loadModules :: [Text] -> IO Text
169loadModules = sendCommand . load
156loadModules = sendCommand . load
170
157
171−loadAll :: IO String
158+loadAll :: IO Text
172loadAll = sendCommand (load [])
159loadAll = sendCommand (load [])
173
160
174−getFlexCompletions :: String -> IO [(String, String, String)]
161+getFlexCompletions :: Text -> IO [(Text, Text, Text)]
175getFlexCompletions q = parseCompletions <$> sendCommand (completion [] (Just (flexMatcher q)) Nothing)
162getFlexCompletions q = parseCompletions <$> sendCommand (completion [] (Just (flexMatcher q)) Nothing)
176
163
177−getFlexCompletionsInModule :: String -> String -> IO [(String, String, String)]
164+getFlexCompletionsInModule :: Text -> Text -> IO [(Text, Text, Text)]
178getFlexCompletionsInModule q m = parseCompletions <$> sendCommand (completion [] (Just (flexMatcher q)) (Just m))
165getFlexCompletionsInModule q m = parseCompletions <$> sendCommand (completion [] (Just (flexMatcher q)) (Just m))
179
166
180−getType :: String -> IO [(String, String, String)]
167+getType :: Text -> IO [(Text, Text, Text)]
181getType q = parseCompletions <$> sendCommand (typeC q [])
168getType q = parseCompletions <$> sendCommand (typeC q [])
182
169
183−addImport :: String -> FilePath -> FilePath -> IO String
170+addImport :: Text -> FilePath -> FilePath -> IO Text
184addImport identifier fp outfp = sendCommand (addImportC identifier fp outfp)
171addImport identifier fp outfp = sendCommand (addImportC identifier fp outfp)
185
172
186−addImplicitImport :: String -> FilePath -> FilePath -> IO String
173+addImplicitImport :: Text -> FilePath -> FilePath -> IO Text
187addImplicitImport mn fp outfp = sendCommand (addImplicitImportC mn fp outfp)
174addImplicitImport mn fp outfp = sendCommand (addImplicitImportC mn fp outfp)
188
175
189−rebuildModule :: FilePath -> IO String
176+rebuildModule :: FilePath -> IO Text
190rebuildModule m = sendCommand (rebuildC m Nothing)
177rebuildModule m = sendCommand (rebuildC m Nothing)
191
178
192-- Command Encoding
179-- Command Encoding
193
180
194−commandWrapper :: String -> Value -> Value
181+commandWrapper :: Text -> Value -> Value
195commandWrapper c p = object ["command" .= c, "params" .= p]
182commandWrapper c p = object ["command" .= c, "params" .= p]
196
183
197−load :: [String] -> Value
184+load :: [Text] -> Value
198load ms = commandWrapper "load" (object ["modules" .= ms])
185load ms = commandWrapper "load" (object ["modules" .= ms])
199
186
200−typeC :: String -> [Value] -> Value
187+typeC :: Text -> [Value] -> Value
201typeC q filters = commandWrapper "type" (object ["search" .= q, "filters" .= filters])
188typeC q filters = commandWrapper "type" (object ["search" .= q, "filters" .= filters])
202
189
203−addImportC :: String -> FilePath -> FilePath -> Value
190+addImportC :: Text -> FilePath -> FilePath -> Value
204addImportC identifier = addImportW $
191addImportC identifier = addImportW $
205− object [ "importCommand" .= ("addImport" :: String)
192+ object [ "importCommand" .= ("addImport" :: Text)
206 , "identifier" .= identifier
193 , "identifier" .= identifier
207 ]
194 ]
208
195
209−addImplicitImportC :: String -> FilePath -> FilePath -> Value
196+addImplicitImportC :: Text -> FilePath -> FilePath -> Value
210addImplicitImportC mn = addImportW $
197addImplicitImportC mn = addImportW $
211− object [ "importCommand" .= ("addImplicitImport" :: String)
198+ object [ "importCommand" .= ("addImplicitImport" :: Text)
212 , "module" .= mn
199 , "module" .= mn
213 ]
200 ]
214
201
@@ -226,7 +213,7 @@ addImportW importCommand fp outfp =
226 ])
213 ])
227
214
228
215
229−completion :: [Value] -> Maybe Value -> Maybe String -> Value
216+completion :: [Value] -> Maybe Value -> Maybe Text -> Value
230completion filters matcher currentModule =
217completion filters matcher currentModule =
231 let
218 let
232 matcher' = case matcher of
219 matcher' = case matcher of
@@ -238,16 +225,16 @@ completion filters matcher currentModule =
238 in
225 in
239 commandWrapper "complete" (object $ "filters" .= filters : matcher' ++ currentModule' )
226 commandWrapper "complete" (object $ "filters" .= filters : matcher' ++ currentModule' )
240
227
241−flexMatcher :: String -> Value
228+flexMatcher :: Text -> Value
242−flexMatcher q = object [ "matcher" .= ("flex" :: String)
229+flexMatcher q = object [ "matcher" .= ("flex" :: Text)
243 , "params" .= object ["search" .= q]
230 , "params" .= object ["search" .= q]
244 ]
231 ]
245
232
246-- Result parsing
233-- Result parsing
247
234
248−unwrapResult :: Value -> Parser (Either String Value)
235+unwrapResult :: Value -> Parser (Either Text Value)
249unwrapResult = withObject "result" $ \o -> do
236unwrapResult = withObject "result" $ \o -> do
250− (rt :: String) <- o .: "resultType"
237+ (rt :: Text) <- o .: "resultType"
251 case rt of
238 case rt of
252 "error" -> do
239 "error" -> do
253 res <- o .: "result"
240 res <- o .: "result"
@@ -255,16 +242,16 @@ unwrapResult = withObject "result" $ \o -> do
255 "success" -> do
242 "success" -> do
256 res <- o .: "result"
243 res <- o .: "result"
257 pure (Right res)
244 pure (Right res)
258− _ -> fail "lol"
245+ _ -> mzero
259
246
260−withResult :: (Value -> Parser a) -> Value -> Parser (Either String a)
247+withResult :: (Value -> Parser a) -> Value -> Parser (Either Text a)
261withResult p v = do
248withResult p v = do
262 r <- unwrapResult v
249 r <- unwrapResult v
263 case r of
250 case r of
264 Left err -> pure (Left err)
251 Left err -> pure (Left err)
265 Right res -> Right <$> p res
252 Right res -> Right <$> p res
266
253
267−completionParser :: Value -> Parser [(String, String, String)]
254+completionParser :: Value -> Parser [(Text, Text, Text)]
268completionParser = withArray "res" $ \cs ->
255completionParser = withArray "res" $ \cs ->
269 mapM (withObject "completion" $ \o -> do
256 mapM (withObject "completion" $ \o -> do
270 ident <- o .: "identifier"
257 ident <- o .: "identifier"
@@ -272,22 +259,16 @@ completionParser = withArray "res" $ \cs ->
272 ty <- o .: "type"
259 ty <- o .: "type"
273 pure (module', ident, ty)) (V.toList cs)
260 pure (module', ident, ty)) (V.toList cs)
274
261
275−valueFromString :: String -> Value
262+valueFromText :: Text -> Value
276−valueFromString = fromJust . decode . BSL.fromString
263+valueFromText = fromJust . decode . toS
277
264
278−resultIsSuccess :: String -> Bool
265+resultIsSuccess :: Text -> Bool
279−resultIsSuccess = isRight . join . parseEither unwrapResult . valueFromString
266+resultIsSuccess = isRight . join . first toS . parseEither unwrapResult . valueFromText
280
267
281−parseCompletions :: String -> [(String, String, String)]
268+parseCompletions :: Text -> [(Text, Text, Text)]
282−parseCompletions s = fromJust $ do
269+parseCompletions s =
283− cs <- parseMaybe (withResult completionParser) (valueFromString s)
270+ fromJust $ join (rightToMaybe <$> parseMaybe (withResult completionParser) (valueFromText s))
284− case cs of
285− Left _ -> error "Failed to parse completions"
286− Right cs' -> pure cs'
287
271
288−parseTextResult :: String -> String
272+parseTextResult :: Text -> Text
289−parseTextResult s = fromJust $ do
273+parseTextResult s =
290− r <- parseMaybe (withResult (withText "tr" pure)) (valueFromString s)
274+ fromJust $ join (rightToMaybe <$> parseMaybe (withResult (withText "tr" pure)) (valueFromText s))
291− case r of
292− Left _ -> error "Failed to parse textResult"
293− Right r' -> pure (T.unpack r')
tests/Language/PureScript/Ide/MatcherSpec.hs+11−12
@@ -1,9 +1,10 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE NoImplicitPrelude #-}
2
3
3module Language.PureScript.Ide.MatcherSpec where
4module Language.PureScript.Ide.MatcherSpec where
4
5
5−import Control.Monad (void)
6+import Protolude
6−import Data.Text (Text)
7+
7import qualified Language.PureScript as P
8import qualified Language.PureScript as P
8import Language.PureScript.Ide.Integration
9import Language.PureScript.Ide.Integration
9import Language.PureScript.Ide.Matcher
10import Language.PureScript.Ide.Matcher
@@ -13,15 +14,13 @@ import Test.Hspec
13value :: Text -> IdeDeclaration
14value :: Text -> IdeDeclaration
14value s = IdeValue s $ P.TypeWildcard $ P.SourceSpan "" (P.SourcePos 0 0) (P.SourcePos 0 0)
15value s = IdeValue s $ P.TypeWildcard $ P.SourceSpan "" (P.SourcePos 0 0) (P.SourcePos 0 0)
15
16
16−completions :: [Match]
17+firstResult, secondResult, fiult :: Match
17−completions =
18− [ Match (P.moduleNameFromString "Match") (value "firstResult")
18+firstResult = Match (P.moduleNameFromString "Match") (value "firstResult")
19− , Match (P.moduleNameFromString "Match") (value "secondResult")
19+secondResult = Match (P.moduleNameFromString "Match") (value "secondResult")
20− , Match (P.moduleNameFromString "Match") (value "fiult")
20+fiult = Match (P.moduleNameFromString "Match") (value "fiult")
21− ]
22
21
23−mkResult :: [Int] -> [Match]
22+completions :: [Match]
24−mkResult = map (completions !!)
23+completions = [firstResult, secondResult, fiult]
25
24
26runFlex :: Text -> [Match]
25runFlex :: Text -> [Match]
27runFlex s = runMatcher (flexMatcher s) completions
26runFlex s = runMatcher (flexMatcher s) completions
@@ -35,9 +34,9 @@ spec = do
35 it "doesn't match on an empty string" $
34 it "doesn't match on an empty string" $
36 runFlex "" `shouldBe` []
35 runFlex "" `shouldBe` []
37 it "matches on equality" $
36 it "matches on equality" $
38− runFlex "firstResult" `shouldBe` mkResult [0]
37+ runFlex "firstResult" `shouldBe` [firstResult]
39 it "scores short matches higher and sorts accordingly" $
38 it "scores short matches higher and sorts accordingly" $
40− runFlex "filt" `shouldBe` mkResult [2, 0]
39+ runFlex "filt" `shouldBe` [fiult, firstResult]
41
40
42 beforeAll_ setup . describe "Integration Tests: Flex Matcher" $ do
41 beforeAll_ setup . describe "Integration Tests: Flex Matcher" $ do
43 it "doesn't match on an empty string" $ do
42 it "doesn't match on an empty string" $ do
tests/Language/PureScript/Ide/RebuildSpec.hs+6−2
@@ -1,13 +1,17 @@
1+{-# LANGUAGE NoImplicitPrelude #-}
2+{-# LANGUAGE OverloadedStrings #-}
1module Language.PureScript.Ide.RebuildSpec where
3module Language.PureScript.Ide.RebuildSpec where
2
4
5+import Protolude
6+
3import qualified Language.PureScript.Ide.Integration as Integration
7import qualified Language.PureScript.Ide.Integration as Integration
4import System.FilePath
8import System.FilePath
5import Test.Hspec
9import Test.Hspec
6
10
7−shouldBeSuccess :: String -> IO ()
11+shouldBeSuccess :: Text -> IO ()
8shouldBeSuccess = shouldBe True . Integration.resultIsSuccess
12shouldBeSuccess = shouldBe True . Integration.resultIsSuccess
9
13
10−shouldBeFailure :: String -> IO ()
14+shouldBeFailure :: Text -> IO ()
11shouldBeFailure = shouldBe False . Integration.resultIsSuccess
15shouldBeFailure = shouldBe False . Integration.resultIsSuccess
12
16
13spec :: Spec
17spec :: Spec
tests/Language/PureScript/Ide/ReexportsSpec.hs+4−6
@@ -1,8 +1,9 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE NoImplicitPrelude #-}
2module Language.PureScript.Ide.ReexportsSpec where
3module Language.PureScript.Ide.ReexportsSpec where
3
4
4−import Control.Exception (evaluate)
5+import Protolude
5−import Data.List (sort)
6+
6import qualified Data.Map as Map
7import qualified Data.Map as Map
7import Language.PureScript.Ide.Reexports
8import Language.PureScript.Ide.Reexports
8import Language.PureScript.Ide.Types
9import Language.PureScript.Ide.Types
@@ -41,7 +42,7 @@ module4 = ("Module4", [Export "T", decl1, dep1, dep2])
41result :: ModuleOld
42result :: ModuleOld
42result = ("Module1", [decl1, decl2, Export "Module3"])
43result = ("Module1", [decl1, decl2, Export "Module3"])
43
44
44−db :: Map.Map ModuleIdent [ExternDecl]
45+db :: Map ModuleIdent [ExternDecl]
45db = Map.fromList [module1, module2, module3]
46db = Map.fromList [module1, module2, module3]
46
47
47shouldBeEqualSorted :: ModuleOld -> ModuleOld -> Expectation
48shouldBeEqualSorted :: ModuleOld -> ModuleOld -> Expectation
@@ -64,9 +65,6 @@ spec =
64 let replaced = replaceReexport (Export "Module2") module1 module2
65 let replaced = replaceReexport (Export "Module2") module1 module2
65 in replaceReexport (Export "Module2") replaced module2 `shouldBeEqualSorted` result
66 in replaceReexport (Export "Module2") replaced module2 `shouldBeEqualSorted` result
66
67
67− it "should error when given a non-Export to replace" $
68− evaluate (replaceReexport decl1 module1 module2)
69− `shouldThrow` errorCall "Should only get Exports here."
70 it "replaces all Exports with their corresponding declarations" $
68 it "replaces all Exports with their corresponding declarations" $
71 replaceReexports module1 db `shouldBe` ("Module1", [decl1, decl2, decl3])
69 replaceReexports module1 db `shouldBe` ("Module1", [decl1, decl2, decl3])
72
70