Skip to content

Commit

Permalink
better rendering of conflicted names in todo
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Jul 9, 2024
1 parent 1e5b925 commit d78154d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
25 changes: 13 additions & 12 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2593,20 +2593,20 @@ unsafePrettyTermResultSig' ppe = \case
head (TypePrinter.prettySignaturesCT ppe [(r, name, typ)])
_ -> error "Don't pass Nothing"

renderNameConflicts :: PPE.PrettyPrintEnv -> Names -> Numbered Pretty
renderNameConflicts ppe conflictedNames = do
renderNameConflicts :: Int -> Names -> Numbered Pretty
renderNameConflicts hashLen conflictedNames = do
let conflictedTypeNames :: Map Name [HQ.HashQualified Name]
conflictedTypeNames =
conflictedNames
& Names.types
& R.domain
& fmap (foldMap (pure @[] . PPE.typeName ppe))
& Map.mapWithKey \name -> map (HQ.take hashLen . HQ.HashQualified name . Reference.toShortHash) . Set.toList
let conflictedTermNames :: Map Name [HQ.HashQualified Name]
conflictedTermNames =
conflictedNames
& Names.terms
& R.domain
& fmap (foldMap (pure @[] . PPE.termName ppe))
& Map.mapWithKey \name -> map (HQ.take hashLen . HQ.HashQualified name . Referent.toShortHash) . Set.toList
let allConflictedNames :: [Name]
allConflictedNames = Set.toList (Map.keysSet conflictedTermNames <> Map.keysSet conflictedTypeNames)
prettyConflictedTypes <- showConflictedNames "type" conflictedTypeNames
Expand Down Expand Up @@ -2639,13 +2639,14 @@ renderNameConflicts ppe conflictedNames = do
prettyConflicts <- for hashes \hash -> do
n <- addNumberedArg $ SA.HashQualified hash
pure $ formatNum n <> (P.blue . P.syntaxToColor . prettyHashQualified $ hash)
pure . P.wrap $
( "The "
<> thingKind
<> " "
<> P.green (prettyName name)
<> " has conflicting definitions:"
)
pure $
P.wrap
( "The "
<> thingKind
<> " "
<> P.green (prettyName name)
<> " has conflicting definitions:"
)
<> P.newline
<> P.newline
<> P.indentN 2 (P.lines prettyConflicts)
Expand Down Expand Up @@ -2722,7 +2723,7 @@ handleTodoOutput todo
prettyConflicts <-
if todo.nameConflicts == mempty
then pure mempty
else renderNameConflicts todo.ppe.unsuffixifiedPPE todo.nameConflicts
else renderNameConflicts todo.hashLen todo.nameConflicts

let prettyDefnsInLib =
if todo.defnsInLib
Expand Down
6 changes: 4 additions & 2 deletions unison-src/transcripts/todo.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ scratch/main> todo
The term bar has conflicting definitions: 1. foo 2.
bar#cq22mm4sca
The term bar has conflicting definitions:
1. bar#14ibahkll6
2. bar#cq22mm4sca
Tip: Use `move.term` or `delete.term` to resolve the
conflicts.
Expand Down

0 comments on commit d78154d

Please sign in to comment.