Skip to content

Commit

Permalink
finish splitting out swarm-doc sublibrary
Browse files Browse the repository at this point in the history
- `Swarm.Doc.Pedagogy` depended on `Swarm.TUI.Controller`, but that
  was easy to resolve: it only needed `getTutorials`, which was easy to
  move to `Swarm.Game.ScenarioInfo` (which is a better place for it
  anyway).
- A thornier problem is that the swarm-docs executable has an option
  for generating all the web API endpoints, so it depends on
  `Swarm.Web`. But `Swarm.Web` depends on `Swarm.Doc.Command` so that
  the list of commands can be accessed via the web interface.  For now
  I commented out the `swarm-docs` command to print the web API, so
  `swarm-web` only depends on `swarm-doc` and not the other way around.
  • Loading branch information
byorgey committed May 10, 2024
1 parent c3658ba commit e18a329
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/doc/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cliParser =
, command "keys" (info (pure SpecialKeyNames) $ progDesc "Output list of recognized special key names")
, command "cheatsheet" (info (CheatSheet <$> address <*> cheatsheet <**> helper) $ progDesc "Output nice Wiki tables")
, command "pedagogy" (info (pure TutorialCoverage) $ progDesc "Output tutorial coverage")
, command "endpoints" (info (pure WebAPIEndpoints) $ progDesc "Generate markdown Web API documentation.")
-- , command "endpoints" (info (pure WebAPIEndpoints) $ progDesc "Generate markdown Web API documentation.")
]
where
editor :: Parser (Maybe EditorType)
Expand Down
10 changes: 0 additions & 10 deletions src/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ module Swarm.TUI.Controller (
-- ** Info panel
handleInfoPanelEvent,

-- ** Utils
getTutorials,
) where

