Skip to content

Commit

Permalink
Merge pull request #5147 from unisonweb/todo-empty
Browse files Browse the repository at this point in the history
  • Loading branch information
aryairani authored Jun 28, 2024
2 parents 570db9b + a76bca1 commit 0558509
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 63 deletions.
11 changes: 10 additions & 1 deletion unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Unison.Codebase.Editor.Output
HistoryTail (..),
TestReportStats (..),
TodoOutput (..),
todoOutputIsEmpty,
UndoFailureReason (..),
ShareError (..),
UpdateOrUpgrade (..),
Expand All @@ -18,6 +19,7 @@ module Unison.Codebase.Editor.Output
where

import Data.List.NonEmpty (NonEmpty)
import Data.Set qualified as Set
import Data.Set.NonEmpty (NESet)
import Data.Time (UTCTime)
import Network.URI (URI)
Expand Down Expand Up @@ -76,10 +78,11 @@ import Unison.Term (Term)
import Unison.Type (Type)
import Unison.Typechecker.Context qualified as Context
import Unison.UnisonFile qualified as UF
import Unison.Util.Defns (DefnsF)
import Unison.Util.Defns (DefnsF, defnsAreEmpty)
import Unison.Util.Pretty qualified as P
import Unison.Util.Relation (Relation)
import Unison.WatchKind qualified as WK
import qualified Unison.Names as Names

type ListDetailed = Bool

Expand Down Expand Up @@ -157,6 +160,12 @@ data TodoOutput = TodoOutput
ppe :: !PrettyPrintEnvDecl
}

todoOutputIsEmpty :: TodoOutput -> Bool
todoOutputIsEmpty todo =
Set.null todo.dependentsOfTodo
&& defnsAreEmpty todo.directDependenciesWithoutNames
&& Names.isEmpty todo.nameConflicts

data AmbiguousReset'Argument
= AmbiguousReset'Hash
| AmbiguousReset'Target
Expand Down
123 changes: 63 additions & 60 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import Unison.Codebase.Editor.Output
TestReportStats (CachedTests, NewlyComputed),
TodoOutput,
UndoFailureReason (CantUndoPastMerge, CantUndoPastStart),
todoOutputIsEmpty,
)
import Unison.Codebase.Editor.Output qualified as E
import Unison.Codebase.Editor.Output.BranchDiff qualified as OBD
Expand Down Expand Up @@ -2661,66 +2662,68 @@ runNumbered m =
in (a, Foldable.toList args)

handleTodoOutput :: TodoOutput -> Numbered Pretty
handleTodoOutput todo = do
prettyConflicts <-
if todo.nameConflicts == mempty
then pure mempty
else renderNameConflicts todo.ppe.unsuffixifiedPPE todo.nameConflicts

prettyDependentsOfTodo <- do
if Set.null todo.dependentsOfTodo
then pure mempty
else do
terms <-
for (Set.toList todo.dependentsOfTodo) \term -> do
n <- addNumberedArg (SA.HashQualified (HQ.HashOnly (Reference.idToShortHash term)))
let name =
term
& Referent.fromTermReferenceId
& PPE.termName todo.ppe.suffixifiedPPE
& prettyHashQualified
& P.syntaxToColor
pure (formatNum n <> name)
pure $
P.wrap "These terms call `todo`:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.lines terms)

prettyDirectTermDependenciesWithoutNames <- do
if Set.null todo.directDependenciesWithoutNames.terms
then pure mempty
else do
terms <-
for (Set.toList todo.directDependenciesWithoutNames.terms) \term -> do
n <- addNumberedArg (SA.HashQualified (HQ.HashOnly (Reference.toShortHash term)))
pure (formatNum n <> P.syntaxToColor (prettyReference todo.hashLen term))
pure $
P.wrap "These terms do not have any names in the current namespace:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.lines terms)

