Skip to content

Commit cece289

Browse files
authored
Merge pull request #5479 from unisonweb/24-12-04-update-output
2 parents 67575ee + fcfee18 commit cece289

File tree

3 files changed

+57
-61
lines changed

3 files changed

+57
-61
lines changed

unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -106,70 +106,75 @@ handleUpdate2 = do
106106
Merge.checkDeclCoherency nametree numConstructors
107107
& onLeft (Cli.returnEarly . Output.IncoherentDeclDuringUpdate)
108108

109-
Cli.respond Output.UpdateLookingForDependents
109+
finalOutput <-
110+
Cli.label \done ->
111+
Cli.withRespondRegion \respondRegion -> do
112+
respondRegion $
113+
Output.Literal (Pretty.wrap "Okay, I'm searching the branch for code that needs to be updated...")
110114

111-
(dependents, hydratedDependents) <-
112-
Cli.runTransaction do
113-
-- Get all dependents of things being updated
114-
dependents0 <-
115-
getNamespaceDependentsOf2
116-
(flattenNametrees nametree)
117-
(getExistingReferencesNamed termAndDeclNames (Branch.toNames currentBranch0ExcludingLibdeps))
115+
(dependents, hydratedDependents) <-
116+
Cli.runTransaction do
117+
-- Get all dependents of things being updated
118+
dependents0 <-
119+
getNamespaceDependentsOf2
120+
(flattenNametrees nametree)
121+
(getExistingReferencesNamed termAndDeclNames (Branch.toNames currentBranch0ExcludingLibdeps))
118122

119-
-- Throw away the dependents that are shadowed by the file itself
120-
let dependents1 :: DefnsF (Map Name) TermReferenceId TypeReferenceId
121-
dependents1 =
122-
bimap
123-
(`Map.withoutKeys` (Set.map Name.unsafeParseVar (UF.termNamespaceBindings tuf)))
124-
(`Map.withoutKeys` (Set.map Name.unsafeParseVar (UF.typeNamespaceBindings tuf)))
125-
dependents0
123+
-- Throw away the dependents that are shadowed by the file itself
124+
let dependents1 :: DefnsF (Map Name) TermReferenceId TypeReferenceId
125+
dependents1 =
126+
bimap
127+
(`Map.withoutKeys` (Set.map Name.unsafeParseVar (UF.termNamespaceBindings tuf)))
128+
(`Map.withoutKeys` (Set.map Name.unsafeParseVar (UF.typeNamespaceBindings tuf)))
129+
dependents0
126130

127-
-- Hydrate the dependents for rendering
128-
hydratedDependents <-
129-
hydrateDefns
130-
(Codebase.unsafeGetTermComponent env.codebase)
131-
Operations.expectDeclComponent
132-
dependents1
131+
-- Hydrate the dependents for rendering
132+
hydratedDependents <-
133+
hydrateDefns
134+
(Codebase.unsafeGetTermComponent env.codebase)
135+
Operations.expectDeclComponent
136+
dependents1
133137

134-
pure (dependents1, hydratedDependents)
138+
pure (dependents1, hydratedDependents)
135139

136-
secondTuf <- do
137-
case defnsAreEmpty dependents of
138-
-- If there are no dependents of the updates, then just use the already-typechecked file.
139-
True -> pure tuf
140-
False -> do
141-
Cli.respond Output.UpdateStartTypechecking
140+
secondTuf <- do
141+
case defnsAreEmpty dependents of
142+
-- If there are no dependents of the updates, then just use the already-typechecked file.
143+
True -> pure tuf
144+
False -> do
145+
respondRegion (Output.Literal (Pretty.wrap "That's done. Now I'm making sure everything typechecks..."))
142146

