Skip to content

Commit

Permalink
remove Debug.todos #12
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Oct 6, 2024
1 parent 130f015 commit 072e5af
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 55 deletions.
5 changes: 5 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ const io = {
this.send({ index, value: answer });
});
},
replGetInputLineWithInitial: function (index, prompt, left, right) {
rl.question(prompt + left + right, (answer) => {
this.send({ index, value: answer });
});
},
procWithCreateProcess: function (index, createProcess) {
// FIXME needs review, only trying to implement the minimum for repl functionality
const file = tmp.fileSync();
Expand Down
49 changes: 34 additions & 15 deletions src/Builder/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module Builder.Build exposing
, fromPaths
, fromRepl
, getRootNames
, ignoreDocs
, keepDocs
, writeDocs
)

import Builder.Elm.Details as Details
Expand Down Expand Up @@ -142,7 +145,7 @@ fromExposed docsDecoder docsEncoder style root details docsGoal ((NE.Nonempty e
docsNeed =
toDocsNeed docsGoal
in
Utils.mapFromKeysA (fork statusEncoder << crawlModule env mvar docsNeed) (e :: es)
Map.fromKeysA compare (fork statusEncoder << crawlModule env mvar docsNeed) (e :: es)
|> IO.bind
(\roots ->
Utils.putMVar statusDictEncoder mvar roots
Expand Down Expand Up @@ -1142,10 +1145,25 @@ addImportProblems results name problems =
-- DOCS


type DocsGoal a
= KeepDocs
| WriteDocs FilePath
| IgnoreDocs
type DocsGoal docs
= KeepDocs (Dict ModuleName.Raw BResult -> docs)
| WriteDocs (Dict ModuleName.Raw BResult -> IO docs)
| IgnoreDocs docs


keepDocs : DocsGoal (Dict ModuleName.Raw Docs.Module)
keepDocs =
KeepDocs (Utils.mapMapMaybe compare toDocs)


writeDocs : FilePath -> DocsGoal ()
writeDocs path =
WriteDocs (E.writeUgly path << Docs.encode << Utils.mapMapMaybe compare toDocs)


ignoreDocs : DocsGoal ()
ignoreDocs =
IgnoreDocs ()


type DocsNeed
Expand All @@ -1155,13 +1173,13 @@ type DocsNeed
toDocsNeed : DocsGoal a -> DocsNeed
toDocsNeed goal =
case goal of
IgnoreDocs ->
IgnoreDocs _ ->
DocsNeed False

WriteDocs _ ->
DocsNeed True

KeepDocs ->
KeepDocs _ ->
DocsNeed True


Expand All @@ -1181,14 +1199,15 @@ makeDocs (DocsNeed isNeeded) modul =

finalizeDocs : DocsGoal docs -> Dict ModuleName.Raw BResult -> IO docs
finalizeDocs goal results =
-- case goal of
-- KeepDocs ->
-- IO.pure <| Utils.mapMapMaybe toDocs results
-- WriteDocs path ->
-- E.writeUgly path <| Docs.encode <| Utils.mapMapMaybe toDocs results
-- IgnoreDocs ->
-- IO.pure ()
Debug.todo "finalizeDocs"
case goal of
KeepDocs f ->
IO.pure <| f results

WriteDocs f ->
f results

IgnoreDocs val ->
IO.pure val


toDocs : BResult -> Maybe Docs.Module
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/Data/Map/Utils.elm
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module Compiler.Data.Map.Utils exposing
( any
, fromKeys
, fromKeysA
, fromValues
)

import Data.IO as IO exposing (IO)
import Data.Map as Dict exposing (Dict)
import Utils.Main as Utils



Expand All @@ -16,6 +19,11 @@ fromKeys toValue keys =
Dict.fromList compare (List.map (\k -> ( k, toValue k )) keys)


fromKeysA : (k -> k -> Order) -> (k -> IO v) -> List k -> IO (Dict k v)
fromKeysA keyComparison toValue keys =
IO.fmap (Dict.fromList keyComparison) (Utils.listTraverse (\k -> IO.fmap (Tuple.pair k) (toValue k)) keys)


fromValues : (v -> comparable) -> List v -> Dict comparable v
fromValues toKey values =
Dict.fromList compare (List.map (\v -> ( toKey v, v )) values)
Expand Down
7 changes: 2 additions & 5 deletions src/Compiler/Elm/Docs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,8 @@ chompOverview names =
|> P.bind
(\isDocs ->
if isDocs then
let
_ =
Space.chomp E.Space
in
P.bind chompOverview (chompDocs names)
Space.chomp E.Space
|> P.bind (\_ -> P.bind chompOverview (chompDocs names))

else
P.pure names
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Parse/Space.elm
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ docComment toExpectation toSpaceError =
MultiGood ->
let
off =
pos3 - pos
pos3

len =
newPos - pos3 - 2
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Reporting/Error.elm
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ errorEncoder error =
BadDocs docsErr ->
Encode.object
[ ( "type", Encode.string "BadDocs" )
, ( "errs", Docs.errorEncoder docsErr )
, ( "docsErr", Docs.errorEncoder docsErr )
]


Expand Down
1 change: 1 addition & 0 deletions src/Data/IO.elm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type Effect
| TakeMVar Int
| PutMVar Int Encode.Value
| ReplGetInputLine String
| ReplGetInputLineWithInitial String ( String, String )
| HClose Handle
| StateGet
| ProcWithCreateProcess CreateProcess
Expand Down
2 changes: 1 addition & 1 deletion src/Terminal/Bump.elm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ generateDocs root (Outline.PkgOutline _ _ _ _ exposed _ _ _) =

e :: es ->
Task.eio Exit.BumpBadBuild <|
Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.KeepDocs (NE.Nonempty e es)
Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.keepDocs (NE.Nonempty e es)
)


Expand Down
2 changes: 1 addition & 1 deletion src/Terminal/Diff.elm
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ generateDocs (Env maybeRoot _ _ _) =

e :: es ->
Task.eio Exit.DiffBadBuild <|
Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.KeepDocs (NE.Nonempty e es)
Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.keepDocs (NE.Nonempty e es)
)


Expand Down
10 changes: 10 additions & 0 deletions src/Terminal/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,16 @@ effectToCmd index portOut effect =
]
}

