⅄ trunk → arya/ooo-sync

This commit is contained in:
Mitchell Rosen 2022-05-05 15:06:36 -04:00
commit 28425c6d2e
22 changed files with 1054 additions and 82 deletions

View File

@ -1,17 +1,22 @@
packages:
yaks/easytest
parser-typechecker
unison-core
unison-cli
lib/unison-prelude
lib/unison-util-relation
codebase2/codebase
codebase2/codebase-sqlite
codebase2/codebase-sync
codebase2/core
codebase2/util
codebase2/util-serialization
codebase2/util-term
yaks/easytest
parser-typechecker
unison-core
unison-cli
unison-share-api
codebase2/codebase
codebase2/codebase-sqlite
codebase2/codebase-sync
codebase2/core
codebase2/util
codebase2/util-serialization
codebase2/util-term
lib/unison-prelude
lib/unison-sqlite
lib/unison-util-relation
lib/unison-pretty-printer
source-repository-package
type: git
@ -28,6 +33,11 @@ source-repository-package
location: https://github.com/unisonweb/megaparsec.git
tag: c4463124c578e8d1074c04518779b5ce5957af6b
source-repository-package
type: git
location: https://github.com/unisonweb/shellmet.git
tag: 2fd348592c8f51bb4c0ca6ba4bc8e38668913746
allow-newer:
haskeline:base
@ -39,6 +49,15 @@ package easytest
package parser-typechecker
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package unison-core
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package unison-cli
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package unison-share-api
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package codebase
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
@ -60,6 +79,18 @@ package util-serialization
package util-term
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package unison-prelude
ghc-options: -Wall -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package unison-sqlite
ghc-options: -Wall -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package unison-util-relation
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
package unison-pretty-printer
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info
-- This options are applied to all packages, local ones and also external dependencies.
package *
ghc-options: -haddock

View File

@ -44,7 +44,7 @@ extra-deps:
- prelude-extras-0.4.0.3@sha256:1c10b0123ea13a6423d74a8fcbaeb2d5249b472588abde418a36b47b7c4f48c8,1163
- sandi-0.5@sha256:b278d072ca717706ea38f9bd646e023f7f2576a778fb43565b434f93638849aa,3010
- strings-1.1@sha256:0285dec4c8ab262359342b3e5ef1eb567074669461b9b38404f1cb870c881c5c,1617
- fuzzyfind-3.0.0
- fuzzyfind-3.0.0@sha256:d79a5d3ed194dd436c6b839bf187211d880cf773b2febaca456e5ccf93f5ac65,1814
- monad-validate-1.2.0.0@sha256:9850f408431098b28806dd464b6825a88a0b56c84f380d7fe0454c1df9d6f881,3505
- NanoID-3.1.0@sha256:9118ab00e8650b5a56a10c90295d357eb77a8057a598b7e56dfedc9c6d53c77d,1524
# not in lts-18.13

View File