import Brick hiding (Direction, Location)
Expand Down Expand Up @@ -140,9 +138,6 @@ import Prelude hiding (Applicative (..)) -- See Note [liftA2 re-export from Prel
-- we could get rid of both explicit imports and just get liftA2 and
-- pure implicitly from Prelude.

tutorialsDirname :: FilePath
tutorialsDirname = "Tutorials"

-- | The top-level event handler for the TUI.
handleEvent :: BrickEvent Name AppEvent -> EventM Name AppState ()
handleEvent = \case
Expand Down Expand Up @@ -226,11 +221,6 @@ handleMainMenuEvent menu = \case
uiState . uiMenu .= MainMenu menu'
_ -> continueWithoutRedraw

getTutorials :: ScenarioCollection -> ScenarioCollection
getTutorials sc = case M.lookup tutorialsDirname (scMap sc) of
Just (SICollection _ c) -> c
_ -> error $ "No tutorials exist: " ++ show sc

-- | If we are in a New Game menu, advance the menu to the next item in order.
--
-- NOTE: be careful to maintain the invariant that the currently selected
Expand Down
8 changes: 4 additions & 4 deletions src/swarm-doc/Swarm/Doc/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Swarm.Game.World.Typecheck (Some (..), TTerm)
import Swarm.Language.Key (specialKeyNames)
import Swarm.Util (both, listEnums)
import Swarm.Util.Effect (simpleErrorHandle)
import Swarm.Web (swarmApiMarkdown)
-- import Swarm.Web (swarmApiMarkdown)
import Text.Dot (Dot, NodeId, (.->.))
import Text.Dot qualified as Dot

Expand All @@ -68,8 +68,8 @@ data GenerateDocs where
CheatSheet :: PageAddress -> Maybe SheetType -> GenerateDocs
-- | List command introductions by tutorial
TutorialCoverage :: GenerateDocs
-- | Web API endpoints
WebAPIEndpoints :: GenerateDocs
-- -- | Web API endpoints
-- WebAPIEndpoints :: GenerateDocs
deriving (Eq, Show)

-- | Generate the requested kind of documentation to stdout.
Expand All @@ -90,7 +90,7 @@ generateDocs = \case
SpecialKeyNames -> generateSpecialKeyNames
CheatSheet address s -> makeWikiPage address s
TutorialCoverage -> renderTutorialProgression >>= putStrLn . T.unpack
WebAPIEndpoints -> putStrLn swarmApiMarkdown
-- WebAPIEndpoints -> putStrLn swarmApiMarkdown

-- ----------------------------------------------------------------------------
-- GENERATE KEYWORDS: LIST OF WORDS TO BE HIGHLIGHTED
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-doc/Swarm/Doc/Pedagogy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Swarm.Game.ScenarioInfo (
ScenarioCollection,
ScenarioInfoPair,
flatten,
getTutorials,
loadScenarios,
scenarioCollectionToList,
scenarioPath,
Expand All @@ -58,7 +59,6 @@ import Swarm.Language.Pipeline (ProcessedTerm (..))
import Swarm.Language.Syntax
import Swarm.Language.Text.Markdown (docToText, findCode)
import Swarm.Language.Types (Polytype)
import Swarm.TUI.Controller (getTutorials)
import Swarm.Util.Effect (ignoreWarnings, simpleErrorHandle)

-- * Constants
Expand Down
17 changes: 15 additions & 2 deletions src/swarm-engine/Swarm/Game/ScenarioInfo.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}

-- -Wno-orphans is for the Eq/Ord Time instances

-- |
-- SPDX-License-Identifier: BSD-3-Clause
--
Expand All @@ -27,6 +25,10 @@ module Swarm.Game.ScenarioInfo (
scenarioItemName,
_SISingle,

-- ** Tutorials
tutorialsDirname,
getTutorials,

-- * Loading and saving scenarios
loadScenarios,
loadScenarioInfo,
Expand Down Expand Up @@ -103,6 +105,17 @@ scenarioItemByPath path = ixp ps
SISingle {} -> pure si
SICollection n' col -> SICollection n' <$> ixp xs f col

-- | Subdirectory of the scenarios directory where tutorials are stored.
tutorialsDirname :: FilePath
tutorialsDirname = "Tutorials"

-- | Extract just the collection of tutorial scenarios from the entire
-- scenario collection.
getTutorials :: ScenarioCollection -> ScenarioCollection
getTutorials sc = case M.lookup tutorialsDirname (scMap sc) of
Just (SICollection _ c) -> c
_ -> error $ "No tutorials exist: " ++ show sc

-- | Canonicalize a scenario path, making it usable as a unique key.
normalizeScenarioPath ::
(MonadIO m) =>
Expand Down
28 changes: 10 additions & 18 deletions swarm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ library swarm-web
swarm,
swarm:swarm-lang,
swarm:swarm-util,
swarm:swarm-doc,

hs-source-dirs: src/swarm-web
default-language: Haskell2010
Expand Down Expand Up @@ -559,12 +560,20 @@ library swarm-doc
aeson >=2.2 && <2.3,
base >=4.14 && <4.20,
containers >=0.6.2 && <0.8,
directory >=1.3 && <1.4,
dotgen >=0.4 && <0.5,
extra >=1.7 && <1.8,
filepath >=1.4 && <1.5,
fused-effects >=1.1.1.1 && <1.2,
lens >=4.19 && <5.4,
mtl >=2.2.2 && <2.4,
pandoc >=3.0 && <3.2,
pandoc-types >=1.23 && <1.24,
scientific >=0.3.6 && <0.3.8,
servant-docs >=0.12 && <0.14,
text >=1.2.4 && <2.2,
transformers >=0.5 && <0.7,
vector >=0.12 && <0.14,

build-depends:
swarm:swarm-util,
Expand Down Expand Up @@ -796,7 +805,6 @@ library
swarm:swarm-lang,
swarm:swarm-scenario,
swarm:swarm-util,
swarm:swarm-doc,

hs-source-dirs: src
default-language: Haskell2010
Expand Down Expand Up @@ -854,26 +862,10 @@ executable swarm-docs

build-depends:
-- Imports shared with the library don't need bounds
aeson,
base,
containers,
directory,
dotgen >=0.4 && <0.5,
extra,
filepath,
fused-effects,
lens,
mtl,
optparse-applicative >=0.16 && <0.19,
pandoc >=3.0 && <3.2,
pandoc-types >=1.23 && <1.24,
scientific >=0.3.6 && <0.3.8,
swarm,
swarm:swarm-lang,
swarm:swarm-web,
swarm:swarm-doc,
text,
transformers,
vector,

hs-source-dirs: app/doc
default-language: Haskell2010
Expand Down

0 comments on commit e18a329

Please sign in to comment.