From d78154d7c186c967a9eb12c0b661bd15427b663c Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Tue, 9 Jul 2024 18:58:42 -0400 Subject: [PATCH] better rendering of conflicted names in `todo` --- .../src/Unison/CommandLine/OutputMessages.hs | 25 ++++++++++--------- unison-src/transcripts/todo.output.md | 6 +++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/unison-cli/src/Unison/CommandLine/OutputMessages.hs b/unison-cli/src/Unison/CommandLine/OutputMessages.hs index 4bc0ea47a..ef088071d 100644 --- a/unison-cli/src/Unison/CommandLine/OutputMessages.hs +++ b/unison-cli/src/Unison/CommandLine/OutputMessages.hs @@ -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 @@ -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) @@ -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 diff --git a/unison-src/transcripts/todo.output.md b/unison-src/transcripts/todo.output.md index dbc5de722..639de4e52 100644 --- a/unison-src/transcripts/todo.output.md +++ b/unison-src/transcripts/todo.output.md @@ -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.