@ -5,122 +5,122 @@
packages:
- completed:
sha256: d4fd87fb7bfc5d8e9fbc3e4ee7302c6b1500cdc00fdb9b659d0f4849b6ebe2d5
name: configurator
size: 15989
url: https://github.com/unisonweb/configurator/archive/e47e9e9fe1f576f8c835183b9def52d73c01327a.tar.gz
name: configurator
version: 0.3.0.0
sha256: d4fd87fb7bfc5d8e9fbc3e4ee7302c6b1500cdc00fdb9b659d0f4849b6ebe2d5
pantry-tree:
size: 955
sha256: 90547cd983fd15ebdc803e057d3ef8735fe93a75e29a00f8a74eadc13ee0f6e9
size: 955
version: 0.3.0.0
original:
url: https://github.com/unisonweb/configurator/archive/e47e9e9fe1f576f8c835183b9def52d73c01327a.tar.gz
- completed:
sha256: 6d44207a4e94a16bc99d13dccbbb79bf676190c0476436b03235eeeaf6c72f9d
name: haskeline
size: 75098
url: https://github.com/unisonweb/haskeline/archive/2944b11d19ee034c48276edc991736105c9d6143.tar.gz
name: haskeline
version: 0.7.5.0
sha256: 6d44207a4e94a16bc99d13dccbbb79bf676190c0476436b03235eeeaf6c72f9d
pantry-tree:
size: 3717
sha256: 878c7fb5801ec7418761a49b529ca3fdab274f22707c7d2759f2b3a2df06c3ea
size: 3717
version: 0.7.5.0
original:
url: https://github.com/unisonweb/haskeline/archive/2944b11d19ee034c48276edc991736105c9d6143.tar.gz
- completed:
sha256: 94f9573735fefda868371ff735a6b1f52bea22b9e52289abeb8114c99bbf8832
name: megaparsec
size: 92490
url: https://github.com/unisonweb/megaparsec/archive/c4463124c578e8d1074c04518779b5ce5957af6b.tar.gz
name: megaparsec
version: 6.5.0
sha256: 94f9573735fefda868371ff735a6b1f52bea22b9e52289abeb8114c99bbf8832
pantry-tree:
size: 2635
sha256: 7d3f8b23c862d878b4adce628caaf7bc337f0ac10b2556e1cdf0913c28a45929
size: 2635
version: 6.5.0
original:
url: https://github.com/unisonweb/megaparsec/archive/c4463124c578e8d1074c04518779b5ce5957af6b.tar.gz
- completed:
sha256: 6e642163070a217cc3363bdbefde571ff6c1878f4fc3d92e9c910db7fa88eaf2
name: shellmet
size: 10460
url: https://github.com/unisonweb/shellmet/archive/2fd348592c8f51bb4c0ca6ba4bc8e38668913746.tar.gz
name: shellmet
version: 0.0.4.0
sha256: 6e642163070a217cc3363bdbefde571ff6c1878f4fc3d92e9c910db7fa88eaf2
pantry-tree:
size: 654
sha256: 05a169a7a6b68100630e885054dc1821d31cd06571b0317ec90c75ac2c41aeb7
size: 654
version: 0.0.4.0
original:
url: https://github.com/unisonweb/shellmet/archive/2fd348592c8f51bb4c0ca6ba4bc8e38668913746.tar.gz
- completed:
hackage: guid-0.1.0@sha256:a7c975be473f6f142d5cc1b39bc807a99043d20b1bb0873fdfe7a3ce84d2faf1,1078
pantry-tree:
size: 364
sha256: a33838b7b1c54f6ac3e1b436b25674948713a4189658e4d82e639b9a689bc90d
size: 364
hackage: guid-0.1.0@sha256:a7c975be473f6f142d5cc1b39bc807a99043d20b1bb0873fdfe7a3ce84d2faf1,1078
original:
hackage: guid-0.1.0@sha256:a7c975be473f6f142d5cc1b39bc807a99043d20b1bb0873fdfe7a3ce84d2faf1,1078
- completed:
hackage: prelude-extras-0.4.0.3@sha256:1c10b0123ea13a6423d74a8fcbaeb2d5249b472588abde418a36b47b7c4f48c8,1163
pantry-tree:
size: 476
sha256: a03f60a1250c9d0daaf208ba58ccf24e05e0807f2e3dc7892fad3f2f3a196f7f
size: 476
hackage: prelude-extras-0.4.0.3@sha256:1c10b0123ea13a6423d74a8fcbaeb2d5249b472588abde418a36b47b7c4f48c8,1163
original:
hackage: prelude-extras-0.4.0.3@sha256:1c10b0123ea13a6423d74a8fcbaeb2d5249b472588abde418a36b47b7c4f48c8,1163
- completed:
hackage: sandi-0.5@sha256:b278d072ca717706ea38f9bd646e023f7f2576a778fb43565b434f93638849aa,3010
pantry-tree:
size: 3455
sha256: 5ca7ce4bc22ab9d4427bb149b5e283ab9db43375df14f7131fdfd48775f36350
size: 3455
hackage: sandi-0.5@sha256:b278d072ca717706ea38f9bd646e023f7f2576a778fb43565b434f93638849aa,3010
original:
hackage: sandi-0.5@sha256:b278d072ca717706ea38f9bd646e023f7f2576a778fb43565b434f93638849aa,3010
- completed:
hackage: strings-1.1@sha256:0285dec4c8ab262359342b3e5ef1eb567074669461b9b38404f1cb870c881c5c,1617
pantry-tree:
size: 212
sha256: 876e5a679244143e2a7e74357427c7522a8d61f68a4cc3ae265fe4960b75a2e2
size: 212
hackage: strings-1.1@sha256:0285dec4c8ab262359342b3e5ef1eb567074669461b9b38404f1cb870c881c5c,1617
original:
hackage: strings-1.1@sha256:0285dec4c8ab262359342b3e5ef1eb567074669461b9b38404f1cb870c881c5c,1617
- completed:
hackage: fuzzyfind-3.0.0@sha256:d79a5d3ed194dd436c6b839bf187211d880cf773b2febaca456e5ccf93f5ac65,1814
pantry-tree:
size: 542
sha256: 0e6c6d4f89083c8385de5adc4f36ad01b2b0ff45261b47f7d90d919969c8b5ed
size: 542
hackage: fuzzyfind-3.0.0@sha256:d79a5d3ed194dd436c6b839bf187211d880cf773b2febaca456e5ccf93f5ac65,1814
original:
hackage: fuzzyfind-3.0.0
hackage: fuzzyfind-3.0.0@sha256:d79a5d3ed194dd436c6b839bf187211d880cf773b2febaca456e5ccf93f5ac65,1814
- completed:
hackage: monad-validate-1.2.0.0@sha256:9850f408431098b28806dd464b6825a88a0b56c84f380d7fe0454c1df9d6f881,3505
pantry-tree:
size: 713
sha256: 8e049bd12ce2bd470909578f2ee8eb80b89d5ff88860afa30e29dd4eafecfa3e
size: 713
hackage: monad-validate-1.2.0.0@sha256:9850f408431098b28806dd464b6825a88a0b56c84f380d7fe0454c1df9d6f881,3505
original:
hackage: monad-validate-1.2.0.0@sha256:9850f408431098b28806dd464b6825a88a0b56c84f380d7fe0454c1df9d6f881,3505
- completed:
hackage: NanoID-3.1.0@sha256:9118ab00e8650b5a56a10c90295d357eb77a8057a598b7e56dfedc9c6d53c77d,1524
pantry-tree:
size: 363
sha256: d33d603a2f0d1a220ff0d5e7edb6273def89120e6bb958c2d836cae89e788334
size: 363
hackage: NanoID-3.1.0@sha256:9118ab00e8650b5a56a10c90295d357eb77a8057a598b7e56dfedc9c6d53c77d,1524
original:
hackage: NanoID-3.1.0@sha256:9118ab00e8650b5a56a10c90295d357eb77a8057a598b7e56dfedc9c6d53c77d,1524
- completed:
hackage: recover-rtti-0.4.0.0@sha256:2ce1e031ec0e34d736fa45f0149bbd55026f614939dc90ffd14a9c5d24093ff4,4423
pantry-tree:
size: 2410
sha256: d87d84c3f760c1b2540f74e4a301cd4e8294df891e8e4262e8bdd313bc8e0bfd
size: 2410
hackage: recover-rtti-0.4.0.0@sha256:2ce1e031ec0e34d736fa45f0149bbd55026f614939dc90ffd14a9c5d24093ff4,4423
original:
hackage: recover-rtti-0.4.0.0@sha256:2ce1e031ec0e34d736fa45f0149bbd55026f614939dc90ffd14a9c5d24093ff4,4423
- completed:
hackage: lock-file-0.7.0.0@sha256:3ad84b5e454145e1d928063b56abb96db24a99a21b493989520e58fa0ab37b00,4484
pantry-tree:
size: 718
sha256: 3634593ce191e82793ea0e060598ab3cf67f2ef2fe1d65345dc9335ad529d25f
size: 718
hackage: lock-file-0.7.0.0@sha256:3ad84b5e454145e1d928063b56abb96db24a99a21b493989520e58fa0ab37b00,4484
original:
hackage: lock-file-0.7.0.0@sha256:3ad84b5e454145e1d928063b56abb96db24a99a21b493989520e58fa0ab37b00,4484
- completed:
hackage: http-client-0.7.11@sha256:3f59ac8ffe2a3768846cdda040a0d1df2a413960529ba61c839861c948871967,5756
pantry-tree:
size: 2547
sha256: 8372e84e9c710097f4f80f2016ca15a5a0cd7884b8ac5ce70f26b3110f4401bd
size: 2547
hackage: http-client-0.7.11@sha256:3f59ac8ffe2a3768846cdda040a0d1df2a413960529ba61c839861c948871967,5756
original:
hackage: http-client-0.7.11
snapshots:
- completed:
sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68
size: 590100
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml
sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68
original: lts-18.28

