Skip to content

Commit

Permalink
Fix up commit.preview and accidentally ignoring top-level terms
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed May 31, 2024
1 parent bd7802b commit 0adc6f3
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 140 deletions.
5 changes: 2 additions & 3 deletions parser-typechecker/src/Unison/Codebase/Branch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ withoutTransitiveLibs b0 =

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

-- | @deleteLibdep name branch@ deletes the libdep named @name@ from @branch@, if it exists.
deleteLibdep :: NameSegment -> Branch0 m -> Branch0 m
Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/Codebase/Editor/HandleInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ loop loadMode e = do
FindI isVerbose fscope ws -> handleFindI isVerbose fscope ws input
StructuredFindI _fscope ws -> handleStructuredFindI ws
StructuredFindReplaceI ws -> handleStructuredFindReplaceI ws
LoadI maybePath -> void $ handleLoad False loadMode maybePath
LoadI maybePath -> void $ handleLoad True loadMode maybePath
ClearI -> Cli.respond ClearScreen
AddI requestedNames -> do
description <- inputDescription input
Expand Down
12 changes: 6 additions & 6 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput/Load.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data LoadMode
deriving (Show, Eq, Ord)

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

loadUnisonFile :: Text -> Text -> Cli (TypecheckedUnisonFile Symbol Ann)
loadUnisonFile sourceName text = do
Expand All @@ -90,8 +90,8 @@ loadUnisonFile sourceName text = do
pure unisonFile

loadUnisonFileForCommit :: Bool -> Text -> Text -> Cli (TypecheckedUnisonFile Symbol Ann)
loadUnisonFileForCommit silent sourceName text = do
when (not silent) . Cli.respond $ Output.LoadingFile sourceName
loadUnisonFileForCommit showWatchExprs sourceName text = do
Cli.respond $ Output.LoadingFile sourceName
beforeBranch0 <- Cli.getCurrentBranch0
let beforeBranch0LibOnly = Branch.onlyLib beforeBranch0
beforePPED <- Cli.currentPrettyPrintEnvDecl
Expand All @@ -100,13 +100,13 @@ loadUnisonFileForCommit silent sourceName text = do
let sr = Slurp.slurpFile unisonFile mempty Slurp.CheckOp libNames
let adds = SlurpResult.adds sr
let afterBranch0 = Update.doSlurpAdds adds unisonFile beforeBranch0LibOnly
afterPPED <- Cli.currentPrettyPrintEnvDecl
afterPPED <- Cli.prettyPrintEnvDeclFromNames (Branch.toNames afterBranch0)
(_ppe, diff) <- diffFromTypecheckedUnisonFile unisonFile beforeBranch0 afterBranch0
let pped = afterPPED `PPED.addFallback` beforePPED
let ppe = PPE.suffixifiedPPE pped
currentPath <- Cli.getCurrentPath
Cli.respondNumbered $ Output.ShowDiffNamespace (Right currentPath) (Right currentPath) ppe diff
when (not silent) do
when showWatchExprs do
(bindings, e) <- evalUnisonFile Permissive ppe unisonFile []
let e' = Map.map go e
go (ann, kind, _hash, _uneval, eval, isHit) = (ann, kind, eval, isHit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Unison.Type (Type)
import Unison.Typechecker.TypeLookup qualified as TL
import Unison.UnisonFile (TypecheckedUnisonFile)
import Unison.UnisonFile qualified as UF
import Unison.UnisonFile.Names qualified as Names

diffHelper ::
Branch0 IO ->
Expand Down Expand Up @@ -69,13 +70,15 @@ diffFromTypecheckedUnisonFile tf before after = do
names <- Cli.currentNames
pped <- Cli.prettyPrintEnvDeclFromNames names
let suffixifiedPPE = PPED.suffixifiedPPE pped
let beforeNames = Branch.toNames before
let afterNames = Names.addNamesFromTypeCheckedUnisonFile tf (Branch.toNames after)
fmap (suffixifiedPPE,) do
OBranchDiff.toOutput
(getTypeOfReferent codebase)
(getDeclOrBuiltin codebase)
hqLength
(Branch.toNames before)
(Branch.toNames after)
beforeNames
afterNames
diff
where
TL.TypeLookup {dataDecls, effectDecls} = UF.typeLookupForTypecheckedFile tf
Expand Down
3 changes: 1 addition & 2 deletions unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Unison.Cli.MergeTypes (MergeSourceAndTarget, MergeSourceOrTarget)
import Unison.Cli.Share.Projects.Types qualified as Share
import Unison.Codebase.Editor.Input
import Unison.Codebase.Editor.Output.BranchDiff (BranchDiffOutput)
import Unison.Codebase.Editor.Output.BranchDiff qualified as BD
import Unison.Codebase.Editor.Output.PushPull (PushPull)
import Unison.Codebase.Editor.RemoteRepo
import Unison.Codebase.Editor.SlurpResult (SlurpResult (..))
Expand Down Expand Up @@ -661,6 +660,6 @@ isNumberedFailure = \case
ShowDiffAfterModifyBranch {} -> False
ShowDiffAfterPull {} -> False
ShowDiffAfterUndo {} -> False
ShowDiffNamespace _ _ _ bd -> BD.isEmpty bd
ShowDiffNamespace _ _ _ _ -> False
ListNamespaceDependencies {} -> False
TodoOutput _ todo -> TO.todoScore todo > 0 || not (TO.noConflicts todo)
7 changes: 4 additions & 3 deletions unison-cli/src/Unison/CommandLine/InputPatterns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ commit =
)
\case
[] -> pure $ Input.CommitI Nothing
[file] -> Input.LoadI . Just <$> unsupportedStructuredArgument "a file name" file
[file] -> Input.CommitI . Just <$> unsupportedStructuredArgument "a file name" file
_ -> Left (I.help load)

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

update :: InputPattern
Expand Down Expand Up @@ -3190,6 +3190,7 @@ validInputs =
clone,
compileScheme,
commit,
commitPreview,
createAuthor,
debugClearWatchCache,
debugDoctor,
Expand Down
6 changes: 3 additions & 3 deletions unison-src/transcripts/commit-command.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```ucm:hide
.> builtins.merge
.> builtins.merge lib
```

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

```unison
```unison:hide
type MyRecord =
{ nat : Nat
, text : Text
Expand All @@ -21,7 +21,7 @@ addToRecordField rec = nat rec + 10
> addToRecordField (MyRecord 9 "hi" true)
```

```ucm
```ucm:hide
.> add
```

Expand Down
Loading

0 comments on commit 0adc6f3

Please sign in to comment.