Skip to content

Commit e65645e

Browse files
committed
Add suggestion framework with "Did you mean composition" example
1 parent 498dadc commit e65645e

File tree

7 files changed

+277
-237
lines changed

7 files changed

+277
-237
lines changed

psc-make/Main.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ runMake opts = runExceptT . runWriterT . flip runReaderT opts . unMake
6262
makeIO :: (IOError -> P.ErrorMessage) -> IO a -> Make a
6363
makeIO f io = do
6464
e <- liftIO $ tryIOError io
65-
either (throwError . P.errorMessage . f) return e
65+
either (throwError . P.singleError . f) return e
6666

6767
instance P.MonadMake Make where
68-
getTimestamp path = makeIO (const (P.CannotGetFileInfo path)) $ do
68+
getTimestamp path = makeIO (const (P.SimpleErrorWrapper $ P.CannotGetFileInfo path)) $ do
6969
exists <- doesFileExist path
7070
traverse (const $ getModificationTime path) $ guard exists
71-
readTextFile path = makeIO (const (P.CannotReadFile path))$ do
71+
readTextFile path = makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile path)) $ do
7272
putStrLn $ "Reading " ++ path
7373
readFile path
74-
writeTextFile path text = makeIO (const (P.CannotWriteFile path)) $ do
74+
writeTextFile path text = makeIO (const (P.SimpleErrorWrapper $ P.CannotWriteFile path)) $ do
7575
mkdirp path
7676
putStrLn $ "Writing " ++ path
7777
writeFile path text

psci/PSCi.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ runMake = runExceptT . fmap fst . runWriterT . flip runReaderT options . unMake
221221
makeIO :: (IOError -> P.ErrorMessage) -> IO a -> Make a
222222
makeIO f io = do
223223
e <- liftIO $ tryIOError io
224-
either (throwError . P.errorMessage . f) return e
224+
either (throwError . P.singleError . f) return e
225225

226226
instance P.MonadMake Make where
227-
getTimestamp path = makeIO (const (P.CannotGetFileInfo path)) $ do
227+
getTimestamp path = makeIO (const (P.SimpleErrorWrapper $ P.CannotGetFileInfo path)) $ do
228228
exists <- doesFileExist path
229229
traverse (const $ getModificationTime path) $ guard exists
230-
readTextFile path = makeIO (const (P.CannotReadFile path)) $ readFile path
231-
writeTextFile path text = makeIO (const (P.CannotWriteFile path)) $ do
230+
readTextFile path = makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile path)) $ readFile path
231+
writeTextFile path text = makeIO (const (P.SimpleErrorWrapper $ P.CannotWriteFile path)) $ do
232232
mkdirp path
233233
writeFile path text
234234
progress s = unless ("Compiling $PSCI" `isPrefixOf` s) $ liftIO . putStrLn $ s

src/Language/PureScript/Environment.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ tyArray = primTy "Array"
220220
tyObject :: Type
221221
tyObject = primTy "Object"
222222

223+
-- |
224+
-- Check whether a type is an object
225+
--
226+
isObject :: Type -> Bool
227+
isObject = (==) tyObject . extract
228+
where extract (TypeApp t _) = t
229+
extract t = t
230+
223231
-- |
224232
-- Smart constructor for function types
225233
--

src/Language/PureScript/Errors.hs

Lines changed: 253 additions & 221 deletions
Large diffs are not rendered by default.

src/Language/PureScript/Sugar/Names.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ addValue env mn name = updateExportedModule env mn $ \m -> do
142142
-- Adds an entry to a list of exports unless it is already present, in which case an error is
143143
-- returned.
144144
--
145-
addExport :: (Applicative m, MonadError MultipleErrors m, Eq a, Show a) => (a -> ErrorMessage) -> [a] -> a -> m [a]
145+
addExport :: (Applicative m, MonadError MultipleErrors m, Eq a, Show a) => (a -> SimpleErrorMessage) -> [a] -> a -> m [a]
146146
addExport what exports name =
147147
if name `elem` exports
148148
then throwConflictError what name
@@ -279,7 +279,7 @@ renameInModule imports exports (Module coms mn decls exps) =
279279