View File

@ -12,6 +12,7 @@ ghc-options: -Wall
dependencies:
- ListLike
- aeson
- aeson-pretty
- async
- base
- bytes

View File

@ -477,6 +477,7 @@ loop = do
"delete.term-replacement" <> HQ.toText src <> " " <> opatch p
RemoveTypeReplacementI src p ->
"delete.type-replacement" <> HQ.toText src <> " " <> opatch p
VersionI -> "version"
where
hp' = either (Text.pack . show) p'
p' = Text.pack . show . resolveToAbsolute
@ -1654,6 +1655,9 @@ loop = do
case mayHost of
Nothing -> respond (UnknownCodeServer codeServer)
Just host -> authLogin (Just $ Host host)
VersionI -> do
ucmVersion <- eval UCMVersion
respond $ PrintVersion ucmVersion
where
notImplemented = eval $ Notify NotImplemented
success = respond Success

View File

@ -186,6 +186,7 @@ data Input
| DocsToHtmlI Path' FilePath
| GistI GistInput
| AuthLoginI (Maybe CodebaseServerName)
| VersionI
deriving (Eq, Show)
-- | @"gist repo"@ pushes the contents of the current namespace to @repo@.

View File

@ -254,6 +254,7 @@ data Output v
InitiateAuthFlow URI
| UnknownCodeServer Text
| CredentialFailureMsg CredentialFailure
| PrintVersion Text
data ReflogEntry = ReflogEntry {hash :: ShortBranchHash, reason :: Text}
deriving (Show)
@ -379,6 +380,7 @@ isFailure o = case o of
InitiateAuthFlow {} -> False
UnknownCodeServer {} -> True
CredentialFailureMsg {} -> True
PrintVersion {} -> False
isNumberedFailure :: NumberedOutput v -> Bool
isNumberedFailure = \case

View File