IO.ReplGetInputLineWithInitial prompt ( left, right ) ->
portOut
{ index = index
, value =
Encode.object
[ ( "fn", Encode.string "replGetInputLineWithInitial" )
, ( "args", Encode.list Encode.string [ prompt, left, right ] )
]
}

IO.HClose (IO.Handle fd) ->
portOut
{ index = index
Expand Down
2 changes: 1 addition & 1 deletion src/Terminal/Make.elm
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ buildExposed : Reporting.Style -> FilePath -> Details.Details -> Maybe FilePath
buildExposed style root details maybeDocs exposed =
let
docsGoal =
Maybe.maybe Build.IgnoreDocs Build.WriteDocs maybeDocs
Maybe.maybe Build.ignoreDocs Build.writeDocs maybeDocs
in
Task.eio Exit.MakeCannotBuild <|
Build.fromExposed (Decode.succeed ()) (\_ -> Encode.object []) style root details docsGoal exposed
Expand Down
4 changes: 2 additions & 2 deletions src/Terminal/Publish.elm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ verifyBuild root =
|> Task.bind
(\exposed ->
Task.eio Exit.PublishBuildProblem <|
Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.KeepDocs exposed
Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.keepDocs exposed
)
)
)
Expand Down Expand Up @@ -416,7 +416,7 @@ verifyZipBuild root =
|> Task.bind
(\exposed ->
Task.eio Exit.PublishZipBuildProblem
(Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.KeepDocs exposed)
(Build.fromExposed Docs.jsonDecoder Docs.jsonEncoder Reporting.silent root details Build.keepDocs exposed)
|> Task.fmap (\_ -> ())
)
)
Expand Down
41 changes: 21 additions & 20 deletions src/Terminal/Repl.elm
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,25 @@ read =

readMore : Lines -> Prefill -> Utils.ReplInputT Input
readMore previousLines prefill =
-- Utils.replGetInputLineWithInitial "| " ( renderPrefill prefill, "" )
-- |> IO.bind
-- (\input ->
-- case input of
-- Nothing ->
-- IO.pure Skip
-- Just chars ->
-- let
-- lines =
-- addLine (stripLegacyBackslash chars) previousLines
-- in
-- case categorize lines of
-- Done doneInput ->
-- IO.pure doneInput
-- Continue p ->
-- readMore lines p
-- )
Debug.todo "readMore"
Utils.replGetInputLineWithInitial "| " ( renderPrefill prefill, "" )
|> IO.bind
(\input ->
case input of
Nothing ->
IO.pure Skip

Just chars ->
let
lines =
addLine (stripLegacyBackslash chars) previousLines
in
case categorize lines of
Done doneInput ->
IO.pure doneInput

Continue p ->
readMore lines p
)



Expand Down Expand Up @@ -269,9 +270,9 @@ type Lines
= Lines String (List String)


addLine : List Char -> Lines -> Lines
addLine : String -> Lines -> Lines
addLine line (Lines x xs) =
Lines (String.fromList line) (x :: xs)
Lines line (x :: xs)


isBlank : Lines -> Bool
Expand Down
10 changes: 2 additions & 8 deletions src/Utils/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ module Utils.Main exposing
, mVarEncoder
, mapFindMin
, mapFromKeys
, mapFromKeysA
, mapFromListWith
, mapInsertWith
, mapIntersectionWith
Expand Down Expand Up @@ -211,11 +210,6 @@ fpAddExtension path extension =
path ++ "." ++ extension


mapFromKeysA : (k -> IO v) -> List k -> IO (Dict k v)
mapFromKeysA _ _ =
Debug.todo "mapFromKeysA"


mapFromListWith : (k -> k -> Order) -> (a -> a -> a) -> List ( k, a ) -> Dict k a
mapFromListWith keyComparison f =
List.foldl
Expand Down Expand Up @@ -1224,8 +1218,8 @@ replGetInputLine prompt =


replGetInputLineWithInitial : String -> ( String, String ) -> ReplInputT (Maybe String)
replGetInputLineWithInitial =
Debug.todo "replGetInputLineWithInitial"
replGetInputLineWithInitial prompt ( left, right ) =
IO.make (Decode.maybe Decode.string) (IO.ReplGetInputLineWithInitial prompt ( left, right ))



Expand Down

0 comments on commit 072e5af

Please sign in to comment.