Skip to content

Commit 0adc6f3

Browse files
committed
Fix up commit.preview and accidentally ignoring top-level terms
1 parent bd7802b commit 0adc6f3

File tree

8 files changed

+188
-140
lines changed

8 files changed

+188
-140
lines changed

parser-typechecker/src/Unison/Codebase/Branch.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ withoutTransitiveLibs b0 =
187187

188188
onlyLib :: Branch0 m -> Branch0 m
189189
onlyLib b =
190-
b
191-
& children %~ \c ->
192-
(Map.singleton NameSegment.libSegment (fromMaybe empty $ Map.lookup NameSegment.libSegment c))
190+
let newChildren = (Map.singleton NameSegment.libSegment (fromMaybe empty $ Map.lookup NameSegment.libSegment (b ^. children)))
191+
in branch0 mempty mempty newChildren mempty
193192

194193
-- | @deleteLibdep name branch@ deletes the libdep named @name@ from @branch@, if it exists.
195194
deleteLibdep :: NameSegment -> Branch0 m -> Branch0 m

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ loop loadMode e = do
710710
FindI isVerbose fscope ws -> handleFindI isVerbose fscope ws input
711711
StructuredFindI _fscope ws -> handleStructuredFindI ws
712712
StructuredFindReplaceI ws -> handleStructuredFindReplaceI ws
713-
LoadI maybePath -> void $ handleLoad False loadMode maybePath
713+
LoadI maybePath -> void $ handleLoad True loadMode maybePath
714714
ClearI -> Cli.respond ClearScreen
715715
AddI requestedNames -> do
716716
description <- inputDescription input

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ data LoadMode
5858
deriving (Show, Eq, Ord)
5959

6060
handleLoad :: Bool -> LoadMode -> Maybe FilePath -> Cli (TypecheckedUnisonFile Symbol Ann)
61-
handleLoad silent loadMode maybePath = do
61+
handleLoad showWatchExprs loadMode maybePath = do
6262
latestFile <- Cli.getLatestFile
6363
path <- (maybePath <|> fst <$> latestFile) & onNothing (Cli.returnEarly Output.NoUnisonFile)
6464
Cli.Env {loadSource} <- ask
@@ -69,7 +69,7 @@ handleLoad silent loadMode maybePath = do
6969
Cli.LoadSuccess contents -> pure contents
7070
case loadMode of
7171
Normal -> loadUnisonFile (Text.pack path) contents
72-
LoadForCommit -> loadUnisonFileForCommit silent (Text.pack path) contents
72+
LoadForCommit -> loadUnisonFileForCommit showWatchExprs (Text.pack path) contents
7373

7474
loadUnisonFile :: Text -> Text -> Cli (TypecheckedUnisonFile Symbol Ann)
7575
loadUnisonFile sourceName text = do
@@ -90,8 +90,8 @@ loadUnisonFile sourceName text = do
9090
pure unisonFile
9191

9292
loadUnisonFileForCommit :: Bool -> Text -> Text -> Cli (TypecheckedUnisonFile Symbol Ann)
93-
loadUnisonFileForCommit silent sourceName text = do
94-
when (not silent) . Cli.respond $ Output.LoadingFile sourceName
93+
loadUnisonFileForCommit showWatchExprs sourceName text = do
94+
Cli.respond $ Output.LoadingFile sourceName
9595
beforeBranch0 <- Cli.getCurrentBranch0
9696
let beforeBranch0LibOnly = Branch.onlyLib beforeBranch0
9797
beforePPED <- Cli.currentPrettyPrintEnvDecl
@@ -100,13 +100,13 @@ loadUnisonFileForCommit silent sourceName text = do
100100
let sr = Slurp.slurpFile unisonFile mempty Slurp.CheckOp libNames
101101
let adds = SlurpResult.adds sr
102102
let afterBranch0 = Update.doSlurpAdds adds unisonFile beforeBranch0LibOnly
103-
afterPPED <- Cli.currentPrettyPrintEnvDecl
103+
afterPPED <- Cli.prettyPrintEnvDeclFromNames (Branch.toNames afterBranch0)
104104
(_ppe, diff) <- diffFromTypecheckedUnisonFile unisonFile beforeBranch0 afterBranch0
105105
let pped = afterPPED `PPED.addFallback` beforePPED
106106
let ppe = PPE.suffixifiedPPE pped
107107
currentPath <- Cli.getCurrentPath
108108
Cli.respondNumbered $ Output.ShowDiffNamespace (Right currentPath) (Right currentPath) ppe diff
109-
when (not silent) do
109+
when showWatchExprs do
110110
(bindings, e) <- evalUnisonFile Permissive ppe unisonFile []
111111
let e' = Map.map go e
112112
go (ann, kind, _hash, _uneval, eval, isHit) = (ann, kind, eval, isHit)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Unison.Type (Type)
3232
import Unison.Typechecker.TypeLookup qualified as TL
3333
import Unison.UnisonFile (TypecheckedUnisonFile)
3434
import Unison.UnisonFile qualified as UF
35+
import Unison.UnisonFile.Names qualified as Names
3536