prettyDirectTypeDependenciesWithoutNames <- do
if Set.null todo.directDependenciesWithoutNames.types
then pure mempty
else do
types <-
for (Set.toList todo.directDependenciesWithoutNames.types) \typ -> do
n <- addNumberedArg (SA.HashQualified (HQ.HashOnly (Reference.toShortHash typ)))
pure (formatNum n <> P.syntaxToColor (prettyReference todo.hashLen typ))
pure $
P.wrap "These types do not have any names in the current namespace:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.lines types)

(pure . P.sep "\n\n" . P.nonEmpty)
[ prettyDependentsOfTodo,
prettyDirectTermDependenciesWithoutNames,
prettyDirectTypeDependenciesWithoutNames,
prettyConflicts
]
handleTodoOutput todo
| todoOutputIsEmpty todo = pure "You have no pending todo items. Good work! ✅"
| otherwise = do
prettyConflicts <-
if todo.nameConflicts == mempty
then pure mempty
else renderNameConflicts todo.ppe.unsuffixifiedPPE todo.nameConflicts

prettyDependentsOfTodo <- do
if Set.null todo.dependentsOfTodo
then pure mempty
else do
terms <-
for (Set.toList todo.dependentsOfTodo) \term -> do
n <- addNumberedArg (SA.HashQualified (HQ.HashOnly (Reference.idToShortHash term)))
let name =
term
& Referent.fromTermReferenceId
& PPE.termName todo.ppe.suffixifiedPPE
& prettyHashQualified
& P.syntaxToColor
pure (formatNum n <> name)
pure $
P.wrap "These terms call `todo`:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.lines terms)

prettyDirectTermDependenciesWithoutNames <- do
if Set.null todo.directDependenciesWithoutNames.terms
then pure mempty
else do
terms <-
for (Set.toList todo.directDependenciesWithoutNames.terms) \term -> do
n <- addNumberedArg (SA.HashQualified (HQ.HashOnly (Reference.toShortHash term)))
pure (formatNum n <> P.syntaxToColor (prettyReference todo.hashLen term))
pure $
P.wrap "These terms do not have any names in the current namespace:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.lines terms)

prettyDirectTypeDependenciesWithoutNames <- do
if Set.null todo.directDependenciesWithoutNames.types
then pure mempty
else do
types <-
for (Set.toList todo.directDependenciesWithoutNames.types) \typ -> do
n <- addNumberedArg (SA.HashQualified (HQ.HashOnly (Reference.toShortHash typ)))
pure (formatNum n <> P.syntaxToColor (prettyReference todo.hashLen typ))
pure $
P.wrap "These types do not have any names in the current namespace:"
<> P.newline
<> P.newline
<> P.indentN 2 (P.lines types)

(pure . P.sep "\n\n" . P.nonEmpty)
[ prettyDependentsOfTodo,
prettyDirectTermDependenciesWithoutNames,
prettyDirectTypeDependenciesWithoutNames,
prettyConflicts
]

listOfDefinitions ::
(Var v) => Input.FindScope -> PPE.PrettyPrintEnv -> E.ListDetailed -> [SR'.SearchResult' v a] -> IO Pretty
Expand Down
4 changes: 2 additions & 2 deletions unison-src/transcripts/fix2254.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ scratch/a2> view A NeedsA f f2 f3 g
scratch/a2> todo
You have no pending todo items. Good work! ✅
```
## Record updates
Expand Down Expand Up @@ -217,6 +217,6 @@ scratch/r2> update.old
scratch/r2> todo
You have no pending todo items. Good work! ✅
```
8 changes: 8 additions & 0 deletions unison-src/transcripts/todo.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Nothing to do

When there's nothing to do, `todo` says this:

```ucm
project/main> todo
```

# Conflicted names

The todo command shows conflicted names (not demonstrated here yet because it is not easy to create them for tests, yet).
Expand Down
10 changes: 10 additions & 0 deletions unison-src/transcripts/todo.output.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Nothing to do

When there's nothing to do, `todo` says this:

```ucm
project/main> todo
You have no pending todo items. Good work! ✅
```
# Conflicted names

The todo command shows conflicted names (not demonstrated here yet because it is not easy to create them for tests, yet).
Expand Down

0 comments on commit 0558509

Please sign in to comment.