git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Further conversions to Text in Docs modules (#2502)
1c5a431Harry Garrood
examples/docs/src/DocComments.pursnew file+11
@@ -0,0 +1,11 @@
1+module DocComments where
2+
3+-- | This declaration has a code block:
4+-- |
5+-- | example == 0
6+-- |
7+-- | Here we are really testing that the leading whitespace is not stripped, as
8+-- | this ensures that we don't accidentally change code blocks into normal
9+-- | paragraphs.
10+example :: Int
11+example = 0
psc-docs/Main.hs+5−4
@@ -9,6 +9,7 @@ import Control.Category ((>>>))
9import Control.Monad.Writer
9import Control.Monad.Writer
10import Data.Text (Text)
10import Data.Text (Text)
11import qualified Data.Text as T
11import qualified Data.Text as T
12+import qualified Data.Text.IO as T
12import Data.Function (on)
13import Data.Function (on)
13import Data.List
14import Data.List
14import Data.Maybe (fromMaybe)
15import Data.Maybe (fromMaybe)
@@ -22,7 +23,7 @@ import qualified Language.PureScript as P
22import qualified Paths_purescript as Paths
23import qualified Paths_purescript as Paths
23import System.Exit (exitFailure)
24import System.Exit (exitFailure)
24import System.IO (hPutStrLn, hPrint, hSetEncoding, stderr, stdout, utf8)
25import System.IO (hPutStrLn, hPrint, hSetEncoding, stderr, stdout, utf8)
25−import System.IO.UTF8 (readUTF8FileT)
26+import System.IO.UTF8 (readUTF8FileT, writeUTF8FileT)
26import System.Directory (createDirectoryIfMissing)
27import System.Directory (createDirectoryIfMissing)
27import System.FilePath (takeDirectory)
28import System.FilePath (takeDirectory)
28import System.FilePath.Glob (glob)
29import System.FilePath.Glob (glob)
@@ -65,11 +66,11 @@ docgen (PSCDocsOptions fmt inputGlob output) = do
65
66
66 case output of
67 case output of
67 EverythingToStdOut ->
68 EverythingToStdOut ->
68− putStrLn (D.runDocs (D.modulesAsMarkdown ms))
69+ T.putStrLn (D.runDocs (D.modulesAsMarkdown ms))
69 ToStdOut names -> do
70 ToStdOut names -> do
70 let (ms', missing) = takeByName ms names
71 let (ms', missing) = takeByName ms names
71 guardMissing missing
72 guardMissing missing
72− putStrLn (D.runDocs (D.modulesAsMarkdown ms'))
73+ T.putStrLn (D.runDocs (D.modulesAsMarkdown ms'))
73 ToFiles names -> do
74 ToFiles names -> do
74 let (ms', missing) = takeByName' ms names
75 let (ms', missing) = takeByName' ms names
75 guardMissing missing
76 guardMissing missing
@@ -78,7 +79,7 @@ docgen (PSCDocsOptions fmt inputGlob output) = do
78 forM_ ms'' $ \grp -> do
79 forM_ ms'' $ \grp -> do
79 let fp = fst (head grp)
80 let fp = fst (head grp)
80 createDirectoryIfMissing True (takeDirectory fp)
81 createDirectoryIfMissing True (takeDirectory fp)
81− writeFile fp (D.runDocs (D.modulesAsMarkdown (map snd grp)))
82+ writeUTF8FileT fp (D.runDocs (D.modulesAsMarkdown (map snd grp)))
82
83
83 where
84 where
84 guardMissing [] = return ()
85 guardMissing [] = return ()
psc-publish/Main.hs+1
@@ -1,3 +1,4 @@
1+{-# LANGUAGE OverloadedStrings #-}
1
2
2module Main where
3module Main where
3
4
src/Language/PureScript/Docs/AsMarkdown.hs+18−16
@@ -13,7 +13,9 @@ import Control.Monad.Error.Class (MonadError)
13import Control.Monad.Writer (Writer, tell, execWriter)
13import Control.Monad.Writer (Writer, tell, execWriter)
14
14
15import Data.Foldable (for_)
15import Data.Foldable (for_)
16+import Data.Monoid ((<>))
16import Data.List (partition)
17import Data.List (partition)
18+import Data.Text (Text)
17import qualified Data.Text as T
19import qualified Data.Text as T
18
20
19import Language.PureScript.Docs.RenderedCode
21import Language.PureScript.Docs.RenderedCode
@@ -24,12 +26,12 @@ import qualified Language.PureScript.Docs.Render as Render
24
26
25-- |
27-- |
26-- Take a list of modules and render them all in order, returning a single
28-- Take a list of modules and render them all in order, returning a single
27−-- Markdown-formatted String.
29+-- Markdown-formatted Text.
28--
30--
29renderModulesAsMarkdown ::
31renderModulesAsMarkdown ::
30 (MonadError P.MultipleErrors m) =>
32 (MonadError P.MultipleErrors m) =>
31 [P.Module] ->
33 [P.Module] ->
32− m String
34+ m Text
33renderModulesAsMarkdown =
35renderModulesAsMarkdown =
34 fmap (runDocs . modulesAsMarkdown) . Convert.convertModules
36 fmap (runDocs . modulesAsMarkdown) . Convert.convertModules
35
37
@@ -38,13 +40,13 @@ modulesAsMarkdown = mapM_ moduleAsMarkdown
38
40
39moduleAsMarkdown :: Module -> Docs
41moduleAsMarkdown :: Module -> Docs
40moduleAsMarkdown Module{..} = do
42moduleAsMarkdown Module{..} = do
41− headerLevel 2 $ "Module " ++ T.unpack (P.runModuleName modName)
43+ headerLevel 2 $ "Module " <> P.runModuleName modName
42 spacer
44 spacer
43 for_ modComments tell'
45 for_ modComments tell'
44 mapM_ (declAsMarkdown modName) modDeclarations
46 mapM_ (declAsMarkdown modName) modDeclarations
45 spacer
47 spacer
46 for_ modReExports $ \(mn, decls) -> do
48 for_ modReExports $ \(mn, decls) -> do
47− headerLevel 3 $ "Re-exported from " ++ T.unpack (P.runModuleName mn) ++ ":"
49+ headerLevel 3 $ "Re-exported from " <> P.runModuleName mn <> ":"
48 spacer
50 spacer
49 mapM_ (declAsMarkdown mn) decls
51 mapM_ (declAsMarkdown mn) decls
50
52
@@ -71,7 +73,7 @@ declAsMarkdown mn decl@Declaration{..} = do
71 isChildInstance (ChildInstance _ _) = True
73 isChildInstance (ChildInstance _ _) = True
72 isChildInstance _ = False
74 isChildInstance _ = False
73
75
74−codeToString :: RenderedCode -> String
76+codeToString :: RenderedCode -> Text
75codeToString = outputWith elemAsMarkdown
77codeToString = outputWith elemAsMarkdown
76 where
78 where
77 elemAsMarkdown (Syntax x) = x
79 elemAsMarkdown (Syntax x) = x
@@ -95,14 +97,14 @@ codeToString = outputWith elemAsMarkdown
95-- P.Infixr -> "right-associative"
97-- P.Infixr -> "right-associative"
96-- P.Infix -> "non-associative"
98-- P.Infix -> "non-associative"
97
99
98−childToString :: First -> ChildDeclaration -> String
100+childToString :: First -> ChildDeclaration -> Text
99childToString f decl@ChildDeclaration{..} =
101childToString f decl@ChildDeclaration{..} =
100 case cdeclInfo of
102 case cdeclInfo of
101 ChildDataConstructor _ ->
103 ChildDataConstructor _ ->
102 let c = if f == First then "=" else "|"
104 let c = if f == First then "=" else "|"
103− in " " ++ c ++ " " ++ str
105+ in " " <> c <> " " <> str
104 ChildTypeClassMember _ ->
106 ChildTypeClassMember _ ->
105− " " ++ str
107+ " " <> str
106 ChildInstance _ _ ->
108 ChildInstance _ _ ->
107 str
109 str
108 where
110 where
@@ -113,19 +115,19 @@ data First
113 | NotFirst
115 | NotFirst
114 deriving (Show, Eq, Ord)
116 deriving (Show, Eq, Ord)
115
117
116−type Docs = Writer [String] ()
118+type Docs = Writer [Text] ()
117
119
118−runDocs :: Docs -> String
120+runDocs :: Docs -> Text
119−runDocs = unlines . execWriter
121+runDocs = T.unlines . execWriter
120
122
121−tell' :: String -> Docs
123+tell' :: Text -> Docs
122tell' = tell . (:[])
124tell' = tell . (:[])
123
125
124spacer :: Docs
126spacer :: Docs
125spacer = tell' ""
127spacer = tell' ""
126
128
127−headerLevel :: Int -> String -> Docs
129+headerLevel :: Int -> Text -> Docs
128−headerLevel level hdr = tell' (replicate level '#' ++ ' ' : hdr)
130+headerLevel level hdr = tell' (T.replicate level "#" <> " " <> hdr)
129
131
130fencedBlock :: Docs -> Docs
132fencedBlock :: Docs -> Docs
131fencedBlock inner = do
133fencedBlock inner = do
@@ -133,5 +135,5 @@ fencedBlock inner = do
133 inner
135 inner
134 tell' "```"
136 tell' "```"
135
137
136−ticks :: String -> String
138+ticks :: Text -> Text
137−ticks = ("`" ++) . (++ "`")
139+ticks = ("`" <>) . (<> "`")
src/Language/PureScript/Docs/Convert.hs+3−3
@@ -16,7 +16,7 @@ import Control.Monad.Error.Class (MonadError)
16import Control.Monad.State (runStateT)
16import Control.Monad.State (runStateT)
17import Control.Monad.Writer.Strict (runWriterT)
17import Control.Monad.Writer.Strict (runWriterT)
18import qualified Data.Map as Map
18import qualified Data.Map as Map
19−import qualified Data.Text as T
19+import Data.Text (Text)
20
20
21import Language.PureScript.Docs.Convert.ReExports (updateReExports)
21import Language.PureScript.Docs.Convert.ReExports (updateReExports)
22import Language.PureScript.Docs.Convert.Single (convertSingleModule, collectBookmarks)
22import Language.PureScript.Docs.Convert.Single (convertSingleModule, collectBookmarks)
@@ -167,9 +167,9 @@ insertValueTypes env m =
167 err msg =
167 err msg =
168 P.internalError ("Docs.Convert.insertValueTypes: " ++ msg)
168 P.internalError ("Docs.Convert.insertValueTypes: " ++ msg)
169
169
170−runParser :: P.TokenParser a -> String -> Either String a
170+runParser :: P.TokenParser a -> Text -> Either String a
171runParser p s = either (Left . show) Right $ do
171runParser p s = either (Left . show) Right $ do
172− ts <- P.lex "" (T.pack s)
172+ ts <- P.lex "" s
173 P.runTokenParser "" (p <* eof) ts
173 P.runTokenParser "" (p <* eof) ts
174
174
175-- |
175-- |
src/Language/PureScript/Docs/Convert/ReExports.hs+18−17
@@ -4,7 +4,7 @@ module Language.PureScript.Docs.Convert.ReExports
4
4
5import Prelude.Compat
5import Prelude.Compat
6
6
7−import Control.Arrow ((&&&), first, second)
7+import Control.Arrow ((&&&), second)
8import Control.Monad
8import Control.Monad
9import Control.Monad.Reader.Class (MonadReader, ask)
9import Control.Monad.Reader.Class (MonadReader, ask)
10import Control.Monad.State.Class (MonadState, gets, modify)
10import Control.Monad.State.Class (MonadState, gets, modify)
@@ -16,6 +16,7 @@ import Data.Map (Map)
16import Data.Maybe (mapMaybe)
16import Data.Maybe (mapMaybe)
17import Data.Monoid ((<>))
17import Data.Monoid ((<>))
18import qualified Data.Map as Map
18import qualified Data.Map as Map
19+import Data.Text (Text)
19import qualified Data.Text as T
20import qualified Data.Text as T
20
21
21import Language.PureScript.Docs.Types
22import Language.PureScript.Docs.Types
@@ -184,12 +185,12 @@ lookupValueDeclaration ::
184 MonadReader P.ModuleName m) =>
185 MonadReader P.ModuleName m) =>
185 P.ModuleName ->
186 P.ModuleName ->
186 P.Ident ->
187 P.Ident ->
187− m (P.ModuleName, [Either (String, P.Constraint, ChildDeclaration) Declaration])
188+ m (P.ModuleName, [Either (Text, P.Constraint, ChildDeclaration) Declaration])
188lookupValueDeclaration importedFrom ident = do
189lookupValueDeclaration importedFrom ident = do
189 decls <- lookupModuleDeclarations "lookupValueDeclaration" importedFrom
190 decls <- lookupModuleDeclarations "lookupValueDeclaration" importedFrom
190 let
191 let
191 rs =
192 rs =
192− filter (\d -> declTitle d == T.unpack (P.showIdent ident)
193+ filter (\d -> declTitle d == P.showIdent ident
193 && (isValue d || isValueAlias d)) decls
194 && (isValue d || isValueAlias d)) decls
194 errOther other =
195 errOther other =
195 internalErrorInModule
196 internalErrorInModule
@@ -215,7 +216,7 @@ lookupValueDeclaration importedFrom ident = do
215 (declChildren d))
216 (declChildren d))
216
217
217 matchesIdent cdecl =
218 matchesIdent cdecl =
218− cdeclTitle cdecl == T.unpack (P.showIdent ident)
219+ cdeclTitle cdecl == P.showIdent ident
219
220
220 matchesAndIsTypeClassMember =
221 matchesAndIsTypeClassMember =
221 uncurry (&&) . (matchesIdent &&& isTypeClassMember)
222 uncurry (&&) . (matchesIdent &&& isTypeClassMember)
@@ -239,7 +240,7 @@ lookupValueOpDeclaration
239 -> m (P.ModuleName, [Declaration])
240 -> m (P.ModuleName, [Declaration])
240lookupValueOpDeclaration importedFrom op = do
241lookupValueOpDeclaration importedFrom op = do
241 decls <- lookupModuleDeclarations "lookupValueOpDeclaration" importedFrom
242 decls <- lookupModuleDeclarations "lookupValueOpDeclaration" importedFrom
242− case filter (\d -> declTitle d == T.unpack (P.showOp op) && isValueAlias d) decls of
243+ case filter (\d -> declTitle d == P.showOp op && isValueAlias d) decls of
243 [d] ->
244 [d] ->
244 pure (importedFrom, [d])
245 pure (importedFrom, [d])
245 other ->
246 other ->
@@ -259,7 +260,7 @@ lookupTypeDeclaration ::
259lookupTypeDeclaration importedFrom ty = do
260lookupTypeDeclaration importedFrom ty = do
260 decls <- lookupModuleDeclarations "lookupTypeDeclaration" importedFrom
261 decls <- lookupModuleDeclarations "lookupTypeDeclaration" importedFrom
261 let
262 let
262− ds = filter (\d -> declTitle d == T.unpack (P.runProperName ty) && isType d) decls
263+ ds = filter (\d -> declTitle d == P.runProperName ty && isType d) decls
263 case ds of
264 case ds of
264 [d] ->
265 [d] ->
265 pure (importedFrom, [d])
266 pure (importedFrom, [d])
@@ -275,7 +276,7 @@ lookupTypeOpDeclaration
275lookupTypeOpDeclaration importedFrom tyOp = do
276lookupTypeOpDeclaration importedFrom tyOp = do
276 decls <- lookupModuleDeclarations "lookupTypeOpDeclaration" importedFrom
277 decls <- lookupModuleDeclarations "lookupTypeOpDeclaration" importedFrom
277 let
278 let
278− ds = filter (\d -> declTitle d == ("type " ++ T.unpack (P.showOp tyOp)) && isTypeAlias d) decls
279+ ds = filter (\d -> declTitle d == ("type " <> P.showOp tyOp) && isTypeAlias d) decls
279 case ds of
280 case ds of
280 [d] ->
281 [d] ->
281 pure (importedFrom, [d])
282 pure (importedFrom, [d])
@@ -291,7 +292,7 @@ lookupTypeClassDeclaration
291lookupTypeClassDeclaration importedFrom tyClass = do
292lookupTypeClassDeclaration importedFrom tyClass = do
292 decls <- lookupModuleDeclarations "lookupTypeClassDeclaration" importedFrom
293 decls <- lookupModuleDeclarations "lookupTypeClassDeclaration" importedFrom
293 let
294 let
294− ds = filter (\d -> declTitle d == T.unpack (P.runProperName tyClass)
295+ ds = filter (\d -> declTitle d == P.runProperName tyClass
295 && isTypeClass d)
296 && isTypeClass d)
296 decls
297 decls
297 case ds of
298 case ds of
@@ -324,7 +325,7 @@ lookupModuleDeclarations definedIn moduleName = do
324
325
325handleTypeClassMembers ::
326handleTypeClassMembers ::
326 (MonadReader P.ModuleName m) =>
327 (MonadReader P.ModuleName m) =>
327− Map P.ModuleName [Either (String, P.Constraint, ChildDeclaration) Declaration] ->
328+ Map P.ModuleName [Either (Text, P.Constraint, ChildDeclaration) Declaration] ->
328 Map P.ModuleName [Declaration] ->
329 Map P.ModuleName [Declaration] ->
329 m (Map P.ModuleName [Declaration], Map P.ModuleName [Declaration])
330 m (Map P.ModuleName [Declaration], Map P.ModuleName [Declaration])
330handleTypeClassMembers valsAndMembers typeClasses =
331handleTypeClassMembers valsAndMembers typeClasses =
@@ -339,7 +340,7 @@ handleTypeClassMembers valsAndMembers typeClasses =
339 |> fmap splitMap
340 |> fmap splitMap
340
341
341valsAndMembersToEnv ::
342valsAndMembersToEnv ::
342− [Either (String, P.Constraint, ChildDeclaration) Declaration] -> TypeClassEnv
343+ [Either (Text, P.Constraint, ChildDeclaration) Declaration] -> TypeClassEnv
343valsAndMembersToEnv xs =
344valsAndMembersToEnv xs =
344 let (envUnhandledMembers, envValues) = partitionEithers xs
345 let (envUnhandledMembers, envValues) = partitionEithers xs
345 envTypeClasses = []
346 envTypeClasses = []
@@ -360,11 +361,11 @@ typeClassesToEnv classes =
360--
361--
361data TypeClassEnv = TypeClassEnv
362data TypeClassEnv = TypeClassEnv
362 { -- |
363 { -- |
363− -- Type class members which have not yet been dealt with. The String is the
364+ -- Type class members which have not yet been dealt with. The Text is the
364 -- name of the type class they belong to, and the constraint is used to
365 -- name of the type class they belong to, and the constraint is used to
365 -- make sure that they have the correct type if they get promoted.
366 -- make sure that they have the correct type if they get promoted.
366 --
367 --
367− envUnhandledMembers :: [(String, P.Constraint, ChildDeclaration)]
368+ envUnhandledMembers :: [(Text, P.Constraint, ChildDeclaration)]
368 -- |
369 -- |
369 -- A list of normal value declarations. Type class members will be added to
370 -- A list of normal value declarations. Type class members will be added to
370 -- this list if their parent type class is not available.
371 -- this list if their parent type class is not available.
@@ -428,7 +429,7 @@ handleEnv TypeClassEnv{..} =
428 _ ->
429 _ ->
429 internalErrorInModule
430 internalErrorInModule
430 ("handleEnv: Bad child declaration passed to promoteChild: "
431 ("handleEnv: Bad child declaration passed to promoteChild: "
431− ++ cdeclTitle)
432+ ++ T.unpack cdeclTitle)
432
433
433 addConstraint constraint =
434 addConstraint constraint =
434 P.quantify . P.moveQuantifiersToFront . P.ConstrainedType [constraint]
435 P.quantify . P.moveQuantifiersToFront . P.ConstrainedType [constraint]
@@ -448,7 +449,7 @@ filterDataConstructors
448 -> Map P.ModuleName [Declaration]
449 -> Map P.ModuleName [Declaration]
449 -> Map P.ModuleName [Declaration]
450 -> Map P.ModuleName [Declaration]
450filterDataConstructors =
451filterDataConstructors =
451− filterExportedChildren isDataConstructor (T.unpack . P.runProperName)
452+ filterExportedChildren isDataConstructor P.runProperName
452
453
453-- |
454-- |
454-- Given a list of exported type class member names, remove any data
455-- Given a list of exported type class member names, remove any data
@@ -460,12 +461,12 @@ filterTypeClassMembers
460 -> Map P.ModuleName [Declaration]
461 -> Map P.ModuleName [Declaration]
461 -> Map P.ModuleName [Declaration]
462 -> Map P.ModuleName [Declaration]
462filterTypeClassMembers =
463filterTypeClassMembers =
463− filterExportedChildren isTypeClassMember (T.unpack . P.showIdent)
464+ filterExportedChildren isTypeClassMember P.showIdent
464
465
465filterExportedChildren
466filterExportedChildren
466 :: (Functor f)
467 :: (Functor f)
467 => (ChildDeclaration -> Bool)
468 => (ChildDeclaration -> Bool)
468− -> (name -> String)
469+ -> (name -> Text)
469 -> [name]
470 -> [name]
470 -> f [Declaration]
471 -> f [Declaration]
471 -> f [Declaration]
472 -> f [Declaration]
@@ -504,7 +505,7 @@ typeClassConstraintFor :: Declaration -> Maybe P.Constraint
504typeClassConstraintFor Declaration{..} =
505typeClassConstraintFor Declaration{..} =
505 case declInfo of
506 case declInfo of
506 TypeClassDeclaration tyArgs _ _ ->
507 TypeClassDeclaration tyArgs _ _ ->
507− Just (P.Constraint (P.Qualified Nothing (P.ProperName (T.pack declTitle))) (mkConstraint (map (first T.pack) tyArgs)) Nothing)
508+ Just (P.Constraint (P.Qualified Nothing (P.ProperName declTitle)) (mkConstraint tyArgs) Nothing)
508 _ ->
509 _ ->
509 Nothing
510 Nothing
510 where
511 where
src/Language/PureScript/Docs/Convert/Single.hs+26−31
@@ -5,13 +5,12 @@ module Language.PureScript.Docs.Convert.Single
5
5
6import Prelude.Compat
6import Prelude.Compat
7
7
8−import Control.Arrow (first)
9import Control.Category ((>>>))
8import Control.Category ((>>>))
10import Control.Monad
9import Control.Monad
11
10
12import Data.Either
11import Data.Either
13import Data.List (nub)
12import Data.List (nub)
14−import Data.Maybe (mapMaybe)
13+import Data.Maybe (mapMaybe, fromMaybe)
15import Data.Monoid ((<>))
14import Data.Monoid ((<>))
16import Data.Text (Text)
15import Data.Text (Text)
17import qualified Data.Text as T
16import qualified Data.Text as T
@@ -19,8 +18,6 @@ import qualified Data.Text as T
19import Language.PureScript.Docs.Types
18import Language.PureScript.Docs.Types
20import qualified Language.PureScript as P
19import qualified Language.PureScript as P
21
20
22−-- TODO (Christoph): Get rid of the T.unpack s
23−
24-- |
21-- |
25-- Convert a single Module, but ignore re-exports; any re-exported types or
22-- Convert a single Module, but ignore re-exports; any re-exported types or
26-- values will not appear in the result.
23-- values will not appear in the result.
@@ -46,14 +43,14 @@ convertSingleModule m@(P.Module _ coms moduleName _ _) =
46-- In the second pass, we go over all of the Left values and augment the
43-- In the second pass, we go over all of the Left values and augment the
47-- relevant declarations, leaving only the augmented Right values.
44-- relevant declarations, leaving only the augmented Right values.
48--
45--
49−-- Note that in the Left case, we provide a [String] as well as augment
46+-- Note that in the Left case, we provide a [Text] as well as augment
50−-- information. The [String] value should be a list of titles of declarations
47+-- information. The [Text] value should be a list of titles of declarations
51-- that the augmentation should apply to. For example, for a type instance
48-- that the augmentation should apply to. For example, for a type instance
52-- declaration, that would be any types or type classes mentioned in the
49-- declaration, that would be any types or type classes mentioned in the
53-- instance. For a fixity declaration, it would be just the relevant operator's
50-- instance. For a fixity declaration, it would be just the relevant operator's
54-- name.
51-- name.
55type IntermediateDeclaration
52type IntermediateDeclaration
56− = Either ([String], DeclarationAugment) Declaration
53+ = Either ([Text], DeclarationAugment) Declaration
57
54
58-- | Some data which will be used to augment a Declaration in the
55-- | Some data which will be used to augment a Declaration in the
59-- output.
56-- output.
@@ -97,7 +94,7 @@ getDeclarationTitle _ = Nothing
97-- | Create a basic Declaration value.
94-- | Create a basic Declaration value.
98mkDeclaration :: Text -> DeclarationInfo -> Declaration
95mkDeclaration :: Text -> DeclarationInfo -> Declaration
99mkDeclaration title info =
96mkDeclaration title info =
100− Declaration { declTitle = T.unpack title
97+ Declaration { declTitle = title
101 , declComments = Nothing
98 , declComments = Nothing
102 , declSourceSpan = Nothing
99 , declSourceSpan = Nothing
103 , declChildren = []
100 , declChildren = []
@@ -119,27 +116,27 @@ convertDeclaration (P.ExternDeclaration _ ty) title =
119convertDeclaration (P.DataDeclaration dtype _ args ctors) title =
116convertDeclaration (P.DataDeclaration dtype _ args ctors) title =
120 Just (Right (mkDeclaration title info) { declChildren = children })
117 Just (Right (mkDeclaration title info) { declChildren = children })
121 where
118 where
122− info = DataDeclaration dtype (map (first T.unpack) args)
119+ info = DataDeclaration dtype args
123 children = map convertCtor ctors
120 children = map convertCtor ctors
124 convertCtor (ctor', tys) =
121 convertCtor (ctor', tys) =
125− ChildDeclaration (T.unpack (P.runProperName ctor')) Nothing Nothing (ChildDataConstructor tys)
122+ ChildDeclaration (P.runProperName ctor') Nothing Nothing (ChildDataConstructor tys)
126convertDeclaration (P.ExternDataDeclaration _ kind') title =
123convertDeclaration (P.ExternDataDeclaration _ kind') title =
127 basicDeclaration title (ExternDataDeclaration kind')
124 basicDeclaration title (ExternDataDeclaration kind')
128convertDeclaration (P.TypeSynonymDeclaration _ args ty) title =
125convertDeclaration (P.TypeSynonymDeclaration _ args ty) title =
129− basicDeclaration title (TypeSynonymDeclaration (map (first T.unpack) args) ty)
126+ basicDeclaration title (TypeSynonymDeclaration args ty)
130convertDeclaration (P.TypeClassDeclaration _ args implies fundeps ds) title =
127convertDeclaration (P.TypeClassDeclaration _ args implies fundeps ds) title =
131 Just (Right (mkDeclaration title info) { declChildren = children })
128 Just (Right (mkDeclaration title info) { declChildren = children })
132 where
129 where
133− info = TypeClassDeclaration (map (first T.unpack) args) implies (convertFundepsToStrings args fundeps)
130+ info = TypeClassDeclaration args implies (convertFundepsToStrings args fundeps)
134 children = map convertClassMember ds
131 children = map convertClassMember ds
135 convertClassMember (P.PositionedDeclaration _ _ d) =
132 convertClassMember (P.PositionedDeclaration _ _ d) =
136 convertClassMember d
133 convertClassMember d
137 convertClassMember (P.TypeDeclaration ident' ty) =
134 convertClassMember (P.TypeDeclaration ident' ty) =
138− ChildDeclaration (T.unpack (P.showIdent ident')) Nothing Nothing (ChildTypeClassMember ty)
135+ ChildDeclaration (P.showIdent ident') Nothing Nothing (ChildTypeClassMember ty)
139 convertClassMember _ =
136 convertClassMember _ =
140 P.internalError "convertDeclaration: Invalid argument to convertClassMember."
137 P.internalError "convertDeclaration: Invalid argument to convertClassMember."
141convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) title =
138convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) title =
142− Just (Left (T.unpack classNameString : map T.unpack typeNameStrings, AugmentChild childDecl))
139+ Just (Left (classNameString : typeNameStrings, AugmentChild childDecl))
143 where
140 where
144 classNameString = unQual className
141 classNameString = unQual className
145 typeNameStrings = nub (concatMap (P.everythingOnTypes (++) extractProperNames) tys)
142 typeNameStrings = nub (concatMap (P.everythingOnTypes (++) extractProperNames) tys)
@@ -148,7 +145,7 @@ convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) tit
148 extractProperNames (P.TypeConstructor n) = [unQual n]
145 extractProperNames (P.TypeConstructor n) = [unQual n]
149 extractProperNames _ = []
146 extractProperNames _ = []
150
147
151− childDecl = ChildDeclaration (T.unpack title) Nothing Nothing (ChildInstance constraints classApp)
148+ childDecl = ChildDeclaration title Nothing Nothing (ChildInstance constraints classApp)
152 classApp = foldl P.TypeApp (P.TypeConstructor (fmap P.coerceProperName className)) tys
149 classApp = foldl P.TypeApp (P.TypeConstructor (fmap P.coerceProperName className)) tys
153convertDeclaration (P.ValueFixityDeclaration fixity (P.Qualified mn alias) _) title =
150convertDeclaration (P.ValueFixityDeclaration fixity (P.Qualified mn alias) _) title =
154 Just $ Right $ mkDeclaration title (AliasDeclaration fixity (P.Qualified mn (Right alias)))
151 Just $ Right $ mkDeclaration title (AliasDeclaration fixity (P.Qualified mn (Right alias)))
@@ -172,25 +169,24 @@ convertDeclaration (P.PositionedDeclaration srcSpan com d') title =
172 withAugmentChild f (t, AugmentChild d) = (t, AugmentChild (f d))
169 withAugmentChild f (t, AugmentChild d) = (t, AugmentChild (f d))
173convertDeclaration _ _ = Nothing
170convertDeclaration _ _ = Nothing
174
171
175−convertComments :: [P.Comment] -> Maybe String
172+convertComments :: [P.Comment] -> Maybe Text
176convertComments cs = do
173convertComments cs = do
177 let raw = concatMap toLines cs
174 let raw = concatMap toLines cs
178 let docs = mapMaybe stripPipe raw
175 let docs = mapMaybe stripPipe raw
179 guard (not (null docs))
176 guard (not (null docs))
180− pure (unlines docs)
177+ pure (T.unlines docs)
181
178
182 where
179 where
183− toLines (P.LineComment s) = [T.unpack s]
180+ toLines (P.LineComment s) = [s]
184− toLines (P.BlockComment s) = lines (T.unpack s)
181+ toLines (P.BlockComment s) = T.lines s
185−
182+
186− stripPipe s' =
183+ stripPipe =
187− case dropWhile (== ' ') s' of
184+ T.dropWhile (== ' ')
188− ('|':' ':s) ->
185+ >>> T.stripPrefix "|"
189− Just s
186+ >>> fmap (dropPrefix " ")
190− ('|':s) ->
187+
191− Just s
188+ dropPrefix prefix str =
192− _ ->
189+ fromMaybe str (T.stripPrefix prefix str)
193− Nothing
194
190
195-- | Go through a PureScript module and extract a list of Bookmarks; references
191-- | Go through a PureScript module and extract a list of Bookmarks; references
196-- to data types or values, to be used as a kind of index. These are used for
192-- to data types or values, to be used as a kind of index. These are used for
@@ -199,8 +195,7 @@ collectBookmarks :: InPackage P.Module -> [Bookmark]
199collectBookmarks (Local m) = map Local (collectBookmarks' m)
195collectBookmarks (Local m) = map Local (collectBookmarks' m)
200collectBookmarks (FromDep pkg m) = map (FromDep pkg) (collectBookmarks' m)
196collectBookmarks (FromDep pkg m) = map (FromDep pkg) (collectBookmarks' m)
201
197
202−collectBookmarks' :: P.Module -> [(P.ModuleName, String)]
198+collectBookmarks' :: P.Module -> [(P.ModuleName, Text)]
203collectBookmarks' m =
199collectBookmarks' m =
204 map (P.getModuleName m, )
200 map (P.getModuleName m, )
205− (mapMaybe (fmap T.unpack . getDeclarationTitle)
201+ (mapMaybe getDeclarationTitle (P.exportedDeclarations m))
206− (P.exportedDeclarations m))
src/Language/PureScript/Docs/Prim.hs+22−22
@@ -2,7 +2,7 @@
2module Language.PureScript.Docs.Prim (primDocsModule) where
2module Language.PureScript.Docs.Prim (primDocsModule) where
3
3
4import Prelude.Compat hiding (fail)
4import Prelude.Compat hiding (fail)
5−import Control.Arrow (first)
5+import Data.Text (Text)
6import qualified Data.Text as T
6import qualified Data.Text as T
7import qualified Data.Map as Map
7import qualified Data.Map as Map
8import Language.PureScript.Docs.Types
8import Language.PureScript.Docs.Types
@@ -30,18 +30,18 @@ primDocsModule = Module
30 }
30 }
31
31
32unsafeLookup :: forall v (a :: P.ProperNameType).
32unsafeLookup :: forall v (a :: P.ProperNameType).
33− Map.Map (P.Qualified (P.ProperName a)) v -> String -> String -> v
33+ Map.Map (P.Qualified (P.ProperName a)) v -> String -> Text -> v
34−unsafeLookup m errorMsg ty = go ty
34+unsafeLookup m errorMsg name = go name
35 where
35 where
36− go = fromJust' . flip Map.lookup m . P.primName . T.pack
36+ go = fromJust' . flip Map.lookup m . P.primName
37
37
38 fromJust' (Just x) = x
38 fromJust' (Just x) = x
39− fromJust' _ = P.internalError $ errorMsg ++ ty
39+ fromJust' _ = P.internalError $ errorMsg ++ show name
40
40
41−lookupPrimKind :: String -> P.Kind
41+lookupPrimKind :: Text -> P.Kind
42lookupPrimKind = fst . unsafeLookup P.primTypes "Docs.Prim: No such Prim type: "
42lookupPrimKind = fst . unsafeLookup P.primTypes "Docs.Prim: No such Prim type: "
43
43
44−primType :: String -> String -> Declaration
44+primType :: Text -> Text -> Declaration
45primType title comments = Declaration
45primType title comments = Declaration
46 { declTitle = title
46 { declTitle = title
47 , declComments = Just comments
47 , declComments = Just comments
@@ -52,10 +52,10 @@ primType title comments = Declaration
52
52
53-- | Lookup the TypeClassData of a Prim class. This function is specifically
53-- | Lookup the TypeClassData of a Prim class. This function is specifically
54-- not exported because it is partial.
54-- not exported because it is partial.
55−lookupPrimClass :: String -> P.TypeClassData
55+lookupPrimClass :: Text -> P.TypeClassData
56lookupPrimClass = unsafeLookup P.primClasses "Docs.Prim: No such Prim class: "
56lookupPrimClass = unsafeLookup P.primClasses "Docs.Prim: No such Prim class: "
57
57
58−primClass :: String -> String -> Declaration
58+primClass :: Text -> Text -> Declaration
59primClass title comments = Declaration
59primClass title comments = Declaration
60 { declTitle = title
60 { declTitle = title
61 , declComments = Just comments
61 , declComments = Just comments
@@ -68,11 +68,11 @@ primClass title comments = Declaration
68 superclasses = P.typeClassSuperclasses tcd
68 superclasses = P.typeClassSuperclasses tcd
69 fundeps = convertFundepsToStrings args (P.typeClassDependencies tcd)
69 fundeps = convertFundepsToStrings args (P.typeClassDependencies tcd)
70 in
70 in
71− TypeClassDeclaration (map (first T.unpack) args) superclasses fundeps
71+ TypeClassDeclaration args superclasses fundeps
72 }
72 }
73
73
74function :: Declaration
74function :: Declaration
75−function = primType "Function" $ unlines
75+function = primType "Function" $ T.unlines
76 [ "A function, which takes values of the type specified by the first type"
76 [ "A function, which takes values of the type specified by the first type"
77 , "parameter, and returns values of the type specified by the second."
77 , "parameter, and returns values of the type specified by the second."
78 , "In the JavaScript backend, this is a standard JavaScript Function."
78 , "In the JavaScript backend, this is a standard JavaScript Function."
@@ -91,7 +91,7 @@ function = primType "Function" $ unlines
91 ]
91 ]
92
92
93array :: Declaration
93array :: Declaration
94−array = primType "Array" $ unlines
94+array = primType "Array" $ T.unlines
95 [ "An Array: a data structure supporting efficient random access. In"
95 [ "An Array: a data structure supporting efficient random access. In"
96 , "the JavaScript backend, values of this type are represented as JavaScript"
96 , "the JavaScript backend, values of this type are represented as JavaScript"
97 , "Arrays at runtime."
97 , "Arrays at runtime."
@@ -102,7 +102,7 @@ array = primType "Array" $ unlines
102 ]
102 ]
103
103
104record :: Declaration
104record :: Declaration
105−record = primType "Record" $ unlines
105+record = primType "Record" $ T.unlines
106 [ "The type of records whose fields are known at compile time. In the"
106 [ "The type of records whose fields are known at compile time. In the"
107 , "JavaScript backend, values of this type are represented as JavaScript"
107 , "JavaScript backend, values of this type are represented as JavaScript"
108 , "Objects at runtime."
108 , "Objects at runtime."
@@ -118,7 +118,7 @@ record = primType "Record" $ unlines
118 ]
118 ]
119
119
120number :: Declaration
120number :: Declaration
121−number = primType "Number" $ unlines
121+number = primType "Number" $ T.unlines
122 [ "A double precision floating point number (IEEE 754)."
122 [ "A double precision floating point number (IEEE 754)."
123 , ""
123 , ""
124 , "Construct values of this type with literals:"
124 , "Construct values of this type with literals:"
@@ -128,7 +128,7 @@ number = primType "Number" $ unlines
128 ]
128 ]
129
129
130int :: Declaration
130int :: Declaration
131−int = primType "Int" $ unlines
131+int = primType "Int" $ T.unlines
132 [ "A 32-bit signed integer. See the purescript-integers package for details"
132 [ "A 32-bit signed integer. See the purescript-integers package for details"
133 , "of how this is accomplished when compiling to JavaScript."
133 , "of how this is accomplished when compiling to JavaScript."
134 , ""
134 , ""
@@ -138,7 +138,7 @@ int = primType "Int" $ unlines
138 ]
138 ]
139
139
140string :: Declaration
140string :: Declaration
141−string = primType "String" $ unlines
141+string = primType "String" $ T.unlines
142 [ "A String. As in JavaScript, String values represent sequences of UTF-16"
142 [ "A String. As in JavaScript, String values represent sequences of UTF-16"
143 , "code units, which are not required to form a valid encoding of Unicode"
143 , "code units, which are not required to form a valid encoding of Unicode"
144 , "text (for example, lone surrogates are permitted)."
144 , "text (for example, lone surrogates are permitted)."
@@ -151,7 +151,7 @@ string = primType "String" $ unlines
151 ]
151 ]
152
152
153char :: Declaration
153char :: Declaration
154−char = primType "Char" $ unlines
154+char = primType "Char" $ T.unlines
155 [ "A single character (UTF-16 code unit). The JavaScript representation is a"
155 [ "A single character (UTF-16 code unit). The JavaScript representation is a"
156 , "normal String, which is guaranteed to contain one code unit. This means"
156 , "normal String, which is guaranteed to contain one code unit. This means"
157 , "that astral plane characters (i.e. those with code point values greater"
157 , "that astral plane characters (i.e. those with code point values greater"
@@ -163,14 +163,14 @@ char = primType "Char" $ unlines
163 ]
163 ]
164
164
165boolean :: Declaration
165boolean :: Declaration
166−boolean = primType "Boolean" $ unlines
166+boolean = primType "Boolean" $ T.unlines
167 [ "A JavaScript Boolean value."
167 [ "A JavaScript Boolean value."
168 , ""
168 , ""
169 , "Construct values of this type with the literals `true` and `false`."
169 , "Construct values of this type with the literals `true` and `false`."
170 ]
170 ]
171
171
172partial :: Declaration
172partial :: Declaration
173−partial = primClass "Partial" $ unlines
173+partial = primClass "Partial" $ T.unlines
174 [ "The Partial type class is used to indicate that a function is *partial,*"
174 [ "The Partial type class is used to indicate that a function is *partial,*"
175 , "that is, it is not defined for all inputs. In practice, attempting to use"
175 , "that is, it is not defined for all inputs. In practice, attempting to use"
176 , "a partial function with a bad input will usually cause an error to be"
176 , "a partial function with a bad input will usually cause an error to be"
@@ -180,7 +180,7 @@ partial = primClass "Partial" $ unlines
180 ]
180 ]
181
181
182fail :: Declaration
182fail :: Declaration
183−fail = primClass "Fail" $ unlines
183+fail = primClass "Fail" $ T.unlines
184 [ "The Fail type class is part of the custom type errors feature. To provide"
184 [ "The Fail type class is part of the custom type errors feature. To provide"
185 , "a custom type error when someone tries to use a particular instance,"
185 , "a custom type error when someone tries to use a particular instance,"
186 , "write that instance out with a Fail constraint."
186 , "write that instance out with a Fail constraint."
@@ -190,7 +190,7 @@ fail = primClass "Fail" $ unlines
190 ]
190 ]
191
191
192typeConcat :: Declaration
192typeConcat :: Declaration
193−typeConcat = primType "TypeConcat" $ unlines
193+typeConcat = primType "TypeConcat" $ T.unlines
194 [ "The TypeConcat type constructor concatenates two Symbols in a custom type"
194 [ "The TypeConcat type constructor concatenates two Symbols in a custom type"
195 , "error."
195 , "error."
196 , ""
196 , ""
@@ -199,7 +199,7 @@ typeConcat = primType "TypeConcat" $ unlines
199 ]
199 ]
200
200
201typeString :: Declaration
201typeString :: Declaration
202−typeString = primType "TypeString" $ unlines
202+typeString = primType "TypeString" $ T.unlines
203 [ "The TypeString type constructor renders any concrete type into a Symbol"
203 [ "The TypeString type constructor renders any concrete type into a Symbol"
204 , "in a custom type error."
204 , "in a custom type error."
205 , ""
205 , ""
src/Language/PureScript/Docs/Render.hs+13−16
@@ -13,16 +13,14 @@ import Prelude.Compat
13
13
14import Data.Maybe (maybeToList)
14import Data.Maybe (maybeToList)
15import Data.Monoid ((<>))
15import Data.Monoid ((<>))
16−import qualified Data.Text as T
17import Data.Text (Text)
16import Data.Text (Text)
17+import qualified Data.Text as T
18
18
19import Language.PureScript.Docs.RenderedCode
19import Language.PureScript.Docs.RenderedCode
20import Language.PureScript.Docs.Types
20import Language.PureScript.Docs.Types
21import Language.PureScript.Docs.Utils.MonoidExtras
21import Language.PureScript.Docs.Utils.MonoidExtras
22import qualified Language.PureScript as P
22import qualified Language.PureScript as P
23
23
24−-- TODO (Christoph): get rid of T.unpack's
25−
26renderDeclaration :: Declaration -> RenderedCode
24renderDeclaration :: Declaration -> RenderedCode
27renderDeclaration = renderDeclarationWithOptions defaultRenderTypeOptions
25renderDeclaration = renderDeclarationWithOptions defaultRenderTypeOptions
28
26
@@ -35,7 +33,7 @@ renderDeclarationWithOptions opts Declaration{..} =
35 , renderType' ty
33 , renderType' ty
36 ]
34 ]
37 DataDeclaration dtype args ->
35 DataDeclaration dtype args ->
38− [ keyword (T.unpack (P.showDataDeclType dtype))
36+ [ keyword (P.showDataDeclType dtype)
39 , renderType' (typeApp declTitle args)
37 , renderType' (typeApp declTitle args)
40 ]
38 ]
41 ExternDataDeclaration kind' ->
39 ExternDataDeclaration kind' ->
@@ -76,7 +74,7 @@ renderDeclarationWithOptions opts Declaration{..} =
76
74
77 AliasDeclaration (P.Fixity associativity precedence) for@(P.Qualified _ alias) ->
75 AliasDeclaration (P.Fixity associativity precedence) for@(P.Qualified _ alias) ->
78 [ keywordFixity associativity
76 [ keywordFixity associativity
79− , syntax $ show precedence
77+ , syntax $ T.pack $ show precedence
80 , ident $ renderQualAlias for
78 , ident $ renderQualAlias for
81 , keyword "as"
79 , keyword "as"
82 , ident $ adjustAliasName alias declTitle
80 , ident $ adjustAliasName alias declTitle
@@ -86,10 +84,10 @@ renderDeclarationWithOptions opts Declaration{..} =
86 renderType' :: P.Type -> RenderedCode
84 renderType' :: P.Type -> RenderedCode
87 renderType' = renderTypeWithOptions opts
85 renderType' = renderTypeWithOptions opts
88
86
89− renderQualAlias :: FixityAlias -> String
87+ renderQualAlias :: FixityAlias -> Text
90 renderQualAlias (P.Qualified mn alias)
88 renderQualAlias (P.Qualified mn alias)
91− | mn == currentModule opts = T.unpack (renderAlias id alias)
89+ | mn == currentModule opts = renderAlias id alias
92− | otherwise = T.unpack (renderAlias (\f -> P.showQualified f . P.Qualified mn) alias)
90+ | otherwise = renderAlias (\f -> P.showQualified f . P.Qualified mn) alias
93
91
94 renderAlias
92 renderAlias
95 :: (forall a. (a -> Text) -> a -> Text)
93 :: (forall a. (a -> Text) -> a -> Text)
@@ -99,8 +97,7 @@ renderDeclarationWithOptions opts Declaration{..} =
99 = either (("type " <>) . f P.runProperName)
97 = either (("type " <>) . f P.runProperName)
100 $ either (f P.runIdent) (f P.runProperName)
98 $ either (f P.runIdent) (f P.runProperName)
101
99
102− -- adjustAliasName (P.AliasType{}) title = drop 6 (init title)
103− adjustAliasName _ title = tail (init title)
100+ adjustAliasName _ title = T.tail (T.init title)
104
101
105renderChildDeclaration :: ChildDeclaration -> RenderedCode
102renderChildDeclaration :: ChildDeclaration -> RenderedCode
106renderChildDeclaration = renderChildDeclarationWithOptions defaultRenderTypeOptions
103renderChildDeclaration = renderChildDeclarationWithOptions defaultRenderTypeOptions
@@ -146,15 +143,15 @@ renderConstraintsWithOptions opts constraints
146 mintersperse (syntax "," <> sp)
143 mintersperse (syntax "," <> sp)
147 (map (renderConstraintWithOptions opts) constraints)
144 (map (renderConstraintWithOptions opts) constraints)
148
145
149−notQualified :: String -> P.Qualified (P.ProperName a)
146+notQualified :: Text -> P.Qualified (P.ProperName a)
150−notQualified = P.Qualified Nothing . P.ProperName . T.pack
147+notQualified = P.Qualified Nothing . P.ProperName
151
148
152−typeApp :: String -> [(String, Maybe P.Kind)] -> P.Type
149+typeApp :: Text -> [(Text, Maybe P.Kind)] -> P.Type
153typeApp title typeArgs =
150typeApp title typeArgs =
154 foldl P.TypeApp
151 foldl P.TypeApp
155 (P.TypeConstructor (notQualified title))
152 (P.TypeConstructor (notQualified title))
156 (map toTypeVar typeArgs)
153 (map toTypeVar typeArgs)
157
154
158−toTypeVar :: (String, Maybe P.Kind) -> P.Type
155+toTypeVar :: (Text, Maybe P.Kind) -> P.Type
159−toTypeVar (s, Nothing) = P.TypeVar (T.pack s)
156+toTypeVar (s, Nothing) = P.TypeVar s
160−toTypeVar (s, Just k) = P.KindedType (P.TypeVar (T.pack s)) k
157+toTypeVar (s, Just k) = P.KindedType (P.TypeVar s) k
src/Language/PureScript/Docs/RenderedCode/Render.hs+10−13
@@ -14,10 +14,9 @@ import Prelude.Compat
14
14
15import Data.Maybe (fromMaybe)
15import Data.Maybe (fromMaybe)
16import Data.Monoid ((<>))
16import Data.Monoid ((<>))
17−import qualified Data.Text as T
18import Data.Text (Text)
17import Data.Text (Text)
19
18
20−import Control.Arrow ((<+>), first)
19+import Control.Arrow ((<+>))
21import Control.PatternArrows as PA
20import Control.PatternArrows as PA
22
21
23import Language.PureScript.Crash
22import Language.PureScript.Crash
@@ -35,7 +34,7 @@ typeLiterals = mkPattern match
35 match TypeWildcard{} =
34 match TypeWildcard{} =
36 Just (syntax "_")
35 Just (syntax "_")
37 match (TypeVar var) =
36 match (TypeVar var) =
38− Just (ident (T.unpack var))
37+ Just (ident var)
39 match (PrettyPrintObject row) =
38 match (PrettyPrintObject row) =
40 Just $ mintersperse sp
39 Just $ mintersperse sp
41 [ syntax "{"
40 [ syntax "{"
@@ -43,7 +42,7 @@ typeLiterals = mkPattern match
43 , syntax "}"
42 , syntax "}"
44 ]
43 ]
45 match (TypeConstructor (Qualified mn name)) =
44 match (TypeConstructor (Qualified mn name)) =
46− Just (ctor (T.unpack (runProperName name)) (maybeToContainingModule mn))
45+ Just (ctor (runProperName name) (maybeToContainingModule mn))
47 match REmpty =
46 match REmpty =
48 Just (syntax "()")
47 Just (syntax "()")
49 match row@RCons{} =
48 match row@RCons{} =
@@ -51,7 +50,7 @@ typeLiterals = mkPattern match
51 match (BinaryNoParensType op l r) =
50 match (BinaryNoParensType op l r) =
52 Just $ renderTypeAtom l <> sp <> renderTypeAtom op <> sp <> renderTypeAtom r
51 Just $ renderTypeAtom l <> sp <> renderTypeAtom op <> sp <> renderTypeAtom r
53 match (TypeOp (Qualified mn op)) =
52 match (TypeOp (Qualified mn op)) =
54− Just (ident' (T.unpack (runOpName op)) (maybeToContainingModule mn))
53+ Just (ident' (runOpName op) (maybeToContainingModule mn))
55 match _ =
54 match _ =
56 Nothing
55 Nothing
57
56
@@ -76,16 +75,14 @@ renderConstraints deps ty =
76-- Render code representing a Row
75-- Render code representing a Row
77--
76--
78renderRow :: Type -> RenderedCode
77renderRow :: Type -> RenderedCode
79−renderRow = uncurry renderRow' . convertString . rowToList
78+renderRow = uncurry renderRow' . rowToList
80 where
79 where
81− convertString :: ([(Text, Type)], Type) -> ([(String, Type)], Type)
82− convertString = first (map (first T.unpack))
83 renderRow' h t = renderHead h <> renderTail t
80 renderRow' h t = renderHead h <> renderTail t
84
81
85−renderHead :: [(String, Type)] -> RenderedCode
82+renderHead :: [(Text, Type)] -> RenderedCode
86renderHead = mintersperse (syntax "," <> sp) . map renderLabel
83renderHead = mintersperse (syntax "," <> sp) . map renderLabel
87
84
88−renderLabel :: (String, Type) -> RenderedCode
85+renderLabel :: (Text, Type) -> RenderedCode
89renderLabel (label, ty) =
86renderLabel (label, ty) =
90 mintersperse sp
87 mintersperse sp
91 [ ident label
88 [ ident label
@@ -145,10 +142,10 @@ matchType = buildPrettyPrinter operators matchTypeAtom
145 , [ Wrap explicitParens $ \_ ty -> ty ]
142 , [ Wrap explicitParens $ \_ ty -> ty ]
146 ]
143 ]
147
144
148−forall_ :: Pattern () Type ([String], Type)
145+forall_ :: Pattern () Type ([Text], Type)
149forall_ = mkPattern match
146forall_ = mkPattern match
150 where
147 where
151− match (PrettyPrintForAll idents ty) = Just (map T.unpack idents, ty)
148+ match (PrettyPrintForAll idents ty) = Just (idents, ty)
152 match _ = Nothing
149 match _ = Nothing
153
150
154insertPlaceholders :: RenderTypeOptions -> Type -> Type
151insertPlaceholders :: RenderTypeOptions -> Type -> Type
@@ -180,7 +177,7 @@ preprocessType opts = dePrim . insertPlaceholders opts
180-- Render code representing a Kind
177-- Render code representing a Kind
181--
178--
182renderKind :: Kind -> RenderedCode
179renderKind :: Kind -> RenderedCode
183−renderKind = kind . T.unpack . prettyPrintKind
180+renderKind = kind . prettyPrintKind
184
181
185-- |
182-- |
186-- Render code representing a Type, as it should appear inside parentheses
183-- Render code representing a Type, as it should appear inside parentheses
src/Language/PureScript/Docs/RenderedCode/Types.hs+21−21
@@ -37,7 +37,7 @@ import Control.Monad.Error.Class (MonadError(..))
37
37
38import Data.Aeson.BetterErrors
38import Data.Aeson.BetterErrors
39import qualified Data.Aeson as A
39import qualified Data.Aeson as A
40−import qualified Data.Text as T
40+import Data.Text (Text)
41
41
42import qualified Language.PureScript as P
42import qualified Language.PureScript as P
43
43
@@ -46,11 +46,11 @@ import qualified Language.PureScript as P
46-- multiple output formats. For example, plain text, or highlighted HTML.
46-- multiple output formats. For example, plain text, or highlighted HTML.
47--
47--
48data RenderedCodeElement
48data RenderedCodeElement
49− = Syntax String
49+ = Syntax Text
50− | Ident String ContainingModule
50+ | Ident Text ContainingModule
51− | Ctor String ContainingModule
51+ | Ctor Text ContainingModule
52− | Kind String
52+ | Kind Text
53− | Keyword String
53+ | Keyword Text
54 | Space
54 | Space
55 deriving (Show, Eq, Ord)
55 deriving (Show, Eq, Ord)
56
56
@@ -66,9 +66,9 @@ instance A.ToJSON RenderedCodeElement where
66 toJSON (Keyword str) =
66 toJSON (Keyword str) =
67 A.toJSON ["keyword", str]
67 A.toJSON ["keyword", str]
68 toJSON Space =
68 toJSON Space =
69− A.toJSON ["space" :: String]
69+ A.toJSON ["space" :: Text]
70
70
71−asRenderedCodeElement :: Parse String RenderedCodeElement
71+asRenderedCodeElement :: Parse Text RenderedCodeElement
72asRenderedCodeElement =
72asRenderedCodeElement =
73 a Syntax "syntax" <|>
73 a Syntax "syntax" <|>
74 asIdent <|>
74 asIdent <|>
@@ -80,14 +80,14 @@ asRenderedCodeElement =
80 where
80 where
81 p <|> q = catchError p (const q)
81 p <|> q = catchError p (const q)
82
82
83− a ctor' ctorStr = ctor' <$> (nth 0 (withString (eq ctorStr)) *> nth 1 asString)
83+ a ctor' ctorStr = ctor' <$> (nth 0 (withText (eq ctorStr)) *> nth 1 asText)
84− asIdent = nth 0 (withString (eq "ident")) *> (Ident <$> nth 1 asString <*> nth 2 asContainingModule)
84+ asIdent = nth 0 (withText (eq "ident")) *> (Ident <$> nth 1 asText <*> nth 2 asContainingModule)
85− asCtor = nth 0 (withString (eq "ctor")) *> (Ctor <$> nth 1 asString <*> nth 2 asContainingModule)
85+ asCtor = nth 0 (withText (eq "ctor")) *> (Ctor <$> nth 1 asText <*> nth 2 asContainingModule)
86− asSpace = nth 0 (withString (eq "space")) *> pure Space
86+ asSpace = nth 0 (withText (eq "space")) *> pure Space
87
87
88 eq s s' = if s == s' then Right () else Left ""
88 eq s s' = if s == s' then Right () else Left ""
89
89
90− unableToParse = withString (Left . show)
90+ unableToParse = withText Left
91
91
92-- |
92-- |
93-- This type is isomorphic to 'Maybe' 'P.ModuleName'. It makes code a bit easier
93-- This type is isomorphic to 'Maybe' 'P.ModuleName'. It makes code a bit easier
@@ -103,7 +103,7 @@ instance A.ToJSON ContainingModule where
103
103
104asContainingModule :: Parse e ContainingModule
104asContainingModule :: Parse e ContainingModule
105asContainingModule =
105asContainingModule =
106− maybeToContainingModule <$> perhaps (P.moduleNameFromString . T.pack <$> asString)
106+ maybeToContainingModule <$> perhaps (P.moduleNameFromString <$> asText)
107
107
108-- |
108-- |
109-- Convert a 'Maybe' 'P.ModuleName' to a 'ContainingModule', using the obvious
109-- Convert a 'Maybe' 'P.ModuleName' to a 'ContainingModule', using the obvious
@@ -139,7 +139,7 @@ newtype RenderedCode
139instance A.ToJSON RenderedCode where
139instance A.ToJSON RenderedCode where
140 toJSON (RC elems) = A.toJSON elems
140 toJSON (RC elems) = A.toJSON elems
141
141
142−asRenderedCode :: Parse String RenderedCode
142+asRenderedCode :: Parse Text RenderedCode
143asRenderedCode = RC <$> eachInArray asRenderedCodeElement
143asRenderedCode = RC <$> eachInArray asRenderedCodeElement
144
144
145-- |
145-- |
@@ -157,22 +157,22 @@ outputWith f = foldMap f . unRC
157sp :: RenderedCode
157sp :: RenderedCode
158sp = RC [Space]
158sp = RC [Space]
159
159
160−syntax :: String -> RenderedCode
160+syntax :: Text -> RenderedCode
161syntax x = RC [Syntax x]
161syntax x = RC [Syntax x]
162
162
163−ident :: String -> RenderedCode
163+ident :: Text -> RenderedCode
164ident x = RC [Ident x ThisModule]
164ident x = RC [Ident x ThisModule]
165
165
166−ident' :: String -> ContainingModule -> RenderedCode
166+ident' :: Text -> ContainingModule -> RenderedCode
167ident' x m = RC [Ident x m]
167ident' x m = RC [Ident x m]
168
168
169−ctor :: String -> ContainingModule -> RenderedCode
169+ctor :: Text -> ContainingModule -> RenderedCode
170ctor x m = RC [Ctor x m]
170ctor x m = RC [Ctor x m]
171
171
172−kind :: String -> RenderedCode
172+kind :: Text -> RenderedCode
173kind x = RC [Kind x]
173kind x = RC [Kind x]
174
174
175−keyword :: String -> RenderedCode
175+keyword :: Text -> RenderedCode
176keyword kw = RC [Keyword kw]
176keyword kw = RC [Keyword kw]
177
177
178keywordForall :: RenderedCode
178keywordForall :: RenderedCode
src/Language/PureScript/Docs/Types.hs+44−46
@@ -9,12 +9,11 @@ import Prelude.Compat
9import Control.Arrow (first, (***))
9import Control.Arrow (first, (***))
10import Control.Monad (when)
10import Control.Monad (when)
11
11
12−import Data.Bifunctor (bimap)
13import Data.Aeson ((.=))
12import Data.Aeson ((.=))
14import Data.Aeson.BetterErrors
13import Data.Aeson.BetterErrors
15import Data.ByteString.Lazy (ByteString)
14import Data.ByteString.Lazy (ByteString)
16import Data.Either (isLeft, isRight)
15import Data.Either (isLeft, isRight)
17−import Data.Maybe (mapMaybe)
16+import Data.Maybe (mapMaybe, fromMaybe)
18import Data.Text (Text)
17import Data.Text (Text)
19import Data.Version
18import Data.Version
20import qualified Data.Vector as V
19import qualified Data.Vector as V
@@ -38,7 +37,7 @@ import Language.PureScript.Docs.RenderedCode as ReExports
38data Package a = Package
37data Package a = Package
39 { pkgMeta :: PackageMeta
38 { pkgMeta :: PackageMeta
40 , pkgVersion :: Version
39 , pkgVersion :: Version
41− , pkgVersionTag :: String
40+ , pkgVersionTag :: Text
42 , pkgModules :: [Module]
41 , pkgModules :: [Module]
43 , pkgBookmarks :: [Bookmark]
42 , pkgBookmarks :: [Bookmark]
44 , pkgResolvedDependencies :: [(PackageName, Version)]
43 , pkgResolvedDependencies :: [(PackageName, Version)]
@@ -73,7 +72,7 @@ packageName = bowerName . pkgMeta
73
72
74data Module = Module
73data Module = Module
75 { modName :: P.ModuleName
74 { modName :: P.ModuleName
76− , modComments :: Maybe String
75+ , modComments :: Maybe Text
77 , modDeclarations :: [Declaration]
76 , modDeclarations :: [Declaration]
78 -- Re-exported values from other modules
77 -- Re-exported values from other modules
79 , modReExports :: [(P.ModuleName, [Declaration])]
78 , modReExports :: [(P.ModuleName, [Declaration])]
@@ -81,8 +80,8 @@ data Module = Module
81 deriving (Show, Eq, Ord)
80 deriving (Show, Eq, Ord)
82
81
83data Declaration = Declaration
82data Declaration = Declaration
84− { declTitle :: String
83+ { declTitle :: Text
85− , declComments :: Maybe String
84+ , declComments :: Maybe Text
86 , declSourceSpan :: Maybe P.SourceSpan
85 , declSourceSpan :: Maybe P.SourceSpan
87 , declChildren :: [ChildDeclaration]
86 , declChildren :: [ChildDeclaration]
88 , declInfo :: DeclarationInfo
87 , declInfo :: DeclarationInfo
@@ -109,7 +108,7 @@ data DeclarationInfo
109 -- newtype) and its type arguments. Constructors are represented as child
108 -- newtype) and its type arguments. Constructors are represented as child
110 -- declarations.
109 -- declarations.
111 --
110 --
112− | DataDeclaration P.DataDeclType [(String, Maybe P.Kind)]
111+ | DataDeclaration P.DataDeclType [(Text, Maybe P.Kind)]
113
112
114 -- |
113 -- |
115 -- A data type foreign import, with its kind.
114 -- A data type foreign import, with its kind.
@@ -119,13 +118,13 @@ data DeclarationInfo
119 -- |
118 -- |
120 -- A type synonym, with its type arguments and its type.
119 -- A type synonym, with its type arguments and its type.
121 --
120 --
122− | TypeSynonymDeclaration [(String, Maybe P.Kind)] P.Type
121+ | TypeSynonymDeclaration [(Text, Maybe P.Kind)] P.Type
123
122
124 -- |
123 -- |
125 -- A type class, with its type arguments, its superclasses and functional
124 -- A type class, with its type arguments, its superclasses and functional
126 -- dependencies. Instances and members are represented as child declarations.
125 -- dependencies. Instances and members are represented as child declarations.
127 --
126 --
128− | TypeClassDeclaration [(String, Maybe P.Kind)] [P.Constraint] [([String], [String])]
127+ | TypeClassDeclaration [(Text, Maybe P.Kind)] [P.Constraint] [([Text], [Text])]
129
128
130 -- |
129 -- |
131 -- An operator alias declaration, with the member the alias is for and the
130 -- An operator alias declaration, with the member the alias is for and the
@@ -134,14 +133,13 @@ data DeclarationInfo
134 | AliasDeclaration P.Fixity FixityAlias
133 | AliasDeclaration P.Fixity FixityAlias
135 deriving (Show, Eq, Ord)
134 deriving (Show, Eq, Ord)
136
135
137−convertFundepsToStrings :: [(Text, Maybe P.Kind)] -> [P.FunctionalDependency] -> [([String], [String])]
136+convertFundepsToStrings :: [(Text, Maybe P.Kind)] -> [P.FunctionalDependency] -> [([Text], [Text])]
138convertFundepsToStrings args fundeps =
137convertFundepsToStrings args fundeps =
139− map (bimap (map T.unpack) (map T.unpack)) fundeps'
138+ map (\(P.FunctionalDependency from to) -> toArgs from to) fundeps
140 where
139 where
141− fundeps' = map (\(P.FunctionalDependency from to) -> toArgs from to) fundeps
142 argsVec = V.fromList (map fst args)
140 argsVec = V.fromList (map fst args)
143 getArg i =
141 getArg i =
144− maybe
142+ fromMaybe
145 (P.internalError $ unlines
143 (P.internalError $ unlines
146 [ "convertDeclaration: Functional dependency index"
144 [ "convertDeclaration: Functional dependency index"
147 , show i
145 , show i
@@ -150,12 +148,12 @@ convertFundepsToStrings args fundeps =
150 , "Functional dependencies are"
148 , "Functional dependencies are"
151 , show fundeps
149 , show fundeps
152 ]
150 ]
153− ) id $ argsVec V.!? i
151+ ) $ argsVec V.!? i
154 toArgs from to = (map getArg from, map getArg to)
152 toArgs from to = (map getArg from, map getArg to)
155
153
156type FixityAlias = P.Qualified (Either (P.ProperName 'P.TypeName) (Either P.Ident (P.ProperName 'P.ConstructorName)))
154type FixityAlias = P.Qualified (Either (P.ProperName 'P.TypeName) (Either P.Ident (P.ProperName 'P.ConstructorName)))
157
155
158−declInfoToString :: DeclarationInfo -> String
156+declInfoToString :: DeclarationInfo -> Text
159declInfoToString (ValueDeclaration _) = "value"
157declInfoToString (ValueDeclaration _) = "value"
160declInfoToString (DataDeclaration _ _) = "data"
158declInfoToString (DataDeclaration _ _) = "data"
161declInfoToString (ExternDataDeclaration _) = "externData"
159declInfoToString (ExternDataDeclaration _) = "externData"
@@ -201,8 +199,8 @@ filterChildren p decl =
201 decl { declChildren = filter p (declChildren decl) }
199 decl { declChildren = filter p (declChildren decl) }
202
200
203data ChildDeclaration = ChildDeclaration
201data ChildDeclaration = ChildDeclaration
204− { cdeclTitle :: String
202+ { cdeclTitle :: Text
205− , cdeclComments :: Maybe String
203+ , cdeclComments :: Maybe Text
206 , cdeclSourceSpan :: Maybe P.SourceSpan
204 , cdeclSourceSpan :: Maybe P.SourceSpan
207 , cdeclInfo :: ChildDeclarationInfo
205 , cdeclInfo :: ChildDeclarationInfo
208 }
206 }
@@ -227,7 +225,7 @@ data ChildDeclarationInfo
227 | ChildTypeClassMember P.Type
225 | ChildTypeClassMember P.Type
228 deriving (Show, Eq, Ord)
226 deriving (Show, Eq, Ord)
229
227
230−childDeclInfoToString :: ChildDeclarationInfo -> String
228+childDeclInfoToString :: ChildDeclarationInfo -> Text
231childDeclInfoToString (ChildInstance _ _) = "instance"
229childDeclInfoToString (ChildInstance _ _) = "instance"
232childDeclInfoToString (ChildDataConstructor _) = "dataConstructor"
230childDeclInfoToString (ChildDataConstructor _) = "dataConstructor"
233childDeclInfoToString (ChildTypeClassMember _) = "typeClassMember"
231childDeclInfoToString (ChildTypeClassMember _) = "typeClassMember"
@@ -245,11 +243,11 @@ isDataConstructor ChildDeclaration{..} =
245 _ -> False
243 _ -> False
246
244
247newtype GithubUser
245newtype GithubUser
248− = GithubUser { runGithubUser :: String }
246+ = GithubUser { runGithubUser :: Text }
249 deriving (Show, Eq, Ord)
247 deriving (Show, Eq, Ord)
250
248
251newtype GithubRepo
249newtype GithubRepo
252− = GithubRepo { runGithubRepo :: String }
250+ = GithubRepo { runGithubRepo :: Text }
253 deriving (Show, Eq, Ord)
251 deriving (Show, Eq, Ord)
254
252
255data PackageError
253data PackageError
@@ -258,14 +256,14 @@ data PackageError
258 -- parser, and actual version used.
256 -- parser, and actual version used.
259 | ErrorInPackageMeta BowerError
257 | ErrorInPackageMeta BowerError
260 | InvalidVersion
258 | InvalidVersion
261− | InvalidDeclarationType String
259+ | InvalidDeclarationType Text
262− | InvalidChildDeclarationType String
260+ | InvalidChildDeclarationType Text
263 | InvalidFixity
261 | InvalidFixity
264− | InvalidKind String
262+ | InvalidKind Text
265− | InvalidDataDeclType String
263+ | InvalidDataDeclType Text
266 deriving (Show, Eq, Ord)
264 deriving (Show, Eq, Ord)
267
265
268−type Bookmark = InPackage (P.ModuleName, String)
266+type Bookmark = InPackage (P.ModuleName, Text)
269
267
270data InPackage a
268data InPackage a
271 = Local a
269 = Local a
@@ -307,7 +305,7 @@ asPackage minimumVersion uploader = do
307
305
308 Package <$> key "packageMeta" asPackageMeta .! ErrorInPackageMeta
306 Package <$> key "packageMeta" asPackageMeta .! ErrorInPackageMeta
309 <*> key "version" asVersion
307 <*> key "version" asVersion
310− <*> key "versionTag" asString
308+ <*> key "versionTag" asText
311 <*> key "modules" (eachInArray asModule)
309 <*> key "modules" (eachInArray asModule)
312 <*> key "bookmarks" asBookmarks .! ErrorInPackageMeta
310 <*> key "bookmarks" asBookmarks .! ErrorInPackageMeta
313 <*> key "resolvedDependencies" asResolvedDependencies
311 <*> key "resolvedDependencies" asResolvedDependencies
@@ -338,15 +336,15 @@ displayPackageError e = case e of
338 InvalidVersion ->
336 InvalidVersion ->
339 "Invalid version"
337 "Invalid version"
340 InvalidDeclarationType str ->
338 InvalidDeclarationType str ->
341− "Invalid declaration type: \"" <> T.pack str <> "\""
339+ "Invalid declaration type: \"" <> str <> "\""
342 InvalidChildDeclarationType str ->
340 InvalidChildDeclarationType str ->
343− "Invalid child declaration type: \"" <> T.pack str <> "\""
341+ "Invalid child declaration type: \"" <> str <> "\""
344 InvalidFixity ->
342 InvalidFixity ->
345 "Invalid fixity"
343 "Invalid fixity"
346 InvalidKind str ->
344 InvalidKind str ->
347− "Invalid kind: \"" <> T.pack str <> "\""
345+ "Invalid kind: \"" <> str <> "\""
348 InvalidDataDeclType str ->
346 InvalidDataDeclType str ->
349− "Invalid data declaration type: \"" <> T.pack str <> "\""
347+ "Invalid data declaration type: \"" <> str <> "\""
350 where
348 where
351 (<>) = T.append
349 (<>) = T.append
352
350
@@ -355,7 +353,7 @@ instance A.FromJSON a => A.FromJSON (Package a) where
355 (asPackage (Version [0,0,0,0] []) fromAesonParser)
353 (asPackage (Version [0,0,0,0] []) fromAesonParser)
356
354
357asGithubUser :: Parse e GithubUser
355asGithubUser :: Parse e GithubUser
358−asGithubUser = GithubUser <$> asString
356+asGithubUser = GithubUser <$> asText
359
357
360instance A.FromJSON GithubUser where
358instance A.FromJSON GithubUser where
361 parseJSON = toAesonParser' asGithubUser
359 parseJSON = toAesonParser' asGithubUser
@@ -372,14 +370,14 @@ parseVersion' str =
372asModule :: Parse PackageError Module
370asModule :: Parse PackageError Module
373asModule =
371asModule =
374 Module <$> key "name" (P.moduleNameFromString <$> asText)
372 Module <$> key "name" (P.moduleNameFromString <$> asText)
375− <*> key "comments" (perhaps asString)
373+ <*> key "comments" (perhaps asText)
376 <*> key "declarations" (eachInArray asDeclaration)
374 <*> key "declarations" (eachInArray asDeclaration)
377 <*> key "reExports" (eachInArray asReExport)
375 <*> key "reExports" (eachInArray asReExport)
378
376
379asDeclaration :: Parse PackageError Declaration
377asDeclaration :: Parse PackageError Declaration
380asDeclaration =
378asDeclaration =
381− Declaration <$> key "title" asString
379+ Declaration <$> key "title" asText
382− <*> key "comments" (perhaps asString)
380+ <*> key "comments" (perhaps asText)
383 <*> key "sourceSpan" (perhaps asSourceSpan)
381 <*> key "sourceSpan" (perhaps asSourceSpan)
384 <*> key "children" (eachInArray asChildDeclaration)
382 <*> key "children" (eachInArray asChildDeclaration)
385 <*> key "info" asDeclarationInfo
383 <*> key "info" asDeclarationInfo
@@ -417,7 +415,7 @@ asAssociativity = withString (maybe (Left InvalidFixity) Right . parseAssociativ
417
415
418asDeclarationInfo :: Parse PackageError DeclarationInfo
416asDeclarationInfo :: Parse PackageError DeclarationInfo
419asDeclarationInfo = do
417asDeclarationInfo = do
420− ty <- key "declType" asString
418+ ty <- key "declType" asText
421 case ty of
419 case ty of
422 "value" ->
420 "value" ->
423 ValueDeclaration <$> key "type" asType
421 ValueDeclaration <$> key "type" asType
@@ -439,10 +437,10 @@ asDeclarationInfo = do
439 other ->
437 other ->
440 throwCustomError (InvalidDeclarationType other)
438 throwCustomError (InvalidDeclarationType other)
441
439
442−asTypeArguments :: Parse PackageError [(String, Maybe P.Kind)]
440+asTypeArguments :: Parse PackageError [(Text, Maybe P.Kind)]
443asTypeArguments = eachInArray asTypeArgument
441asTypeArguments = eachInArray asTypeArgument
444 where
442 where
445− asTypeArgument = (,) <$> nth 0 asString <*> nth 1 (perhaps asKind)
443+ asTypeArgument = (,) <$> nth 0 asText <*> nth 1 (perhaps asKind)
446
444
447asKind :: Parse e P.Kind
445asKind :: Parse e P.Kind
448asKind = fromAesonParser
446asKind = fromAesonParser
@@ -450,28 +448,28 @@ asKind = fromAesonParser
450asType :: Parse e P.Type
448asType :: Parse e P.Type
451asType = fromAesonParser
449asType = fromAesonParser
452
450
453−asFunDeps :: Parse PackageError [([String], [String])]
451+asFunDeps :: Parse PackageError [([Text], [Text])]
454asFunDeps = eachInArray asFunDep
452asFunDeps = eachInArray asFunDep
455 where
453 where
456− asFunDep = (,) <$> nth 0 (eachInArray asString) <*> nth 1 (eachInArray asString)
454+ asFunDep = (,) <$> nth 0 (eachInArray asText) <*> nth 1 (eachInArray asText)
457
455
458asDataDeclType :: Parse PackageError P.DataDeclType
456asDataDeclType :: Parse PackageError P.DataDeclType
459asDataDeclType =
457asDataDeclType =
460− withString $ \s -> case s of
458+ withText $ \s -> case s of
461 "data" -> Right P.Data
459 "data" -> Right P.Data
462 "newtype" -> Right P.Newtype
460 "newtype" -> Right P.Newtype
463 other -> Left (InvalidDataDeclType other)
461 other -> Left (InvalidDataDeclType other)
464
462
465asChildDeclaration :: Parse PackageError ChildDeclaration
463asChildDeclaration :: Parse PackageError ChildDeclaration
466asChildDeclaration =
464asChildDeclaration =
467− ChildDeclaration <$> key "title" asString
465+ ChildDeclaration <$> key "title" asText
468− <*> key "comments" (perhaps asString)
466+ <*> key "comments" (perhaps asText)
469 <*> key "sourceSpan" (perhaps asSourceSpan)
467 <*> key "sourceSpan" (perhaps asSourceSpan)
470 <*> key "info" asChildDeclarationInfo
468 <*> key "info" asChildDeclarationInfo
471
469
472asChildDeclarationInfo :: Parse PackageError ChildDeclarationInfo
470asChildDeclarationInfo :: Parse PackageError ChildDeclarationInfo
473asChildDeclarationInfo = do
471asChildDeclarationInfo = do
474− ty <- key "declType" asString
472+ ty <- key "declType" asText
475 case ty of
473 case ty of
476 "instance" ->
474 "instance" ->
477 ChildInstance <$> key "dependencies" (eachInArray asConstraint)
475 ChildInstance <$> key "dependencies" (eachInArray asConstraint)
@@ -504,7 +502,7 @@ asBookmarks = eachInArray asBookmark
504asBookmark :: Parse BowerError Bookmark
502asBookmark :: Parse BowerError Bookmark
505asBookmark =
503asBookmark =
506 asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asText)
504 asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asText)
507− <*> nth 1 asString)
505+ <*> nth 1 asText)
508
506
509asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
507asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
510asResolvedDependencies =
508asResolvedDependencies =
@@ -514,8 +512,8 @@ asResolvedDependencies =
514 mapLeft _ (Right x) = Right x
512 mapLeft _ (Right x) = Right x
515
513
516asGithub :: Parse e (GithubUser, GithubRepo)
514asGithub :: Parse e (GithubUser, GithubRepo)
517−asGithub = (,) <$> nth 0 (GithubUser <$> asString)
515+asGithub = (,) <$> nth 0 (GithubUser <$> asText)
518− <*> nth 1 (GithubRepo <$> asString)
516+ <*> nth 1 (GithubRepo <$> asText)
519
517
520asSourceSpan :: Parse e P.SourceSpan
518asSourceSpan :: Parse e P.SourceSpan
521asSourceSpan = P.SourceSpan <$> key "name" asString
519asSourceSpan = P.SourceSpan <$> key "name" asString
src/Language/PureScript/Publish.hs+24−22
@@ -23,7 +23,7 @@ module Language.PureScript.Publish
23import Prelude ()
23import Prelude ()
24import Prelude.Compat hiding (userError)
24import Prelude.Compat hiding (userError)
25
25
26−import Control.Arrow ((***))
26+import Control.Arrow ((***), first)
27import Control.Category ((>>>))
27import Control.Category ((>>>))
28import Control.Exception (catch, try)
28import Control.Exception (catch, try)
29import Control.Monad.Error.Class (MonadError(..))
29import Control.Monad.Error.Class (MonadError(..))
@@ -35,12 +35,13 @@ import Data.Aeson.BetterErrors
35import Data.Char (isSpace)
35import Data.Char (isSpace)
36import Data.Foldable (traverse_)
36import Data.Foldable (traverse_)
37import Data.Function (on)
37import Data.Function (on)
38−import Data.List (stripPrefix, isSuffixOf, (\\), nubBy)
38+import Data.List (stripPrefix, (\\), nubBy)
39import Data.List.NonEmpty (NonEmpty(..))
39import Data.List.NonEmpty (NonEmpty(..))
40import Data.List.Split (splitOn)
40import Data.List.Split (splitOn)
41import Data.Maybe
41import Data.Maybe
42import Data.Version
42import Data.Version
43import qualified Data.SPDX as SPDX
43import qualified Data.SPDX as SPDX
44+import Data.Text (Text)
44import qualified Data.Text as T
45import qualified Data.Text as T
45import qualified Data.Text.Lazy as TL
46import qualified Data.Text.Lazy as TL
46import qualified Data.Text.Lazy.Encoding as TL
47import qualified Data.Text.Lazy.Encoding as TL
@@ -65,7 +66,7 @@ import qualified Language.PureScript.Docs as D
65data PublishOptions = PublishOptions
66data PublishOptions = PublishOptions
66 { -- | How to obtain the version tag and version that the data being
67 { -- | How to obtain the version tag and version that the data being
67 -- generated will refer to.
68 -- generated will refer to.
68− publishGetVersion :: PrepareM (String, Version)
69+ publishGetVersion :: PrepareM (Text, Version)
69 , -- | What to do when the working tree is dirty
70 , -- | What to do when the working tree is dirty
70 publishWorkingTreeDirty :: PrepareM ()
71 publishWorkingTreeDirty :: PrepareM ()
71 }
72 }
@@ -184,13 +185,13 @@ checkCleanWorkingTree opts = do
184 unless (status == Clean) $
185 unless (status == Clean) $
185 publishWorkingTreeDirty opts
186 publishWorkingTreeDirty opts
186
187
187−getVersionFromGitTag :: PrepareM (String, Version)
188+getVersionFromGitTag :: PrepareM (Text, Version)
188getVersionFromGitTag = do
189getVersionFromGitTag = do
189 out <- readProcess' "git" ["tag", "--list", "--points-at", "HEAD"] ""
190 out <- readProcess' "git" ["tag", "--list", "--points-at", "HEAD"] ""
190 let vs = map trimWhitespace (lines out)
191 let vs = map trimWhitespace (lines out)
191 case mapMaybe parseMay vs of
192 case mapMaybe parseMay vs of
192 [] -> userError TagMustBeCheckedOut
193 [] -> userError TagMustBeCheckedOut
193− [x] -> return x
194+ [x] -> return (first T.pack x)
194 xs -> userError (AmbiguousVersions (map snd xs))
195 xs -> userError (AmbiguousVersions (map snd xs))
195 where
196 where
196 trimWhitespace =
197 trimWhitespace =
@@ -209,7 +210,7 @@ getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExt
209 Just Repository{..} -> do
210 Just Repository{..} -> do
210 unless (repositoryType == "git")
211 unless (repositoryType == "git")
211 (Left (BadRepositoryType repositoryType))
212 (Left (BadRepositoryType repositoryType))
212− maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
213+ maybe (Left NotOnGithub) Right (extractGithub (T.pack repositoryUrl))
213
214
214checkLicense :: PackageMeta -> PrepareM ()
215checkLicense :: PackageMeta -> PrepareM ()
215checkLicense pkgMeta =
216checkLicense pkgMeta =
@@ -226,9 +227,9 @@ checkLicense pkgMeta =
226isValidSPDX :: String -> Bool
227isValidSPDX :: String -> Bool
227isValidSPDX = (== 1) . length . SPDX.parseExpression
228isValidSPDX = (== 1) . length . SPDX.parseExpression
228
229
229−extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
230+extractGithub :: Text -> Maybe (D.GithubUser, D.GithubRepo)
230extractGithub = stripGitHubPrefixes
231extractGithub = stripGitHubPrefixes
231− >>> fmap (splitOn "/")
232+ >>> fmap (T.splitOn "/")
232 >=> takeTwo
233 >=> takeTwo
233 >>> fmap (D.GithubUser *** (D.GithubRepo . dropDotGit))
234 >>> fmap (D.GithubUser *** (D.GithubRepo . dropDotGit))
234
235
@@ -237,18 +238,18 @@ extractGithub = stripGitHubPrefixes
237 takeTwo [x, y] = Just (x, y)
238 takeTwo [x, y] = Just (x, y)
238 takeTwo _ = Nothing
239 takeTwo _ = Nothing
239
240
240− stripGitHubPrefixes :: String -> Maybe String
241+ stripGitHubPrefixes :: Text -> Maybe Text
241 stripGitHubPrefixes = stripPrefixes [ "git://github.com/"
242 stripGitHubPrefixes = stripPrefixes [ "git://github.com/"
242 , "https://github.com/"
243 , "https://github.com/"
243 , "git@github.com:"
244 , "git@github.com:"
244 ]
245 ]
245
246
246− stripPrefixes :: [String] -> String -> Maybe String
247+ stripPrefixes :: [Text] -> Text -> Maybe Text
247− stripPrefixes prefixes str = msum $ (`stripPrefix` str) <$> prefixes
248+ stripPrefixes prefixes str = msum $ (`T.stripPrefix` str) <$> prefixes
248
249
249− dropDotGit :: String -> String
250+ dropDotGit :: Text -> Text
250 dropDotGit str
251 dropDotGit str
251− | ".git" `isSuffixOf` str = take (length str - 4) str
252+ | ".git" `T.isSuffixOf` str = T.take (T.length str - 4) str
252 | otherwise = str
253 | otherwise = str
253
254
254readProcess' :: String -> [String] -> String -> PrepareM String
255readProcess' :: String -> [String] -> String -> PrepareM String
@@ -265,12 +266,12 @@ data DependencyStatus
265 -- _resolution key. This can be caused by adding the dependency using
266 -- _resolution key. This can be caused by adding the dependency using
266 -- `bower link`, or simply copying it into bower_components instead of
267 -- `bower link`, or simply copying it into bower_components instead of
267 -- installing it normally.
268 -- installing it normally.
268− | ResolvedOther String
269+ | ResolvedOther Text
269− -- ^ Resolved, but to something other than a version. The String argument
270+ -- ^ Resolved, but to something other than a version. The Text argument
270 -- is the resolution type. The values it can take that I'm aware of are
271 -- is the resolution type. The values it can take that I'm aware of are
271 -- "commit" and "branch".
272 -- "commit" and "branch".
272− | ResolvedVersion String
273+ | ResolvedVersion Text
273− -- ^ Resolved to a version. The String argument is the resolution tag (eg,
274+ -- ^ Resolved to a version. The Text argument is the resolution tag (eg,
274 -- "v0.1.0").
275 -- "v0.1.0").
275 deriving (Show, Eq)
276 deriving (Show, Eq)
276
277
@@ -341,9 +342,9 @@ asDependencyStatus = do
341 else
342 else
342 key "pkgMeta" $
343 key "pkgMeta" $
343 keyOrDefault "_resolution" NoResolution $ do
344 keyOrDefault "_resolution" NoResolution $ do
344− type_ <- key "type" asString
345+ type_ <- key "type" asText
345 case type_ of
346 case type_ of
346− "version" -> ResolvedVersion <$> key "tag" asString
347+ "version" -> ResolvedVersion <$> key "tag" asText
347 other -> return (ResolvedOther other)
348 other -> return (ResolvedOther other)
348
349
349warnUndeclared :: [PackageName] -> [PackageName] -> PrepareM ()
350warnUndeclared :: [PackageName] -> [PackageName] -> PrepareM ()
@@ -374,15 +375,16 @@ handleDeps deps = do
374 bowerDir pkgName = "bower_components/" ++ runPackageName pkgName
375 bowerDir pkgName = "bower_components/" ++ runPackageName pkgName
375
376
376 -- Try to extract a version, and warn if unsuccessful.
377 -- Try to extract a version, and warn if unsuccessful.
378+ tryExtractVersion' :: (PackageName, Text) -> PrepareM (Maybe (PackageName, Version))
377 tryExtractVersion' pair =
379 tryExtractVersion' pair =
378 maybe (warn (UnacceptableVersion pair) >> return Nothing)
380 maybe (warn (UnacceptableVersion pair) >> return Nothing)
379 (return . Just)
381 (return . Just)
380 (tryExtractVersion pair)
382 (tryExtractVersion pair)
381
383
382−tryExtractVersion :: (PackageName, String) -> Maybe (PackageName, Version)
384+tryExtractVersion :: (PackageName, Text) -> Maybe (PackageName, Version)
383tryExtractVersion (pkgName, tag) =
385tryExtractVersion (pkgName, tag) =
384− let tag' = fromMaybe tag (stripPrefix "v" tag)
386+ let tag' = fromMaybe tag (T.stripPrefix "v" tag)
385− in (pkgName,) <$> D.parseVersion' tag'
387+ in (pkgName,) <$> D.parseVersion' (T.unpack tag')
386
388
387-- | Returns whether it looks like there is a purescript package checked out
389-- | Returns whether it looks like there is a purescript package checked out
388-- in the given directory.
390-- in the given directory.
src/Language/PureScript/Publish/ErrorsWarnings.hs+5−4
@@ -24,6 +24,7 @@ import Data.Maybe
24import Data.Monoid
24import Data.Monoid
25import Data.Version
25import Data.Version
26import qualified Data.List.NonEmpty as NonEmpty
26import qualified Data.List.NonEmpty as NonEmpty
27+import Data.Text (Text)
27import qualified Data.Text as T
28import qualified Data.Text as T
28
29
29import Language.PureScript.Publish.BoxesHelpers
30import Language.PureScript.Publish.BoxesHelpers
@@ -43,7 +44,7 @@ data PackageError
43data PackageWarning
44data PackageWarning
44 = NoResolvedVersion PackageName
45 = NoResolvedVersion PackageName
45 | UndeclaredDependency PackageName
46 | UndeclaredDependency PackageName
46− | UnacceptableVersion (PackageName, String)
47+ | UnacceptableVersion (PackageName, Text)
47 | DirtyWorkingTree_Warn
48 | DirtyWorkingTree_Warn
48 deriving (Show)
49 deriving (Show)
49
50
@@ -311,7 +312,7 @@ displayOtherError e = case e of
311data CollectedWarnings = CollectedWarnings
312data CollectedWarnings = CollectedWarnings
312 { noResolvedVersions :: [PackageName]
313 { noResolvedVersions :: [PackageName]
313 , undeclaredDependencies :: [PackageName]
314 , undeclaredDependencies :: [PackageName]
314− , unacceptableVersions :: [(PackageName, String)]
315+ , unacceptableVersions :: [(PackageName, Text)]
315 , dirtyWorkingTree :: Any
316 , dirtyWorkingTree :: Any
316 }
317 }
317 deriving (Show, Eq, Ord)
318 deriving (Show, Eq, Ord)
@@ -387,7 +388,7 @@ warnUndeclaredDependencies pkgNames =
387 ])
388 ])
388 : bulletedList runPackageName (NonEmpty.toList pkgNames)
389 : bulletedList runPackageName (NonEmpty.toList pkgNames)
389
390
390−warnUnacceptableVersions :: NonEmpty (PackageName, String) -> Box
391+warnUnacceptableVersions :: NonEmpty (PackageName, Text) -> Box
391warnUnacceptableVersions pkgs =
392warnUnacceptableVersions pkgs =
392 let singular = NonEmpty.length pkgs == 1
393 let singular = NonEmpty.length pkgs == 1
393 pl a b = if singular then b else a
394 pl a b = if singular then b else a
@@ -414,7 +415,7 @@ warnUnacceptableVersions pkgs =
414 ])
415 ])
415 ]
416 ]
416 where
417 where
417− showTuple (pkgName, tag) = runPackageName pkgName ++ "#" ++ tag
418+ showTuple (pkgName, tag) = runPackageName pkgName ++ "#" ++ T.unpack tag
418
419
419warnDirtyWorkingTree :: Box
420warnDirtyWorkingTree :: Box
420warnDirtyWorkingTree =
421warnDirtyWorkingTree =
tests/TestDocs.hs+83−70
@@ -1,6 +1,7 @@
1{-# LANGUAGE RecordWildCards #-}
1{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE ViewPatterns #-}
2{-# LANGUAGE ViewPatterns #-}
3{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE OverloadedStrings #-}
4
5
5module TestDocs where
6module TestDocs where
6
7
@@ -13,6 +14,7 @@ import Data.Monoid
13import Data.Maybe (fromMaybe)
14import Data.Maybe (fromMaybe)
14import Data.List ((\\))
15import Data.List ((\\))
15import Data.Foldable
16import Data.Foldable
17+import Data.Text (Text)
16import qualified Data.Text as T
18import qualified Data.Text as T
17import System.Exit
19import System.Exit
18
20
@@ -37,7 +39,7 @@ main = pushd "examples/docs" $ do
37 case res of
39 case res of
38 Left e -> Publish.printErrorToStdout e >> exitFailure
40 Left e -> Publish.printErrorToStdout e >> exitFailure
39 Right Docs.Package{..} ->
41 Right Docs.Package{..} ->
40− forM_ testCases $ \(P.moduleNameFromString . T.pack -> mn, pragmas) ->
42+ forM_ testCases $ \(P.moduleNameFromString -> mn, pragmas) ->
41 let mdl = takeJust ("module not found in docs: " ++ T.unpack (P.runModuleName mn))
43 let mdl = takeJust ("module not found in docs: " ++ T.unpack (P.runModuleName mn))
42 (find ((==) mn . Docs.modName) pkgModules)
44 (find ((==) mn . Docs.modName) pkgModules)
43 in forM_ pragmas (`runAssertionIO` mdl)
45 in forM_ pragmas (`runAssertionIO` mdl)
@@ -49,25 +51,28 @@ takeJust msg = fromMaybe (error msg)
49data Assertion
51data Assertion
50 -- | Assert that a particular declaration is documented with the given
52 -- | Assert that a particular declaration is documented with the given
51 -- children
53 -- children
52− = ShouldBeDocumented P.ModuleName String [String]
54+ = ShouldBeDocumented P.ModuleName Text [Text]
53 -- | Assert that a particular declaration is not documented
55 -- | Assert that a particular declaration is not documented
54− | ShouldNotBeDocumented P.ModuleName String
56+ | ShouldNotBeDocumented P.ModuleName Text
55 -- | Assert that a particular declaration exists, but without a particular
57 -- | Assert that a particular declaration exists, but without a particular
56 -- child.
58 -- child.
57− | ChildShouldNotBeDocumented P.ModuleName String String
59+ | ChildShouldNotBeDocumented P.ModuleName Text Text
58 -- | Assert that a particular declaration has a particular type class
60 -- | Assert that a particular declaration has a particular type class
59 -- constraint.
61 -- constraint.
60− | ShouldBeConstrained P.ModuleName String String
62+ | ShouldBeConstrained P.ModuleName Text Text
61 -- | Assert that a particular typeclass declaration has a functional
63 -- | Assert that a particular typeclass declaration has a functional
62 -- dependency list.
64 -- dependency list.
63− | ShouldHaveFunDeps P.ModuleName String [([String],[String])]
65+ | ShouldHaveFunDeps P.ModuleName Text [([Text],[Text])]
64 -- | Assert that a particular value declaration exists, and its type
66 -- | Assert that a particular value declaration exists, and its type
65 -- satisfies the given predicate.
67 -- satisfies the given predicate.
66− | ValueShouldHaveTypeSignature P.ModuleName String (ShowFn (P.Type -> Bool))
68+ | ValueShouldHaveTypeSignature P.ModuleName Text (ShowFn (P.Type -> Bool))
67 -- | Assert that a particular type alias exists, and its corresponding
69 -- | Assert that a particular type alias exists, and its corresponding
68 -- type, when rendered, matches a given string exactly
70 -- type, when rendered, matches a given string exactly
69 -- fields: module, type synonym name, expected type
71 -- fields: module, type synonym name, expected type
70− | TypeSynonymShouldRenderAs P.ModuleName String String
72+ | TypeSynonymShouldRenderAs P.ModuleName Text Text
73+ -- | Assert that a documented declaration includes a documentation comment
74+ -- containing a particular string
75+ | ShouldHaveDocComment P.ModuleName Text Text
71 deriving (Show)
76 deriving (Show)
72
77
73newtype ShowFn a = ShowFn a
78newtype ShowFn a = ShowFn a
@@ -77,28 +82,31 @@ instance Show (ShowFn a) where
77
82
78data AssertionFailure
83data AssertionFailure
79 -- | A declaration was not documented, but should have been
84 -- | A declaration was not documented, but should have been
80− = NotDocumented P.ModuleName String
85+ = NotDocumented P.ModuleName Text
81 -- | A child declaration was not documented, but should have been
86 -- | A child declaration was not documented, but should have been
82− | ChildrenNotDocumented P.ModuleName String [String]
87+ | ChildrenNotDocumented P.ModuleName Text [Text]
83 -- | A declaration was documented, but should not have been
88 -- | A declaration was documented, but should not have been
84− | Documented P.ModuleName String
89+ | Documented P.ModuleName Text
85 -- | A child declaration was documented, but should not have been
90 -- | A child declaration was documented, but should not have been
86− | ChildDocumented P.ModuleName String String
91+ | ChildDocumented P.ModuleName Text Text
87 -- | A constraint was missing.
92 -- | A constraint was missing.
88− | ConstraintMissing P.ModuleName String String
93+ | ConstraintMissing P.ModuleName Text Text
89 -- | A functional dependency was missing.
94 -- | A functional dependency was missing.
90− | FunDepMissing P.ModuleName String [([String], [String])]
95+ | FunDepMissing P.ModuleName Text [([Text], [Text])]
91 -- | A declaration had the wrong "type" (ie, value, type, type class)
96 -- | A declaration had the wrong "type" (ie, value, type, type class)
92 -- Fields: declaration title, expected "type", actual "type".
97 -- Fields: declaration title, expected "type", actual "type".
93− | WrongDeclarationType P.ModuleName String String String
98+ | WrongDeclarationType P.ModuleName Text Text Text
94 -- | A value declaration had the wrong type (in the sense of "type
99 -- | A value declaration had the wrong type (in the sense of "type
95 -- checking"), eg, because the inferred type was used when the explicit type
100 -- checking"), eg, because the inferred type was used when the explicit type
96 -- should have been.
101 -- should have been.
97 -- Fields: module name, declaration name, actual type.
102 -- Fields: module name, declaration name, actual type.
98− | ValueDeclarationWrongType P.ModuleName String P.Type
103+ | ValueDeclarationWrongType P.ModuleName Text P.Type
99 -- | A Type synonym has been rendered in an unexpected format
104 -- | A Type synonym has been rendered in an unexpected format
100 -- Fields: module name, declaration name, expected rendering, actual rendering
105 -- Fields: module name, declaration name, expected rendering, actual rendering
101− | TypeSynonymMismatch P.ModuleName String String String
106+ | TypeSynonymMismatch P.ModuleName Text Text Text
107+ -- | A doc comment was not found or did not match what was expected
108+ -- Fields: declaration title, expected substring, actual comments
109+ | DocCommentMissing P.ModuleName Text (Maybe Text)
102 deriving (Show)
110 deriving (Show)
103
111
104data AssertionResult
112data AssertionResult
@@ -135,62 +143,56 @@ runAssertion assertion Docs.Module{..} =
135 Fail (NotDocumented mn decl)
143 Fail (NotDocumented mn decl)
136
144
137 ShouldBeConstrained mn decl tyClass ->
145 ShouldBeConstrained mn decl tyClass ->
138− case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
139− Nothing ->
140− Fail (NotDocumented mn decl)
141− Just Docs.Declaration{..} ->
146+ findDecl mn decl $ \Docs.Declaration{..} ->
142− case declInfo of
147+ case declInfo of
143− Docs.ValueDeclaration ty ->
148+ Docs.ValueDeclaration ty ->
144− if checkConstrained ty tyClass
149+ if checkConstrained ty tyClass
145− then Pass
150+ then Pass
146− else Fail (ConstraintMissing mn decl tyClass)
151+ else Fail (ConstraintMissing mn decl tyClass)
147− _ ->
152+ _ ->
148− Fail (WrongDeclarationType mn decl "value"
153+ Fail (WrongDeclarationType mn decl "value"
149− (Docs.declInfoToString declInfo))
154+ (Docs.declInfoToString declInfo))
150
155
151 ShouldHaveFunDeps mn decl fds ->
156 ShouldHaveFunDeps mn decl fds ->
152− case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
153− Nothing ->
154− Fail (NotDocumented mn decl)
155− Just Docs.Declaration{..} ->
157+ findDecl mn decl $ \Docs.Declaration{..} ->
156− case declInfo of
158+ case declInfo of
157− Docs.TypeClassDeclaration _ _ fundeps ->
159+ Docs.TypeClassDeclaration _ _ fundeps ->
158− if fundeps == fds
160+ if fundeps == fds
159− then Pass
161+ then Pass
160− else Fail (FunDepMissing mn decl fds)
162+ else Fail (FunDepMissing mn decl fds)
161− _ ->
163+ _ ->
162− Fail (WrongDeclarationType mn decl "value"
164+ Fail (WrongDeclarationType mn decl "value"
163− (Docs.declInfoToString declInfo))
165+ (Docs.declInfoToString declInfo))
164
166
165 ValueShouldHaveTypeSignature mn decl (ShowFn tyPredicate) ->
167 ValueShouldHaveTypeSignature mn decl (ShowFn tyPredicate) ->
166− case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
167− Nothing ->
168− Fail (NotDocumented mn decl)
169− Just Docs.Declaration{..} ->
168+ findDecl mn decl $ \Docs.Declaration{..} ->
170− case declInfo of
169+ case declInfo of
171− Docs.ValueDeclaration ty ->
170+ Docs.ValueDeclaration ty ->
172− if tyPredicate ty
171+ if tyPredicate ty
173− then Pass
172+ then Pass
174− else Fail
173+ else Fail
175− (ValueDeclarationWrongType mn decl ty)
174+ (ValueDeclarationWrongType mn decl ty)
176− _ ->
175+ _ ->
177− Fail (WrongDeclarationType mn decl "value"
176+ Fail (WrongDeclarationType mn decl "value"
178− (Docs.declInfoToString declInfo))
177+ (Docs.declInfoToString declInfo))
179
178
180 TypeSynonymShouldRenderAs mn decl expected ->
179 TypeSynonymShouldRenderAs mn decl expected ->
181− case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
182− Nothing ->
183− Fail (NotDocumented mn decl)
184− Just Docs.Declaration{..} ->
180+ findDecl mn decl $ \Docs.Declaration{..} ->
185− case declInfo of
181+ case declInfo of
186− Docs.TypeSynonymDeclaration [] ty ->
182+ Docs.TypeSynonymDeclaration [] ty ->
187− let actual = codeToString (Docs.renderType ty) in
183+ let actual = codeToString (Docs.renderType ty) in
188− if actual == expected
184+ if actual == expected
189− then Pass
185+ then Pass
190− else Fail (TypeSynonymMismatch mn decl expected actual)
186+ else Fail (TypeSynonymMismatch mn decl expected actual)
191− _ ->
187+ _ ->
192− Fail (WrongDeclarationType mn decl "synonym"
188+ Fail (WrongDeclarationType mn decl "synonym"
193− (Docs.declInfoToString declInfo))
189+ (Docs.declInfoToString declInfo))
190+
191+ ShouldHaveDocComment mn decl expected ->
192+ findDecl mn decl $ \Docs.Declaration{..} ->
193+ if maybe False (expected `T.isInfixOf`) declComments
194+ then Pass
195+ else Fail (DocCommentMissing mn decl declComments)
194
196
195 where
197 where
196 declarationsFor mn =
198 declarationsFor mn =
@@ -201,9 +203,16 @@ runAssertion assertion Docs.Module{..} =
201 findChildren title =
203 findChildren title =
202 fmap childrenTitles . find ((==) title . Docs.declTitle)
204 fmap childrenTitles . find ((==) title . Docs.declTitle)
203
205
206+ findDecl mn title f =
207+ case find ((==) title . Docs.declTitle) (declarationsFor mn) of
208+ Nothing ->
209+ Fail (NotDocumented mn title)
210+ Just decl ->
211+ f decl
212+
204 childrenTitles = map Docs.cdeclTitle . Docs.declChildren
213 childrenTitles = map Docs.cdeclTitle . Docs.declChildren
205
214
206−checkConstrained :: P.Type -> String -> Bool
215+checkConstrained :: P.Type -> Text -> Bool
207checkConstrained ty tyClass =
216checkConstrained ty tyClass =
208 -- Note that we don't recurse on ConstrainedType if none of the constraints
217 -- Note that we don't recurse on ConstrainedType if none of the constraints
209 -- match; this is by design, as constraints should be moved to the front
218 -- match; this is by design, as constraints should be moved to the front
@@ -217,7 +226,7 @@ checkConstrained ty tyClass =
217 False
226 False
218 where
227 where
219 matches className =
228 matches className =
220− (==) className . T.unpack . P.runProperName . P.disqualify . P.constraintClass
229+ (==) className . P.runProperName . P.disqualify . P.constraintClass
221
230
222runAssertionIO :: Assertion -> Docs.Module -> IO ()
231runAssertionIO :: Assertion -> Docs.Module -> IO ()
223runAssertionIO assertion mdl = do
232runAssertionIO assertion mdl = do
@@ -228,7 +237,7 @@ runAssertionIO assertion mdl = do
228 putStrLn ("Failed: " <> show reason)
237 putStrLn ("Failed: " <> show reason)
229 exitFailure
238 exitFailure
230
239
231−testCases :: [(String, [Assertion])]
240+testCases :: [(Text, [Assertion])]
232testCases =
241testCases =
233 [ ("Example",
242 [ ("Example",
234 [ -- From dependencies
243 [ -- From dependencies
@@ -319,6 +328,10 @@ testCases =
319 , ValueShouldHaveTypeSignature (n "TypeOpAliases") "test4" (renderedType "forall a b c d. ((a ~> b) ~> c) ~> d")
328 , ValueShouldHaveTypeSignature (n "TypeOpAliases") "test4" (renderedType "forall a b c d. ((a ~> b) ~> c) ~> d")
320 , ValueShouldHaveTypeSignature (n "TypeOpAliases") "third" (renderedType "forall a b c. a × b × c -> c")
329 , ValueShouldHaveTypeSignature (n "TypeOpAliases") "third" (renderedType "forall a b c. a × b × c -> c")
321 ])
330 ])
331+
332+ , ("DocComments",
333+ [ ShouldHaveDocComment (n "DocComments") "example" " example == 0"
334+ ])
322 ]
335 ]
323
336
324 where
337 where
tests/TestPrimDocs.hs+2−3
@@ -3,7 +3,6 @@ module TestPrimDocs where
3import Control.Monad
3import Control.Monad
4import Data.List ((\\))
4import Data.List ((\\))
5import qualified Data.Map as Map
5import qualified Data.Map as Map
6−import qualified Data.Text as T
7import qualified Language.PureScript as P
6import qualified Language.PureScript as P
8import qualified Language.PureScript.Docs as D
7import qualified Language.PureScript.Docs as D
9import qualified Language.PureScript.Docs.AsMarkdown as D
8import qualified Language.PureScript.Docs.AsMarkdown as D
@@ -11,11 +10,11 @@ import qualified Language.PureScript.Docs.AsMarkdown as D
11main :: IO ()
10main :: IO ()
12main = do
11main = do
13 putStrLn "Test that there are no bottoms hiding in primDocsModule"
12 putStrLn "Test that there are no bottoms hiding in primDocsModule"
14− seq (T.pack (D.runDocs (D.modulesAsMarkdown [D.primDocsModule]))) (return ())
13+ seq (D.runDocs (D.modulesAsMarkdown [D.primDocsModule])) (return ())
15
14
16 putStrLn "Test that Prim is fully documented"
15 putStrLn "Test that Prim is fully documented"
17 let actualPrimTypes = map (P.runProperName . P.disqualify . fst) $ Map.toList P.primTypes
16 let actualPrimTypes = map (P.runProperName . P.disqualify . fst) $ Map.toList P.primTypes
18− let documentedPrimTypes = map (T.pack . D.declTitle) (D.modDeclarations D.primDocsModule)
17+ let documentedPrimTypes = map D.declTitle (D.modDeclarations D.primDocsModule)
19
18
20 let undocumentedTypes = actualPrimTypes \\ documentedPrimTypes
19 let undocumentedTypes = actualPrimTypes \\ documentedPrimTypes
21 let extraTypes = documentedPrimTypes \\ actualPrimTypes
20 let extraTypes = documentedPrimTypes \\ actualPrimTypes
tests/TestPscPublish.hs+2−10
@@ -1,20 +1,12 @@
1{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
1{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
2−{-# OPTIONS_GHC -fno-warn-unused-imports #-}
3{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE OverloadedStrings #-}
4
4
5module TestPscPublish where
5module TestPscPublish where
6
6
7−import Control.Monad
8−import Control.Applicative
9−import Control.Exception
10−import System.Process
11−import System.Directory
12−import System.IO
13−import System.Exit
7+import System.Exit (exitFailure)
14−import qualified Data.ByteString.Lazy as BL
15import Data.ByteString.Lazy (ByteString)
8import Data.ByteString.Lazy (ByteString)
16import qualified Data.Aeson as A
9import qualified Data.Aeson as A
17−import Data.Aeson.BetterErrors
18import Data.Version
10import Data.Version
19
11
20import Language.PureScript.Docs
12import Language.PureScript.Docs