@ -21,6 +21,9 @@ where
import Control.Concurrent.STM (atomically)
import Control.Lens (view)
import qualified Crypto.Random as Random
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Encode.Pretty as Aeson
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Char as Char
import qualified Data.Configurator as Configurator
import Data.Configurator.Types (Config)
@ -28,6 +31,7 @@ import Data.IORef
import Data.List (isSubsequenceOf)
import qualified Data.Map as Map
import qualified Data.Text as Text
import qualified Network.HTTP.Client as HTTP
import System.Directory (doesFileExist)
import System.Exit (die)
import qualified System.IO as IO
@ -54,14 +58,15 @@ import Unison.Parser.Ann (Ann)
import Unison.Prelude
import Unison.PrettyTerminal
import qualified Unison.Runtime.Interface as RTI
import qualified Unison.Server.CodebaseServer as Server
import Unison.Symbol (Symbol)
import qualified Unison.Util.Pretty as P
import qualified Unison.Util.Pretty as Pretty
import qualified Unison.Util.TQueue as Q
import qualified UnliftIO
import Prelude hiding (readFile, writeFile)
-- | Render transcript errors at a width of 65 chars.
terminalWidth :: P.Width
terminalWidth :: Pretty.Width
terminalWidth = 65
type ExpectingError = Bool
@ -77,9 +82,18 @@ data UcmLine
= UcmCommand Path.Absolute Text
| UcmComment Text -- Text does not include the '--' prefix.
data APIRequest
= GetRequest Text
| APIComment Text
instance Show APIRequest where
show (GetRequest txt) = "GET " <> Text.unpack txt
show (APIComment txt) = "-- " <> Text.unpack txt
data Stanza
= Ucm Hidden ExpectingError [UcmLine]
| Unison Hidden ExpectingError (Maybe ScratchFileName) Text
| API [APIRequest]
| UnprocessedFence FenceType Text
| Unfenced Text
@ -110,6 +124,13 @@ instance Show Stanza where
""
]
]
API apiRequests ->
"```api\n"
<> ( apiRequests
& fmap (\(GetRequest txt) -> Text.unpack txt)
& unlines
)
<> "```\n"
UnprocessedFence typ txt ->
unlines
[ "```" <> Text.unpack typ,
@ -150,10 +171,11 @@ withTranscriptRunner ::
withTranscriptRunner ucmVersion configFile action = do
withRuntime $ \runtime -> withConfig $ \config -> do
action $ \transcriptName transcriptSrc (codebaseDir, codebase) -> do
let parsed = parse transcriptName transcriptSrc
result <- for parsed $ \stanzas -> do
liftIO $ run codebaseDir stanzas codebase runtime config ucmVersion
pure $ join @(Either TranscriptError) result
Server.startServer Server.defaultCodebaseServerOpts runtime codebase $ \baseUrl -> do
let parsed = parse transcriptName transcriptSrc
result <- for parsed $ \stanzas -> do
liftIO $ run codebaseDir stanzas codebase runtime config ucmVersion (tShow baseUrl)
pure $ join @(Either TranscriptError) result
where
withRuntime :: ((Runtime.Runtime Symbol -> m a) -> m a)
withRuntime action =
@ -181,11 +203,13 @@ run ::
Runtime.Runtime Symbol ->
Maybe Config ->
UCMVersion ->
Text ->
IO (Either TranscriptError Text)
run dir stanzas codebase runtime config ucmVersion = UnliftIO.try $ do
run dir stanzas codebase runtime config ucmVersion baseURL = UnliftIO.try $ do
httpManager <- HTTP.newManager HTTP.defaultManagerSettings
let initialPath = Path.absoluteEmpty
putPrettyLn $
P.lines
Pretty.lines
[ asciiartUnison,
"",
"Running the provided transcript file...",
@ -224,6 +248,22 @@ run dir stanzas codebase runtime config ucmVersion = UnliftIO.try $ do
output = output' False
outputEcho = output' True
apiRequest :: APIRequest -> IO ()
apiRequest req = do
output (show req <> "\n")
case req of
(APIComment {}) -> pure ()
(GetRequest path) -> do
req <- case HTTP.parseRequest (Text.unpack $ baseURL <> path) of
Left err -> dieWithMsg (show err)
Right req -> pure req
respBytes <- HTTP.httpLbs req httpManager
case Aeson.eitherDecode (HTTP.responseBody respBytes) of
Right (v :: Aeson.Value) -> do
let prettyBytes = Aeson.encodePretty' (Aeson.defConfig {Aeson.confCompare = compare}) v
output . (<> "\n") . BL.unpack $ prettyBytes
Left err -> dieWithMsg ("Error decoding response from " <> Text.unpack path <> ": " <> err)
awaitInput :: IO (Either Event Input)
awaitInput = do
cmd <- atomically (Q.tryDequeue cmdQueue)
@ -257,7 +297,7 @@ run dir stanzas codebase runtime config ucmVersion = UnliftIO.try $ do
currentRoot <- Branch.head <$> readIORef rootBranchRef
case parseInput currentRoot curPath numberedArgs patternMap args of
-- invalid command is treated as a failure
Left msg -> dieWithMsg $ P.toPlain terminalWidth msg
Left msg -> dieWithMsg $ Pretty.toPlain terminalWidth msg
Right input -> pure $ Right input
Nothing -> do
dieUnexpectedSuccess
@ -290,6 +330,11 @@ run dir stanzas codebase runtime config ucmVersion = UnliftIO.try $ do
atomically . Q.enqueue cmdQueue $ Nothing
modifyIORef' unisonFiles (Map.insert (fromMaybe "scratch.u" filename) txt)
pure $ Left (UnisonFileChanged (fromMaybe "scratch.u" filename) txt)
API apiRequests -> do
output "```api\n"
for_ apiRequests apiRequest
output "```"
awaitInput
Ucm hide errOk cmds -> do
writeIORef hidden hide
writeIORef allowErrors errOk
@ -317,7 +362,7 @@ run dir stanzas codebase runtime config ucmVersion = UnliftIO.try $ do
print o = do
msg <- notifyUser dir o
errOk <- readIORef allowErrors
let rendered = P.toPlain terminalWidth (P.border 2 msg)
let rendered = Pretty.toPlain terminalWidth (Pretty.border 2 msg)
output rendered
when (Output.isFailure o) $
if errOk
@ -327,7 +372,7 @@ run dir stanzas codebase runtime config ucmVersion = UnliftIO.try $ do
printNumbered o = do
let (msg, numberedArgs) = notifyNumbered o
errOk <- readIORef allowErrors
let rendered = P.toPlain terminalWidth (P.border 2 msg)
let rendered = Pretty.toPlain terminalWidth (Pretty.border 2 msg)
output rendered
when (Output.isNumberedFailure o) $
if errOk
@ -443,31 +488,50 @@ ucmLine = ucmCommand <|> ucmComment
line <- P.takeWhileP Nothing (/= '\n') <* spaces
pure $ UcmComment line
apiRequest :: P APIRequest
apiRequest = do
apiComment <|> getRequest
where
getRequest = do
word "GET"
spaces
path <- P.takeWhile1P Nothing (/= '\n')
spaces
pure (GetRequest path)
apiComment = do
word "--"
comment <- P.takeWhileP Nothing (/= '\n')
spaces
pure (APIComment comment)
fenced :: P Stanza
fenced = do
fence
fenceType <- lineToken (word "ucm" <|> word "unison" <|> language)
fenceType <- lineToken (word "ucm" <|> word "unison" <|> word "api" <|> language)
stanza <-
if fenceType == "ucm"
then do
case fenceType of
"ucm" -> do
hide <- hidden
err <- expectingError
_ <- spaces
cmds <- many ucmLine
pure $ Ucm hide err cmds
else
if fenceType == "unison"
then do
-- todo: this has to be more interesting
-- ```unison:hide
-- ```unison
-- ```unison:hide:all scratch.u
hide <- lineToken hidden
err <- lineToken expectingError
fileName <- optional untilSpace1
blob <- spaces *> untilFence
pure $ Unison hide err fileName blob
else UnprocessedFence fenceType <$> untilFence
"unison" ->
do
-- todo: this has to be more interesting
-- ```unison:hide
-- ```unison
-- ```unison:hide:all scratch.u
hide <- lineToken hidden
err <- lineToken expectingError
fileName <- optional untilSpace1
blob <- spaces *> untilFence
pure $ Unison hide err fileName blob
"api" -> do
_ <- spaces
apiRequests <- many apiRequest
pure $ API apiRequests
_ -> UnprocessedFence fenceType <$> untilFence
fence
pure stanza

View File

@ -2030,6 +2030,20 @@ authLogin =
_ -> Left (showPatternHelp authLogin)
)
printVersion :: InputPattern
printVersion =
InputPattern
"version"
[]
I.Visible
[]
( P.wrap "Print the version of unison you're running"
)
( \case
[] -> Right $ Input.VersionI
_ -> Left (showPatternHelp printVersion)
)
validInputs :: [InputPattern]
validInputs =
sortOn
@ -2119,7 +2133,8 @@ validInputs =
debugDumpNamespaceSimple,
debugClearWatchCache,
gist,
authLogin
authLogin,
printVersion
]
visibleInputs :: [InputPattern]