3637
diffHelper ::
3738
Branch0 IO ->
@@ -69,13 +70,15 @@ diffFromTypecheckedUnisonFile tf before after = do
6970
names <- Cli.currentNames
7071
pped <- Cli.prettyPrintEnvDeclFromNames names
7172
let suffixifiedPPE = PPED.suffixifiedPPE pped
73+
let beforeNames = Branch.toNames before
74+
let afterNames = Names.addNamesFromTypeCheckedUnisonFile tf (Branch.toNames after)
7275
fmap (suffixifiedPPE,) do
7376
OBranchDiff.toOutput
7477
(getTypeOfReferent codebase)
7578
(getDeclOrBuiltin codebase)
7679
hqLength
77-
(Branch.toNames before)
78-
(Branch.toNames after)
80+
beforeNames
81+
afterNames
7982
diff
8083
where
8184
TL.TypeLookup {dataDecls, effectDecls} = UF.typeLookupForTypecheckedFile tf

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import Unison.Cli.MergeTypes (MergeSourceAndTarget, MergeSourceOrTarget)
3131
import Unison.Cli.Share.Projects.Types qualified as Share
3232
import Unison.Codebase.Editor.Input
3333
import Unison.Codebase.Editor.Output.BranchDiff (BranchDiffOutput)
34-
import Unison.Codebase.Editor.Output.BranchDiff qualified as BD
3534
import Unison.Codebase.Editor.Output.PushPull (PushPull)
3635
import Unison.Codebase.Editor.RemoteRepo
3736
import Unison.Codebase.Editor.SlurpResult (SlurpResult (..))
@@ -661,6 +660,6 @@ isNumberedFailure = \case
661660
ShowDiffAfterModifyBranch {} -> False
662661
ShowDiffAfterPull {} -> False
663662
ShowDiffAfterUndo {} -> False
664-
ShowDiffNamespace _ _ _ bd -> BD.isEmpty bd
663+
ShowDiffNamespace _ _ _ _ -> False
665664
ListNamespaceDependencies {} -> False
666665
TodoOutput _ todo -> TO.todoScore todo > 0 || not (TO.noConflicts todo)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ commit =
815815
)
816816
\case
817817
[] -> pure $ Input.CommitI Nothing
818-
[file] -> Input.LoadI . Just <$> unsupportedStructuredArgument "a file name" file
818+
[file] -> Input.CommitI . Just <$> unsupportedStructuredArgument "a file name" file
819819
_ -> Left (I.help load)
820820

821821
commitPreview :: InputPattern
@@ -828,8 +828,8 @@ commitPreview =
828828
( "`experimental.commit.preview` shows the diff which would be applied if you were to run " <> patternName commit
829829
)
830830
\case
831-
[] -> pure $ Input.CommitI Nothing
832-
[file] -> Input.LoadI . Just <$> unsupportedStructuredArgument "a file name" file
831+
[] -> pure $ Input.CommitPreviewI Nothing
832+
[file] -> Input.CommitPreviewI . Just <$> unsupportedStructuredArgument "a file name" file
833833
_ -> Left (I.help load)
834834

835835
update :: InputPattern
@@ -3190,6 +3190,7 @@ validInputs =
31903190
clone,
31913191
compileScheme,
31923192
commit,
3193+
commitPreview,
31933194
createAuthor,
31943195
debugClearWatchCache,
31953196
debugDoctor,

unison-src/transcripts/commit-command.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
```ucm:hide
2-
.> builtins.merge
2+
.> builtins.merge lib
33
```
44

55
Add some definitions to the codebase for us to later update.
66

7-
```unison
7+
```unison:hide
88
type MyRecord =
99
{ nat : Nat
1010
, text : Text
@@ -21,7 +21,7 @@ addToRecordField rec = nat rec + 10
2121
> addToRecordField (MyRecord 9 "hi" true)
2222
```
2323

24-
```ucm
24+
```ucm:hide
2525
.> add
2626
```
2727

0 commit comments

Comments
 (0)