mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-19 06:17:33 +03:00
Transcripts now output changes to the scratchfile
This commit is contained in:
parent
407629aa5d
commit
19f58795f5
@ -1723,7 +1723,8 @@ handleShowDefinition outputLoc showDefinitionScope query = do
|
||||
-- next update for that file (which will happen immediately)
|
||||
#latestFile ?= (fp, True)
|
||||
liftIO $ writeSource (Text.pack fp) renderedCodeText
|
||||
Cli.respond $ LoadedDefinitionsToSourceFile fp renderedCodePretty
|
||||
let numDefinitions = Map.size terms + Map.size types
|
||||
Cli.respond $ LoadedDefinitionsToSourceFile fp numDefinitions
|
||||
when (not (null misses)) (Cli.respond (SearchTermsNotFound misses))
|
||||
where
|
||||
renderCodePretty pped isSourceFile isTest terms types =
|
||||
|
@ -254,7 +254,7 @@ data Output
|
||||
DisplayDefinitions (P.Pretty P.ColorText)
|
||||
| -- Like `DisplayDefinitions`, but the definitions are already rendered. `Nothing` means they were output to the terminal.
|
||||
DisplayDefinitionsString !(Maybe FilePath) !(P.Pretty P.ColorText {- rendered definitions -})
|
||||
| LoadedDefinitionsToSourceFile FilePath (P.Pretty P.ColorText)
|
||||
| LoadedDefinitionsToSourceFile FilePath Int
|
||||
| TestIncrementalOutputStart PPE.PrettyPrintEnv (Int, Int) TermReferenceId
|
||||
| TestIncrementalOutputEnd PPE.PrettyPrintEnv (Int, Int) TermReferenceId Bool {- True if success, False for Failure -}
|
||||
| TestResults
|
||||
|
@ -267,7 +267,9 @@ run verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion
|
||||
Just accessToken ->
|
||||
\_codeserverID -> pure $ Right accessToken
|
||||
seedRef <- newIORef (0 :: Int)
|
||||
inputQueue <- Q.newIO
|
||||
-- Queue of Stanzas and Just index, or Nothing if the stanza was programmatically generated
|
||||
-- e.g. a unison-file update by a command like 'edit'
|
||||
inputQueue <- Q.newIO @(Stanza, Maybe Int)
|
||||
cmdQueue <- Q.newIO
|
||||
unisonFiles <- newIORef Map.empty
|
||||
out <- newIORef mempty
|
||||
@ -275,7 +277,7 @@ run verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion
|
||||
allowErrors <- newIORef False
|
||||
hasErrors <- newIORef False
|
||||
mStanza <- newIORef Nothing
|
||||
traverse_ (atomically . Q.enqueue inputQueue) (stanzas `zip` [1 :: Int ..])
|
||||
traverse_ (atomically . Q.enqueue inputQueue) (stanzas `zip` (Just <$> [1 :: Int ..]))
|
||||
let patternMap =
|
||||
Map.fromList $
|
||||
validInputs
|
||||
@ -395,7 +397,7 @@ run verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion
|
||||
liftIO (output "```ucm\n")
|
||||
atomically . Q.enqueue cmdQueue $ Nothing
|
||||
let sourceName = fromMaybe "scratch.u" filename
|
||||
liftIO $ writeSourceFile sourceName txt
|
||||
liftIO $ writeSourceFile False sourceName txt
|
||||
pure $ Left (UnisonFileChanged sourceName txt)
|
||||
API apiRequests -> do
|
||||
liftIO (output "```api\n")
|
||||
@ -426,8 +428,11 @@ run verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion
|
||||
let f = Cli.LoadSuccess <$> readUtf8 (Text.unpack name)
|
||||
in f <|> pure Cli.InvalidSourceNameError
|
||||
|
||||
writeSourceFile :: ScratchFileName -> Text -> IO ()
|
||||
writeSourceFile fp contents = do
|
||||
writeSourceFile :: Bool -> ScratchFileName -> Text -> IO ()
|
||||
writeSourceFile programmaticUpdate fp contents = do
|
||||
when programmaticUpdate $ do
|
||||
let fenceDescription = "unison:added-by-ucm " <> fp
|
||||
atomically (Q.undequeue inputQueue (UnprocessedFence fenceDescription contents, Nothing))
|
||||
liftIO (modifyIORef' unisonFiles (Map.insert fp contents))
|
||||
|
||||
print :: Output.Output -> IO ()
|
||||
@ -504,7 +509,7 @@ run verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion
|
||||
pure (Parser.uniqueBase32Namegen (Random.drgNewSeed (Random.seedFromInteger (fromIntegral i)))),
|
||||
isTranscript = True, -- we are running a transcript
|
||||
loadSource = loadPreviousUnisonBlock,
|
||||
writeSource = writeSourceFile,
|
||||
writeSource = writeSourceFile True,
|
||||
notify = print,
|
||||
notifyNumbered = printNumbered,
|
||||
runtime,
|
||||
|
@ -760,16 +760,14 @@ notifyUser dir = \case
|
||||
[prettyReadRemoteNamespaceWith absurd baseNS, prettyPath' squashedPath]
|
||||
<> "to push the changes."
|
||||
]
|
||||
LoadedDefinitionsToSourceFile fp code ->
|
||||
LoadedDefinitionsToSourceFile fp numDefinitions ->
|
||||
pure $
|
||||
P.callout "☝️" $
|
||||
P.lines
|
||||
[ P.wrap $ "I added these definitions to the top of " <> fromString fp,
|
||||
"",
|
||||
P.indentN 2 code,
|
||||
[ P.wrap $ "I added " <> P.shown @Int numDefinitions <> " definitions to the top of " <> fromString fp,
|
||||
"",
|
||||
P.wrap $
|
||||
"You can edit them there, then do"
|
||||
"You can edit them there, then run"
|
||||
<> makeExample' IP.update
|
||||
<> "to replace the definitions currently in this namespace."
|
||||
]
|
||||
|
@ -45,29 +45,33 @@ mytest = [Ok "ok"]
|
||||
|
||||
☝️
|
||||
|
||||
I added these definitions to the top of /private/tmp/scratch.u
|
||||
I added 2 definitions to the top of /private/tmp/scratch.u
|
||||
|
||||
bar : Nat
|
||||
bar = 456
|
||||
|
||||
foo : Nat
|
||||
foo = 123
|
||||
|
||||
You can edit them there, then do `update` to replace the
|
||||
You can edit them there, then run `update` to replace the
|
||||
definitions currently in this namespace.
|
||||
|
||||
.> edit mytest
|
||||
|
||||
☝️
|
||||
|
||||
I added these definitions to the top of /private/tmp/scratch.u
|
||||
I added 1 definitions to the top of /private/tmp/scratch.u
|
||||
|
||||
test> mytest = [Ok "ok"]
|
||||
|
||||
You can edit them there, then do `update` to replace the
|
||||
You can edit them there, then run `update` to replace the
|
||||
definitions currently in this namespace.
|
||||
|
||||
```
|
||||
```unison:added-by-ucm /private/tmp/scratch.u
|
||||
test> mytest = [Ok "ok"]
|
||||
```
|
||||
|
||||
```unison:added-by-ucm /private/tmp/scratch.u
|
||||
bar : Nat
|
||||
bar = 456
|
||||
|
||||
foo : Nat
|
||||
foo = 123
|
||||
```
|
||||
|
||||
```ucm
|
||||
.> edit missing
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user