View File

@ -1579,6 +1579,7 @@ notifyUser dir o = case o of
[ "Failed to parse a URI from the hostname: " <> P.text host <> ".",
"Host names should NOT include a schema or path."
]
PrintVersion ucmVersion -> pure (P.text ucmVersion)
where
_nameChange _cmd _pastTenseCmd _oldName _newName _r = error "todo"

View File

@ -95,6 +95,7 @@ library
build-depends:
ListLike
, aeson
, aeson-pretty
, async
, base
, bytes
@ -192,6 +193,7 @@ executable cli-integration-tests
build-depends:
ListLike
, aeson
, aeson-pretty
, async
, base
, bytes
@ -287,6 +289,7 @@ executable transcripts
build-depends:
ListLike
, aeson
, aeson-pretty
, async
, base
, bytes
@ -386,6 +389,7 @@ executable unison
build-depends:
ListLike
, aeson
, aeson-pretty
, async
, base
, bytes
@ -490,6 +494,7 @@ test-suite cli-tests
build-depends:
ListLike
, aeson
, aeson-pretty
, async
, base
, bytes

View File

@ -248,13 +248,22 @@ data CodebaseServerOpts = CodebaseServerOpts
}
deriving (Show, Eq)
defaultCodebaseServerOpts :: CodebaseServerOpts
defaultCodebaseServerOpts =
CodebaseServerOpts
{ token = Nothing,
host = Nothing,
port = Nothing,
codebaseUIPath = Nothing
}
-- The auth token required for accessing the server is passed to the function k
startServer ::
CodebaseServerOpts ->
Rt.Runtime Symbol ->
Codebase IO Symbol Ann ->
(BaseUrl -> IO ()) ->
IO ()
(BaseUrl -> IO a) ->
IO a
startServer opts rt codebase onStart = do
-- the `canonicalizePath` resolves symlinks
exePath <- canonicalizePath =<< getExecutablePath

View File

@ -0,0 +1,26 @@
# find api
```unison
rachel.filesystem.x = 42
ross.httpClient.y = 43
joey.httpServer.z = 44
joey.yaml.zz = 45
```
```ucm
.> add
```
```api
-- Namespace segment prefix search
GET /api/find?query=http
-- Namespace segment suffix search
GET /api/find?query=Server
-- Substring search
GET /api/find?query=lesys
-- Cross-segment search
GET /api/find?query=joey.http
```

View File

