on master help sign in
Remove docs generation from normal compilation flow

Current plan is to generate docs separately.

commit3f6492fa7dba2fa737d1fddb68872357a9bf519c authorEvan Czaplicki <evancz@users.noreply.github.com> dateSat 29 Dec 2018, 19:25 (8 years ago) parent1265a9b
8 files changed+60−140
builder/src/File/Compile.hs+6−40 builder/src/File/Plan.hs+5−13 builder/src/Generate/Artifacts.hs+3−22 compiler/src/Compile.hs+5−29 compiler/src/Elm/Compiler.hs+37−32 terminal/src/Develop.hs+1−1 terminal/src/Develop/StaticFiles/Build.hs+1−1 terminal/src/Make.hs+2−2
builder/src/File/Compile.hs+6−40
@@ -26,8 +26,8 @@ import qualified Reporting.Task as Task
2626-- COMPILE
2727
2828
29−compile :: Project -> Maybe FilePath -> I.Interfaces -> Dict Plan.Info -> Task.Task (Dict Answer)
30−compile project maybeDocsPath ifaces modules =
29+compile :: Project -> I.Interfaces -> Dict Plan.Info -> Task.Task (Dict Answer)
30+compile project ifaces modules =
3131 do Task.report (Progress.CompileStart (Map.size modules))
3232
3333 tell <- Task.getReporter
@@ -35,7 +35,7 @@ compile project maybeDocsPath ifaces modules =
3535 answers <- liftIO $
3636 do mvar <- newEmptyMVar
3737 iMVar <- newMVar ifaces
38− answerMVars <- Map.traverseWithKey (compileModule tell project maybeDocsPath mvar iMVar) modules
38+ answerMVars <- Map.traverseWithKey (compileModule tell project mvar iMVar) modules
3939 putMVar mvar answerMVars
4040 traverse readMVar answerMVars
4141
@@ -64,13 +64,12 @@ type Dict a = Map.Map ModuleName.Raw a
6464compileModule
6565 :: (Progress.Progress -> IO ())
6666 -> Project
67− -> Maybe FilePath
6867 -> MVar (Dict (MVar Answer))
6968 -> MVar I.Interfaces
7069 -> ModuleName.Raw
7170 -> Plan.Info
7271 -> IO (MVar Answer)
73−compileModule tell project maybeDocsPath answersMVar ifacesMVar name info =
72+compileModule tell project answersMVar ifacesMVar name info =
7473 do mvar <- newEmptyMVar
7574
7675 void $ forkIO $
@@ -81,18 +80,17 @@ compileModule tell project maybeDocsPath answersMVar ifacesMVar name info =
8180 else
8281 do tell (Progress.CompileFileStart name)
8382 let pkg = Project.getName project
84− let docs = toDocsFlag name project maybeDocsPath
8583 let imports = makeImports project info
8684 ifaces <- readMVar ifacesMVar
8785 let source = Plan._src info
88− case Compiler.compile docs pkg imports ifaces source of
86+ case Compiler.compile pkg imports ifaces source of
8987 (_warnings, Left errors) ->
9088 do tell (Progress.CompileFileEnd name Progress.Bad)
9189 let time = Plan._time info
9290 let path = Plan._path info
9391 putMVar mvar (Bad path time source errors)
9492
95− (_warnings, Right result@(Compiler.Artifacts elmi _ _)) ->
93+ (_warnings, Right result@(Compiler.Artifacts elmi _)) ->
9694 do tell (Progress.CompileFileEnd name Progress.Good)
9795 let canonicalName = ModuleName.Canonical pkg name
9896 lock <- takeMVar ifacesMVar
@@ -103,38 +101,6 @@ compileModule tell project maybeDocsPath answersMVar ifacesMVar name info =
103101
104102
105103
106−-- TO DOCS FLAG
107−
108−
109−toDocsFlag :: ModuleName.Raw -> Project -> Maybe FilePath -> Compiler.DocsFlag
110−toDocsFlag name project maybeDocsPath =
111− case maybeDocsPath of
112− Nothing ->
113− Compiler.NoDocs
114−
115− Just _ ->
116− case project of
117− Project.App _ ->
118− Compiler.NoDocs
119−
120− Project.Pkg info ->
121− if isExposed name (Project._pkg_exposed info) then
122− Compiler.YesDocs
123− else
124− Compiler.NoDocs
125−
126−
127−isExposed :: ModuleName.Raw -> Project.Exposed -> Bool
128−isExposed name exposed =
129− case exposed of
130− Project.ExposedList modules ->
131− elem name modules
132−
133− Project.ExposedDict chunks ->
134− elem name (concatMap snd chunks)
135−
136−
137−
138104-- IMPORTS
139105
140106
builder/src/File/Plan.hs+5−13
@@ -6,6 +6,7 @@ module File.Plan
66 )
77 where
88
9+
910import Control.Concurrent (forkIO)
1011import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
1112import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, readMVar)
@@ -35,11 +36,11 @@ import qualified Stuff.Paths
3536type Dict value = Map.Map ModuleName.Raw value
3637
3738
38−plan :: Maybe FilePath -> Summary.Summary -> Crawl.Result -> Task.Task (Dict Info, I.Interfaces)
39−plan docs (Summary.Summary root project _ ifaces _) (Crawl.Graph _ locals _ foreigns _) =
39+plan :: Summary.Summary -> Crawl.Result -> Task.Task (Dict Info, I.Interfaces)
40+plan (Summary.Summary root project _ ifaces _) (Crawl.Graph _ locals _ foreigns _) =
4041 liftIO $
4142 do queue <- newChan
42− let env = Env queue root (Project.getName project) docs
43+ let env = Env queue root (Project.getName project)
4344
4445 mvar <- newEmptyMVar
4546 statusMVars <- Map.traverseWithKey (getStatus env mvar foreigns) locals
@@ -57,7 +58,6 @@ data Env =
5758 { _queue :: Chan Msg
5859 , _root :: FilePath
5960 , _pkg :: Pkg.Name
60− , _docs :: Maybe FilePath
6161 }
6262
6363
@@ -100,29 +100,21 @@ getStatus env statusMVars foreigns name (Header.Info path time src deps) =
100100 info <- foldM (addDep statuses foreigns) (Info path time src [] [] []) deps
101101
102102 let elmi = Stuff.Paths.elmi (_root env) name
103− let docs = Stuff.Paths.moduleDocs (_root env) name
104103
105104 case _dirty info of
106105 _ : _ ->
107106 do remove elmi
108− remove docs
109107 return (Just info)
110108
111109 [] ->
112110 do freshElmi <- isFresh time elmi
113− freshDocs <-
114− case _docs env of
115− Nothing -> return True
116− Just _ -> isFresh time docs
117−
118− if name /= "Main" && freshElmi && freshDocs
111+ if name /= "Main" && freshElmi
119112 then
120113 do let canonical = ModuleName.Canonical (_pkg env) name
121114 writeChan (_queue env) (Get canonical elmi)
122115 return Nothing
123116 else
124117 do remove elmi
125− remove docs
126118 return (Just info)
127119
128120 return mvar
builder/src/Generate/Artifacts.hs+3−22
@@ -1,7 +1,6 @@
11module Generate.Artifacts
22 ( ignore
33 , write
4− , writeDocs
54 )
65 where
76
@@ -11,15 +10,12 @@ import Control.Concurrent.MVar (newEmptyMVar, putMVar, readMVar)
1110import Control.Monad (foldM, void)
1211import Control.Monad.Except (liftIO)
1312import qualified Data.Binary as Binary
13+import qualified Data.ByteString.UTF8 as BS_UTF8
1414import Data.Map (Map)
1515import qualified Data.Map as Map
16−import qualified Data.Maybe as Maybe
17−import qualified Data.Text.Encoding as Text
1816
1917import qualified Elm.Compiler as Compiler
20−import qualified Elm.Docs as Docs
2118import qualified Elm.ModuleName as ModuleName
22−import qualified Json.Encode as Encode
2319
2420import File.Compile (Answer(..))
2521import qualified Reporting.Exit.Compile as E
@@ -48,7 +44,7 @@ ignore answers =
4844write :: FilePath -> Map ModuleName.Raw Answer -> Task.Task (Map ModuleName.Raw Compiler.Artifacts)
4945write root answers =
5046 let
51− writer name result@(Compiler.Artifacts elmi elmo _) =
47+ writer name result@(Compiler.Artifacts elmi elmo) =
5248 do mvar <- newEmptyMVar
5349 void $ forkIO $
5450 do Binary.encodeFile (Path.elmi root name) elmi
@@ -60,21 +56,6 @@ write root answers =
6056 liftIO $ traverse readMVar mvars
6157
6258
63−writeDocs :: Map ModuleName.Raw Compiler.Artifacts -> FilePath -> Task.Task Docs.Documentation
64−writeDocs results path =
65− let
66− getDocs (Compiler.Artifacts _ _ docs) =
67− docs
68− in
69− case Maybe.mapMaybe getDocs (Map.elems results) of
70− [] ->
71− return Map.empty
72−
73− docs ->
74− do liftIO $ Encode.writeUgly path $ Encode.list Docs.encode docs
75− return $ Docs.toDict docs
76−
77−
7859
7960-- GATHER
8061
@@ -102,7 +83,7 @@ gatherHelp onGood summary (name, answer) =
10283 return summary
10384
10485 Bad path time src errors ->
105− do let err = E.Exit name path time (Text.decodeUtf8 src) errors
86+ do let err = E.Exit name path time (BS_UTF8.toString src) errors
10687 return (addErr err summary)
10788
10889 Good result ->
compiler/src/Compile.hs+5−29
@@ -1,7 +1,6 @@
11{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
22module Compile
3− ( DocsFlag(..)
4− , compile
3+ ( compile
54 , Artifacts(..)
65 )
76 where
@@ -14,13 +13,12 @@ import qualified Data.Name as Name
1413import qualified AST.Canonical as Can
1514import qualified AST.Optimized as Opt
1615import qualified Canonicalize.Module as Canonicalize
17−import qualified Elm.Docs as Docs
1816import qualified Elm.Interface as I
1917import qualified Elm.ModuleName as ModuleName
2018import qualified Elm.Package as Pkg
2119import qualified Nitpick.PatternMatches as PatternMatches
2220import qualified Optimize.Module as Optimize
23−import qualified Parse.Parse as Parse
21+import qualified Parse.Module as Parse
2422import qualified Reporting.Error as Error
2523import qualified Reporting.Render.Type.Localizer as L
2624import qualified Reporting.Result as Result
@@ -47,15 +45,14 @@ data Artifacts =
4745 Artifacts
4846 { _elmi :: I.Interface
4947 , _elmo :: Opt.Graph
50− , _docs :: Maybe Docs.Module
5148 }
5249
5350
54−compile :: DocsFlag -> Pkg.Name -> ImportDict -> I.Interfaces -> BS.ByteString -> Result i Artifacts
55−compile flag pkg importDict interfaces source =
51+compile :: Pkg.Name -> ImportDict -> I.Interfaces -> BS.ByteString -> Result i Artifacts
52+compile pkg importDict interfaces source =
5653 do
5754 valid <- Result.mapError Error.Syntax $
58− Parse.program pkg source
55+ Parse.fromByteString pkg source
5956
6057 canonical <- Result.mapError Error.Canonicalize $
6158 Canonicalize.canonicalize pkg importDict interfaces valid
@@ -71,14 +68,10 @@ compile flag pkg importDict interfaces source =
7168 graph <- Result.mapError (Error.Main localizer) $
7269 Optimize.optimize annotations canonical
7370
74− documentation <-
75− genarateDocs flag canonical
76−
7771 Result.ok $
7872 Artifacts
7973 { _elmi = I.fromModule annotations canonical
8074 , _elmo = graph
81− , _docs = documentation
8275 }
8376
8477
@@ -108,20 +101,3 @@ exhaustivenessCheck canonical =
108101
109102 Right () ->
110103 Result.ok ()
111−
112−
113−
114−-- DOCUMENTATION
115−
116−
117−data DocsFlag = YesDocs | NoDocs
118−
119−
120−genarateDocs :: DocsFlag -> Can.Module -> Result.Result i w Error.Error (Maybe Docs.Module)
121−genarateDocs flag modul =
122− case flag of
123− NoDocs ->
124− Result.ok Nothing
125−
126− YesDocs ->
127− Just <$> Docs.fromModule modul
compiler/src/Elm/Compiler.hs+37−32
@@ -1,8 +1,6 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Elm.Compiler
3− ( version
4− , Compile.DocsFlag(..)
5− , Compile.Artifacts(..)
3+ ( Compile.Artifacts(..)
64 , compile
75 , Error.Error
86 , errorsToDoc
@@ -14,52 +12,43 @@ module Elm.Compiler
1412
1513import qualified Data.ByteString as BS
1614import qualified Data.Map as Map
17−import qualified Data.Text as Text
15+import qualified Data.Name as Name
16+import qualified Data.Utf8 as Utf8
1817
1918import qualified Compile
20−import qualified Elm.Compiler.Version
2119import qualified Elm.Interface as I
2220import qualified Elm.ModuleName as ModuleName
2321import qualified Elm.Package as Pkg
24−import qualified Json.Encode as Encode
22+import qualified Json.Encode as E
23+import Json.Encode ((==>))
24+import qualified Reporting.Annotation as A
2525import qualified Reporting.Doc as D
2626import qualified Reporting.Error as Error
2727import qualified Reporting.Render.Code as Code
28−import qualified Reporting.Region as Region
2928import qualified Reporting.Report as Report
3029import qualified Reporting.Result as Result
3130import qualified Reporting.Warning as Warning
3231
3332
3433
35−-- VERSION
36−
37−
38−version :: Pkg.Version
39−version =
40− Elm.Compiler.Version.version
41−
42−
43−
4434-- COMPILE
4535
4636
4737compile
48− :: Compile.DocsFlag
49− -> Pkg.Name
38+ :: Pkg.Name
5039 -> Map.Map ModuleName.Raw ModuleName.Canonical
5140 -> I.Interfaces
5241 -> BS.ByteString
5342 -> ( [Warning.Warning], Either [Error.Error] Compile.Artifacts )
54−compile docsFlag pkg importDict interfaces source =
55− Result.run $ Compile.compile docsFlag pkg importDict interfaces source
43+compile pkg importDict interfaces source =
44+ Result.run $ Compile.compile pkg importDict interfaces source
5645
5746
5847
5948-- ERRORS TO DOC
6049
6150
62−errorsToDoc :: FilePath -> Text.Text -> [Error.Error] -> D.Doc
51+errorsToDoc :: FilePath -> String -> [Error.Error] -> D.Doc
6352errorsToDoc filePath source errors =
6453 let
6554 reports =
@@ -72,23 +61,39 @@ errorsToDoc filePath source errors =
7261-- ERRORS TO JSON
7362
7463
75−errorsToJson :: ModuleName.Raw -> FilePath -> Text.Text -> [Error.Error] -> Encode.Value
64+errorsToJson :: ModuleName.Raw -> FilePath -> String -> [Error.Error] -> E.Value
7665errorsToJson moduleName filePath source errors =
7766 let
7867 reports =
7968 concatMap (Error.toReports (Code.toSource source)) errors
8069 in
81− Encode.object
82− [ ("path", Encode.text (Text.pack filePath))
83− , ("name", Encode.name moduleName)
84− , ("problems", Encode.array (map reportToJson reports))
70+ E.object
71+ [ "path" ==> E.string (Utf8.fromChars filePath)
72+ , "name" ==> E.string (Name.toUtf8 moduleName)
73+ , "problems" ==> E.array (map reportToJson reports)
8574 ]
8675
8776
88−reportToJson :: Report.Report -> Encode.Value
77+reportToJson :: Report.Report -> E.Value
8978reportToJson (Report.Report title region _sgstns message) =
90− Encode.object
91− [ ("title", Encode.text (Text.pack title))
92− , ("region", Region.encode region)
93− , ("message", D.encode message)
94− ]
79+ E.object
80+ [ "title" ==> E.string (Utf8.fromChars title)
81+ , "region" ==> encodeRegion region
82+ , "message" ==> D.encode message
83+ ]
84+
85+
86+encodeRegion :: A.Region -> E.Value
87+encodeRegion (A.Region (A.Position sr sc) (A.Position er ec)) =
88+ E.object
89+ [ "start" ==>
90+ E.object
91+ [ ("line", E.int (fromIntegral sr))
92+ , ("column", E.int (fromIntegral sc))
93+ ]
94+ , "end" ==>
95+ E.object
96+ [ ("line", E.int (fromIntegral er))
97+ , ("column", E.int (fromIntegral ec))
98+ ]
99+ ]
terminal/src/Develop.hs+1−1
@@ -167,7 +167,7 @@ compileToHtmlBuilder file =
167167
168168 void $ Task.try reporter $
169169 do summary <- Project.getRoot
170− Project.compile Output.Dev Output.Client output Nothing summary [file]
170+ Project.compile Output.Dev Output.Client output summary [file]
171171
172172 result <- takeMVar mvar1
173173 case result of
terminal/src/Develop/StaticFiles/Build.hs+1−1
@@ -36,7 +36,7 @@ compile =
3636 Task.run reporter $
3737 do summary <- Project.getRoot
3838 let jsOutput = Just (Output.JavaScript Nothing tempFileName)
39− Project.compile Output.Prod Output.Client jsOutput Nothing summary rootPaths
39+ Project.compile Output.Prod Output.Client jsOutput summary rootPaths
4040
4141 result <- BS.readFile tempFileName
4242 seq (BS.length result) (Dir.removeFile tempFileName)
terminal/src/Make.hs+2−2
@@ -36,12 +36,12 @@ data Flags =
3636
3737
3838run :: [FilePath] -> Flags -> IO ()
39−run paths (Flags debug optimize output report docs) =
39+run paths (Flags debug optimize output report _docs) =
4040 do reporter <- toReporter report
4141 Task.run reporter $
4242 do mode <- toMode debug optimize
4343 summary <- Project.getRoot
44− Project.compile mode Output.Client output docs summary paths
44+ Project.compile mode Output.Client output summary paths
4545
4646
4747toMode :: Bool -> Bool -> Task.Task Output.Mode