280280
-- Update names so unqualified references become qualified, and locally qualified references
281281
-- are replaced with their canoncial qualified names (e.g. M.Map -> Data.Map.Map)
282-
update :: (Ord a, Show a) => (Qualified a -> ErrorMessage)
282+
update :: (Ord a, Show a) => (Qualified a -> SimpleErrorMessage)
283283
-> (ImportEnvironment -> M.Map (Qualified a) (Qualified a))
284284
-> (Exports -> a -> Bool)
285285
-> Qualified a
@@ -529,7 +529,7 @@ resolveImport currentModule importModule exps imps impQual =
529529
checkDctorExists = checkImportExists (flip UnknownDataConstructor Nothing)
530530

531531
-- Check that an explicitly imported item exists in the module it is being imported from
532-
checkImportExists :: (Eq a, Show a) => (Qualified a -> ErrorMessage) -> [a] -> a -> m a
532+
checkImportExists :: (Eq a, Show a) => (Qualified a -> SimpleErrorMessage) -> [a] -> a -> m a
533533
checkImportExists unknown exports item =
534534
if item `elem` exports
535535
then return item
@@ -538,5 +538,5 @@ resolveImport currentModule importModule exps imps impQual =
538538
-- |
539539
-- Raises an error for when there is more than one definition for something.
540540
--
541-
throwConflictError :: (Applicative m, MonadError MultipleErrors m, Show a) => (a -> ErrorMessage) -> a -> m b
541+
throwConflictError :: (Applicative m, MonadError MultipleErrors m, Show a) => (a -> SimpleErrorMessage) -> a -> m b
542542
throwConflictError conflict = throwError . errorMessage . conflict

src/Language/PureScript/TypeChecker/Skolems.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ skolemEscapeCheck root@TypedValue{} =
8888
let (_, f, _, _, _) = everythingWithContextOnValues [] [] (++) def go def def def
8989
in case f root of
9090
[] -> return ()
91-
((binding, val) : _) -> throwError . errorMessage . ErrorInExpression val $ EscapedSkolem binding
91+
((binding, val) : _) -> throwError . singleError $ ErrorInExpression val $ SimpleErrorWrapper $ EscapedSkolem binding
9292
where
9393
def s _ = (s, [])
9494

src/Language/PureScript/TypeChecker/Synonyms.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ buildTypeSubstitution name n = go n []
4646
where
4747
go :: Int -> [Type] -> Type -> Either ErrorMessage (Maybe Type)
4848
go 0 args (TypeConstructor ctor) | name == ctor = return (Just $ SaturatedTypeSynonym ctor args)
49-
go m _ (TypeConstructor ctor) | m > 0 && name == ctor = throwError $ PartiallyAppliedSynonym name
49+
go m _ (TypeConstructor ctor) | m > 0 && name == ctor = throwError $ SimpleErrorWrapper $ PartiallyAppliedSynonym name
5050
go m args (TypeApp f arg) = go (m - 1) (arg:args) f
5151
go _ _ _ = return Nothing
5252

@@ -87,7 +87,7 @@ replaceAllTypeSynonyms' env d =
8787
replaceAllTypeSynonyms :: (e ~ MultipleErrors, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
8888
replaceAllTypeSynonyms d = do
8989
env <- getEnv
90-
either (throwError . errorMessage) return $ replaceAllTypeSynonyms' env d
90+
either (throwError . singleError) return $ replaceAllTypeSynonyms' env d
9191

9292
-- |
9393
-- Replace a type synonym and its arguments with the aliased type
@@ -103,7 +103,7 @@ expandTypeSynonym' env name args =
103103
expandTypeSynonym :: (e ~ MultipleErrors, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Qualified ProperName -> [Type] -> m Type
104104
expandTypeSynonym name args = do
105105
env <- getEnv
106-
either (throwError . errorMessage) return $ expandTypeSynonym' env name args
106+
either (throwError . singleError) return $ expandTypeSynonym' env name args
107107

108108
expandAllTypeSynonyms :: (e ~ MultipleErrors, Functor m, Applicative m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
109109
expandAllTypeSynonyms = everywhereOnTypesTopDownM go

0 commit comments

Comments
 (0)