@ -0,0 +1,253 @@
# find api
```unison
rachel.filesystem.x = 42
ross.httpClient.y = 43
joey.httpServer.z = 44
joey.yaml.zz = 45
```
```ucm
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
joey.httpServer.z : ##Nat
joey.yaml.zz : ##Nat
rachel.filesystem.x : ##Nat
ross.httpClient.y : ##Nat
```
```ucm
.> add
⍟ I've added these definitions:
joey.httpServer.z : ##Nat
joey.yaml.zz : ##Nat
rachel.filesystem.x : ##Nat
ross.httpClient.y : ##Nat
```
```api
-- Namespace segment prefix search
GET /api/find?query=http
[
[
{
"result": {
"segments": [
{
"contents": "ross.",
"tag": "Gap"
},
{
"contents": "http",
"tag": "Match"
},
{
"contents": "Client.y",
"tag": "Gap"
}
]
},
"score": 156
},
{
"contents": {
"bestFoundTermName": "y",
"namedTerm": {
"termHash": "#emomp74i93h6ps0b5sukke0tci0ooba3f9jk21qm919a7act9u7asani84c0mqbdk4lcjrdvr9olpedp23p6df78r4trqlg0cciadc8",
"termName": "ross.httpClient.y",
"termTag": null,
"termType": [
{
"annotation": {
"contents": "##Nat",
"tag": "HashQualifier"
},
"segment": "##Nat"
}
]
}
},
"tag": "FoundTermResult"
}
],
[
{
"result": {
"segments": [
{
"contents": "joey.",
"tag": "Gap"
},
{
"contents": "http",
"tag": "Match"
},
{
"contents": "Server.z",
"tag": "Gap"
}
]
},
"score": 156
},
{
"contents": {
"bestFoundTermName": "z",
"namedTerm": {
"termHash": "#a84tg4er4kfl9k2p250vp2o1dsp5kmn9a7q8g2bo723qbtbf9sagrl28fa4q0j5f2cv4alsjik6rf487ss646qt95gbm3dd13k7e1fo",
"termName": "joey.httpServer.z",
"termTag": null,
"termType": [
{
"annotation": {
"contents": "##Nat",
"tag": "HashQualifier"
},
"segment": "##Nat"
}
]
}
},
"tag": "FoundTermResult"
}
]
]
-- Namespace segment suffix search
GET /api/find?query=Server
[
[
{
"result": {
"segments": [
{
"contents": "joey.http",
"tag": "Gap"
},
{
"contents": "Server",
"tag": "Match"
},
{
"contents": ".z",
"tag": "Gap"
}
]
},
"score": 223
},
{
"contents": {
"bestFoundTermName": "z",
"namedTerm": {
"termHash": "#a84tg4er4kfl9k2p250vp2o1dsp5kmn9a7q8g2bo723qbtbf9sagrl28fa4q0j5f2cv4alsjik6rf487ss646qt95gbm3dd13k7e1fo",
"termName": "joey.httpServer.z",
"termTag": null,
"termType": [
{
"annotation": {
"contents": "##Nat",
"tag": "HashQualifier"
},
"segment": "##Nat"
}
]
}
},
"tag": "FoundTermResult"
}
]
]
-- Substring search
GET /api/find?query=lesys
[
[
{
"result": {
"segments": [
{
"contents": "rachel.fi",
"tag": "Gap"
},
{
"contents": "lesys",
"tag": "Match"
},
{
"contents": "tem.x",
"tag": "Gap"
}
]
},
"score": 175
},
{
"contents": {
"bestFoundTermName": "x",
"namedTerm": {
"termHash": "#qkhkl0n238s1eqibd1ecb8605sqj1m4hpoaag177cu572otqlaf1u28c8suuuqgljdtthsjtr07rv04np05o6oa27ml9105k7uas0t8",
"termName": "rachel.filesystem.x",
"termTag": null,
"termType": [
{
"annotation": {
"contents": "##Nat",
"tag": "HashQualifier"
},
"segment": "##Nat"
}
]
}
},
"tag": "FoundTermResult"
}
]
]
-- Cross-segment search
GET /api/find?query=joey.http
[
[
{
"result": {
"segments": [
{
"contents": "joey.http",
"tag": "Match"
},
{
"contents": "Server.z",
"tag": "Gap"
}
]
},
"score": 300
},
{
"contents": {
"bestFoundTermName": "z",
"namedTerm": {
"termHash": "#a84tg4er4kfl9k2p250vp2o1dsp5kmn9a7q8g2bo723qbtbf9sagrl28fa4q0j5f2cv4alsjik6rf487ss646qt95gbm3dd13k7e1fo",
"termName": "joey.httpServer.z",
"termTag": null,
"termType": [
{
"annotation": {
"contents": "##Nat",
"tag": "HashQualifier"
},
"segment": "##Nat"
}
]
}
},
"tag": "FoundTermResult"
}
]
]
```

View File

@ -0,0 +1,22 @@
# Get Definitions Test
```ucm:hide
.> builtins.mergeio
```
```unison
{{ Documentation }}
nested.names.x = 42
```
```ucm
.> add
```
```api
-- Should find names by suffix
GET /api/getDefinition?names=x
-- Term names should strip relativeTo prefix.
GET /api/getDefinition?names=x&relativeTo=nested
```

View File