143-
let prettyUnisonFile =
144-
let ppe = makePPE 10 namesIncludingLibdeps (UF.typecheckedToNames tuf) dependents
145-
in makePrettyUnisonFile
146-
(Pretty.prettyUnisonFile ppe (UF.discardTypes tuf))
147-
(renderDefnsForUnisonFile declNameLookup ppe (over (#terms . mapped) snd hydratedDependents))
147+
let prettyUnisonFile =
148+
let ppe = makePPE 10 namesIncludingLibdeps (UF.typecheckedToNames tuf) dependents
149+
in makePrettyUnisonFile
150+
(Pretty.prettyUnisonFile ppe (UF.discardTypes tuf))
151+
(renderDefnsForUnisonFile declNameLookup ppe (over (#terms . mapped) snd hydratedDependents))
148152

149-
parsingEnv <- Cli.makeParsingEnv pp namesIncludingLibdeps
153+
parsingEnv <- Cli.makeParsingEnv pp namesIncludingLibdeps
150154

151-
secondTuf <-
152-
parseAndTypecheck prettyUnisonFile parsingEnv & onNothingM do
153-
scratchFilePath <- fst <$> Cli.expectLatestFile
154-
liftIO $ env.writeSource (Text.pack scratchFilePath) (Text.pack $ Pretty.toPlain 80 prettyUnisonFile) True
155-
Cli.returnEarly Output.UpdateTypecheckingFailure
155+
secondTuf <-
156+
parseAndTypecheck prettyUnisonFile parsingEnv & onNothingM do
157+
scratchFilePath <- fst <$> Cli.expectLatestFile
158+
liftIO $ env.writeSource (Text.pack scratchFilePath) (Text.pack $ Pretty.toPlain 80 prettyUnisonFile) True
159+
done Output.UpdateTypecheckingFailure
156160

157-
Cli.respond Output.UpdateTypecheckingSuccess
161+
respondRegion (Output.Literal (Pretty.wrap "Everything typechecks, so I'm saving the results..."))
158162

159-
pure secondTuf
163+
pure secondTuf
160164

161-
path <- Cli.getCurrentProjectPath
162-
branchUpdates <-
163-
Cli.runTransactionWithRollback \abort -> do
164-
Codebase.addDefsToCodebase env.codebase secondTuf
165-
typecheckedUnisonFileToBranchUpdates
166-
abort
167-
(\typeName -> Right (Map.lookup typeName declNameLookup.declToConstructors))
168-
secondTuf
169-
Cli.stepAt "update" (path, Branch.batchUpdates branchUpdates)
170-
#latestTypecheckedFile .= Nothing
165+
path <- Cli.getCurrentProjectPath
166+
branchUpdates <-
167+
Cli.runTransactionWithRollback \abort -> do
168+
Codebase.addDefsToCodebase env.codebase secondTuf
169+
typecheckedUnisonFileToBranchUpdates
170+
abort
171+
(\typeName -> Right (Map.lookup typeName declNameLookup.declToConstructors))
172+
secondTuf
173+
Cli.stepAt "update" (path, Branch.batchUpdates branchUpdates)
174+
#latestTypecheckedFile .= Nothing
175+
pure Output.Success
171176

172-
Cli.respond Output.Success
177+
Cli.respond finalOutput
173178

174179
makePrettyUnisonFile :: Pretty ColorText -> DefnsF (Map Name) (Pretty ColorText) (Pretty ColorText) -> Pretty ColorText
175180
makePrettyUnisonFile originalFile dependents =

unison-cli/src/Unison/Codebase/Editor/Output.hs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,7 @@ data Output
417417
| FailedToFetchLatestReleaseOfBase
418418
| HappyCoding
419419
| ProjectHasNoReleases ProjectName
420-
| UpdateLookingForDependents
421-
| UpdateStartTypechecking
422420
| UpdateTypecheckingFailure
423-
| UpdateTypecheckingSuccess
424421
| UpdateIncompleteConstructorSet UpdateOrUpgrade Name (Map ConstructorId Name) (Maybe Int)
425422
| UpgradeFailure !ProjectBranchName !ProjectBranchName !FilePath !NameSegment !NameSegment
426423
| UpgradeSuccess !NameSegment !NameSegment
@@ -499,10 +496,7 @@ type SourceFileContents = Text
499496

500497
isFailure :: Output -> Bool
501498
isFailure o = case o of
502-
UpdateLookingForDependents -> False
503-
UpdateStartTypechecking -> False
504499
UpdateTypecheckingFailure {} -> True
505-
UpdateTypecheckingSuccess {} -> False
506500
UpdateIncompleteConstructorSet {} -> True
507501
AmbiguousCloneLocal {} -> True
508502
AmbiguousCloneRemote {} -> True

unison-cli/src/Unison/CommandLine/OutputMessages.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,6 @@ notifyUser dir = \case
19361936
<> P.wrap "🎉 🥳 Happy coding!"
19371937
ProjectHasNoReleases projectName ->
19381938
pure . P.wrap $ prettyProjectName projectName <> "has no releases."
1939-
UpdateLookingForDependents -> pure . P.wrap $ "Okay, I'm searching the branch for code that needs to be updated..."
1940-
UpdateStartTypechecking -> pure . P.wrap $ "That's done. Now I'm making sure everything typechecks..."
1941-
UpdateTypecheckingSuccess -> pure . P.wrap $ "Everything typechecks, so I'm saving the results..."
19421939
UpdateTypecheckingFailure ->
19431940
pure . P.wrap $
19441941
"Typechecking failed. I've updated your scratch file with the definitions that need fixing."

0 commit comments

Comments
 (0)