@ -0,0 +1,220 @@
# Get Definitions Test
```unison
{{ Documentation }}
nested.names.x = 42
```
```ucm
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
nested.names.x : Nat
nested.names.x.doc : Doc2
```
```ucm
.> add
⍟ I've added these definitions:
nested.names.x : Nat
nested.names.x.doc : Doc2
```
```api
-- Should find names by suffix
GET /api/getDefinition?names=x
{
"missingDefinitions": [],
"termDefinitions": {
"#qkhkl0n238s1eqibd1ecb8605sqj1m4hpoaag177cu572otqlaf1u28c8suuuqgljdtthsjtr07rv04np05o6oa27ml9105k7uas0t8": {
"bestTermName": "x",
"defnTermTag": null,
"signature": [
{
"annotation": {
"contents": "##Nat",
"tag": "TypeReference"
},
"segment": "Nat"
}
],
"termDefinition": {
"contents": [
{
"annotation": {
"contents": "x",
"tag": "HashQualifier"
},
"segment": "x"
},
{
"annotation": {
"tag": "TypeAscriptionColon"
},
"segment": " :"
},
{
"annotation": null,
"segment": " "
},
{
"annotation": {
"contents": "##Nat",
"tag": "TypeReference"
},
"segment": "Nat"
},
{
"annotation": null,
"segment": "\n"
},
{
"annotation": {
"contents": "x",
"tag": "HashQualifier"
},
"segment": "x"
},
{
"annotation": {
"tag": "BindingEquals"
},
"segment": " ="
},
{
"annotation": null,
"segment": " "
},
{
"annotation": {
"tag": "NumericLiteral"
},
"segment": "42"
}
],
"tag": "UserObject"
},
"termDocs": [
[
"doc",
"#ulr9f75rpcrv79d7sfo2ep2tvbntu3e360lfomird2bdpj4bnea230e8o5j0b9our8vggocpa7eck3pus14fcfajlttat1bg71t6rbg",
{
"contents": [
{
"contents": "Documentation",
"tag": "Word"
}
],
"tag": "Paragraph"
}
]
],
"termNames": [
"nested.names.x"
]
}
},
"typeDefinitions": {}
}
-- Term names should strip relativeTo prefix.
GET /api/getDefinition?names=x&relativeTo=nested
{
"missingDefinitions": [],
"termDefinitions": {
"#qkhkl0n238s1eqibd1ecb8605sqj1m4hpoaag177cu572otqlaf1u28c8suuuqgljdtthsjtr07rv04np05o6oa27ml9105k7uas0t8": {
"bestTermName": "x",
"defnTermTag": null,
"signature": [
{
"annotation": {
"contents": "##Nat",
"tag": "TypeReference"
},
"segment": "Nat"
}
],
"termDefinition": {
"contents": [
{
"annotation": {
"contents": "x",
"tag": "HashQualifier"
},
"segment": "x"
},
{
"annotation": {
"tag": "TypeAscriptionColon"
},
"segment": " :"
},
{
"annotation": null,
"segment": " "
},
{
"annotation": {
"contents": "##Nat",
"tag": "TypeReference"
},
"segment": "Nat"
},
{
"annotation": null,
"segment": "\n"
},
{
"annotation": {
"contents": "x",
"tag": "HashQualifier"
},
"segment": "x"
},
{
"annotation": {
"tag": "BindingEquals"
},
"segment": " ="
},
{
"annotation": null,
"segment": " "
},
{
"annotation": {
"tag": "NumericLiteral"
},
"segment": "42"
}
],
"tag": "UserObject"
},
"termDocs": [
[
"doc",
"#ulr9f75rpcrv79d7sfo2ep2tvbntu3e360lfomird2bdpj4bnea230e8o5j0b9our8vggocpa7eck3pus14fcfajlttat1bg71t6rbg",
{
"contents": [
{
"contents": "Documentation",
"tag": "Word"
}
],
"tag": "Paragraph"
}
]
],
"termNames": [
"names.x"
]
}
},
"typeDefinitions": {}
}
```

View File

@ -0,0 +1,20 @@
# Namespace details api
```ucm:hide
.> builtins.mergeio
```
```unison
{{ Documentation }}
nested.names.x = 42
nested.names.readme = {{ I'm a readme! }}
```
```ucm
.> add
```
```api
GET /api/namespaces/nested.names
```

View File

@ -0,0 +1,56 @@
# Namespace details api
```unison
{{ Documentation }}
nested.names.x = 42
nested.names.readme = {{ I'm a readme! }}
```
```ucm
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
nested.names.readme : Doc2
nested.names.x : Nat
nested.names.x.doc : Doc2
```
```ucm
.> add
⍟ I've added these definitions:
nested.names.readme : Doc2
nested.names.x : Nat
nested.names.x.doc : Doc2
```
```api
GET /api/namespaces/nested.names
{
"fqn": "nested.names",
"hash": "#oms19b4f9s3c8tb5skeb8jii95ij35n3hdg038pu6rv5b0fikqe4gd7lnu6a1i6aq5tdh2opdo4s0sfrupvk6vfkr9lf0n752gbl8o0",
"readme": {
"contents": [
{
"contents": "I'm",
"tag": "Word"
},
{
"contents": "a",
"tag": "Word"
},
{
"contents": "readme!",
"tag": "Word"
}
],
"tag": "Paragraph"
}
}
```

View File

@ -0,0 +1,22 @@
# Namespace list api
```ucm:hide
.> builtins.mergeio
```
```unison
{{ Documentation }}
nested.names.x = 42
nested.names.readme = {{ I'm a readme! }}
```
```ucm
.> add
```
```api
GET /api/list?namespace=nested.names
GET /api/list?namespace=names&relativeTo=nested
```

View File

@ -0,0 +1,130 @@
# Namespace list api
```unison
{{ Documentation }}
nested.names.x = 42
nested.names.readme = {{ I'm a readme! }}
```
```ucm
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
nested.names.readme : Doc2
nested.names.x : Nat
nested.names.x.doc : Doc2
```
```ucm
.> add
⍟ I've added these definitions:
nested.names.readme : Doc2
nested.names.x : Nat
nested.names.x.doc : Doc2
```
```api
GET /api/list?namespace=nested.names
{
"namespaceListingChildren": [
{
"contents": {
"termHash": "#ddmmatmmiqsts2ku0i02kntd0s7rvcui4nn1cusio8thp9oqhbtilvcnhen52ibv43kr5q83f5er5q9h56s807k17tnelnrac7cch8o",
"termName": "readme",
"termTag": "Doc",
"termType": [
{
"annotation": {
"contents": "#ej86si0ur1",
"tag": "HashQualifier"
},
"segment": "#ej86si0ur1"
}
]
},
"tag": "TermObject"
},
{
"contents": {
"termHash": "#qkhkl0n238s1eqibd1ecb8605sqj1m4hpoaag177cu572otqlaf1u28c8suuuqgljdtthsjtr07rv04np05o6oa27ml9105k7uas0t8",
"termName": "x",
"termTag": null,
"termType": [
{
"annotation": {
"contents": "##Nat",
"tag": "HashQualifier"
},
"segment": "##Nat"
}
]
},
"tag": "TermObject"
},
{
"contents": {
"namespaceHash": "#n1egracfeljprftoktbjcase2hs4f4p8idbhs5ujipl42agld1810hrq9t7p7ped16aagni2cm1fjcjhho770jh80ipthhmg0cnsur0",
"namespaceName": "x"
},
"tag": "Subnamespace"
}
],
"namespaceListingFQN": "nested.names",
"namespaceListingHash": "#oms19b4f9s3c8tb5skeb8jii95ij35n3hdg038pu6rv5b0fikqe4gd7lnu6a1i6aq5tdh2opdo4s0sfrupvk6vfkr9lf0n752gbl8o0"
}
GET /api/list?namespace=names&relativeTo=nested
{
"namespaceListingChildren": [
{
"contents": {
"termHash": "#ddmmatmmiqsts2ku0i02kntd0s7rvcui4nn1cusio8thp9oqhbtilvcnhen52ibv43kr5q83f5er5q9h56s807k17tnelnrac7cch8o",
"termName": "readme",
"termTag": "Doc",
"termType": [
{
"annotation": {
"contents": "#ej86si0ur1",
"tag": "HashQualifier"
},
"segment": "#ej86si0ur1"
}
]
},
"tag": "TermObject"
},
{
"contents": {
"termHash": "#qkhkl0n238s1eqibd1ecb8605sqj1m4hpoaag177cu572otqlaf1u28c8suuuqgljdtthsjtr07rv04np05o6oa27ml9105k7uas0t8",
"termName": "x",
"termTag": null,
"termType": [
{
"annotation": {
"contents": "##Nat",
"tag": "HashQualifier"
},
"segment": "##Nat"
}
]
},
"tag": "TermObject"
},
{
"contents": {
"namespaceHash": "#n1egracfeljprftoktbjcase2hs4f4p8idbhs5ujipl42agld1810hrq9t7p7ped16aagni2cm1fjcjhho770jh80ipthhmg0cnsur0",
"namespaceName": "x"
},
"tag": "Subnamespace"
}
],
"namespaceListingFQN": "nested.names",
"namespaceListingHash": "#oms19b4f9s3c8tb5skeb8jii95ij35n3hdg038pu6rv5b0fikqe4gd7lnu6a1i6aq5tdh2opdo4s0sfrupvk6vfkr9lf0n752gbl8o0"
}
```

View File

@ -0,0 +1,18 @@
# projects api
```unison
rachel.filesystem.x = 42
ross.http.y = 43
joey.json.z = 44
joey.yaml.zz = 45
```
```ucm
.> add
```
```api
GET /api/projects
GET /api/projects?owner=joey
```

View File

@ -0,0 +1,72 @@
# projects api
```unison
rachel.filesystem.x = 42
ross.http.y = 43
joey.json.z = 44
joey.yaml.zz = 45
```
```ucm
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
joey.json.z : ##Nat
joey.yaml.zz : ##Nat
rachel.filesystem.x : ##Nat
ross.http.y : ##Nat
```
```ucm
.> add
⍟ I've added these definitions:
joey.json.z : ##Nat
joey.yaml.zz : ##Nat
rachel.filesystem.x : ##Nat
ross.http.y : ##Nat
```
```api
GET /api/projects
[
{
"hash": "#vjmnhfbas8pejgpgsh26255ebaolepuc56juiifft4b9bg8u43nmmhe2skfncrfvin3std4grbfa7io846nskq3j5b3819rvaddnbn0",
"name": "json",
"owner": "joey"
},
{
"hash": "#plgokdvco3iu26r56u20faojs7pv0r0114pkd5aumt7ucd567t307bcuv92ejtkcvvmp0tg4e2g5d3btqbggn54pifbvql2kd9hlg48",
"name": "yaml",
"owner": "joey"
},
{
"hash": "#sbh98idno2b9ide5ue7bcj01ftu7u9msm57g3jn7q9efsbo0bdtnaei5i8sq4p3gb6p8alkqrp8gttp4ptvq9f45c8stkf39l9pvb2g",
"name": "filesystem",
"owner": "rachel"
},
{
"hash": "#1l4rfnjpsut79lc0kcv7aa4m6elk1lj7nse69ptaipb4gvlfa7kcnqrte56opeeb5ahrr6tvms2052e9fjjjuh97glkll6hp3lam788",
"name": "http",
"owner": "ross"
}
]
GET /api/projects?owner=joey
[
{
"hash": "#vjmnhfbas8pejgpgsh26255ebaolepuc56juiifft4b9bg8u43nmmhe2skfncrfvin3std4grbfa7io846nskq3j5b3819rvaddnbn0",
"name": "json",
"owner": "joey"
},
{
"hash": "#plgokdvco3iu26r56u20faojs7pv0r0114pkd5aumt7ucd567t307bcuv92ejtkcvvmp0tg4e2g5d3btqbggn54pifbvql2kd9hlg48",
"name": "yaml",
"owner": "joey"
}
]
```