mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
Maintain NumberedArgs
as structured data
This is the first step toward avoiding printing/parsing the values provided via `NumberedArgs`. It simply adds a new sum type to hold all of the types that can be in numbered args and stores it alongside the `Text` representation. It currently gets discarded when we actually expand the arguments.
This commit is contained in:
parent
a41e8d0bd7
commit
e250d05980
@ -345,8 +345,8 @@ prettyWhichBranchEmpty = \case
|
||||
WhichBranchEmptyPath path -> prettyPath' path
|
||||
|
||||
-- | Displays a full, non-truncated Branch.CausalHash to a string, e.g. #abcdef
|
||||
displayBranchHash :: CausalHash -> String
|
||||
displayBranchHash = ("#" <>) . Text.unpack . Hash.toBase32HexText . unCausalHash
|
||||
displayBranchHash :: CausalHash -> Text
|
||||
displayBranchHash = ("#" <>) . Hash.toBase32HexText . unCausalHash
|
||||
|
||||
prettyHumanReadableTime :: UTCTime -> UTCTime -> Pretty
|
||||
prettyHumanReadableTime now time =
|
||||
|
@ -5,6 +5,7 @@ module Unison.Codebase.Editor.HandleInput (loop) where
|
||||
|
||||
-- TODO: Don't import backend
|
||||
|
||||
import Control.Arrow ((&&&))
|
||||
import Control.Error.Util qualified as ErrorUtil
|
||||
import Control.Lens hiding (from)
|
||||
import Control.Monad.Reader (ask)
|
||||
@ -96,6 +97,7 @@ import Unison.Codebase.Editor.Output.DumpNamespace qualified as Output.DN
|
||||
import Unison.Codebase.Editor.RemoteRepo qualified as RemoteRepo
|
||||
import Unison.Codebase.Editor.Slurp qualified as Slurp
|
||||
import Unison.Codebase.Editor.SlurpResult qualified as SlurpResult
|
||||
import Unison.Codebase.Editor.StructuredArgument qualified as SA
|
||||
import Unison.Codebase.Editor.TodoOutput qualified as TO
|
||||
import Unison.Codebase.IntegrityCheck qualified as IntegrityCheck (integrityCheckFullCodebase)
|
||||
import Unison.Codebase.Metadata qualified as Metadata
|
||||
@ -288,19 +290,22 @@ loop e = do
|
||||
Cli.respond $ PrintMessage pretty
|
||||
ShowReflogI -> do
|
||||
let numEntriesToShow = 500
|
||||
entries <-
|
||||
Cli.runTransaction do
|
||||
schLength <- Codebase.branchHashLength
|
||||
Codebase.getReflog numEntriesToShow <&> fmap (first $ SCH.fromHash schLength)
|
||||
(schLength, entries) <-
|
||||
Cli.runTransaction $
|
||||
(,) <$> Codebase.branchHashLength <*> Codebase.getReflog numEntriesToShow
|
||||
let moreEntriesToLoad = length entries == numEntriesToShow
|
||||
let expandedEntries = List.unfoldr expandEntries (entries, Nothing, moreEntriesToLoad)
|
||||
let numberedEntries = expandedEntries <&> \(_time, hash, _reason) -> "#" <> SCH.toString hash
|
||||
let (shortEntries, numberedEntries) =
|
||||
unzip $
|
||||
expandedEntries <&> \(time, hash, reason) ->
|
||||
let ((exp, txt), sa) = ((id &&& ("#" <>) . SCH.toText) . SCH.fromHash schLength &&& SA.Namespace) hash
|
||||
in ((time, exp, reason), (txt, sa))
|
||||
Cli.setNumberedArgs numberedEntries
|
||||
Cli.respond $ ShowReflog expandedEntries
|
||||
Cli.respond $ ShowReflog shortEntries
|
||||
where
|
||||
expandEntries ::
|
||||
([Reflog.Entry SCH.ShortCausalHash Text], Maybe SCH.ShortCausalHash, Bool) ->
|
||||
Maybe ((Maybe UTCTime, SCH.ShortCausalHash, Text), ([Reflog.Entry SCH.ShortCausalHash Text], Maybe SCH.ShortCausalHash, Bool))
|
||||
([Reflog.Entry CausalHash Text], Maybe CausalHash, Bool) ->
|
||||
Maybe ((Maybe UTCTime, CausalHash, Text), ([Reflog.Entry CausalHash Text], Maybe CausalHash, Bool))
|
||||
expandEntries ([], Just expectedHash, moreEntriesToLoad) =
|
||||
if moreEntriesToLoad
|
||||
then Nothing
|
||||
@ -786,13 +791,13 @@ loop e = do
|
||||
(seg, _) <- Map.toList (Branch._edits b)
|
||||
]
|
||||
Cli.respond $ ListOfPatches $ Set.fromList patches
|
||||
Cli.setNumberedArgs $ fmap (Text.unpack . Name.toText) patches
|
||||
Cli.setNumberedArgs $ fmap (Name.toText &&& SA.Name) patches
|
||||
FindShallowI pathArg -> do
|
||||
Cli.Env {codebase} <- ask
|
||||
|
||||
pathArgAbs <- Cli.resolvePath' pathArg
|
||||
entries <- liftIO (Backend.lsAtPath codebase Nothing pathArgAbs)
|
||||
Cli.setNumberedArgs $ fmap entryToHQString entries
|
||||
Cli.setNumberedArgs $ fmap (entryToHQText &&& SA.ShallowListEntry pathArg) entries
|
||||
pped <- Cli.currentPrettyPrintEnvDecl
|
||||
let suffixifiedPPE = PPED.suffixifiedPPE pped
|
||||
-- This used to be a delayed action which only forced the loading of the root
|
||||
@ -803,19 +808,20 @@ loop e = do
|
||||
let buildPPE = pure suffixifiedPPE
|
||||
Cli.respond $ ListShallow buildPPE entries
|
||||
where
|
||||
entryToHQString :: ShallowListEntry v Ann -> String
|
||||
entryToHQString e =
|
||||
fixup $ Text.unpack case e of
|
||||
entryToHQText :: ShallowListEntry v Ann -> Text
|
||||
entryToHQText e =
|
||||
fixup $ case e of
|
||||
ShallowTypeEntry te -> Backend.typeEntryDisplayName te
|
||||
ShallowTermEntry te -> Backend.termEntryDisplayName te
|
||||
ShallowBranchEntry ns _ _ -> NameSegment.toEscapedText ns
|
||||
ShallowPatchEntry ns -> NameSegment.toEscapedText ns
|
||||
where
|
||||
fixup s = case pathArgStr of
|
||||
"" -> s
|
||||
p | last p == '.' -> p ++ s
|
||||
p -> p ++ "." ++ s
|
||||
pathArgStr = show pathArg
|
||||
fixup s =
|
||||
pathArgStr
|
||||
<> if Text.null pathArgStr || Text.isSuffixOf "." pathArgStr
|
||||
then s
|
||||
else "." <> s
|
||||
pathArgStr = Text.pack $ show pathArg
|
||||
FindI isVerbose fscope ws -> handleFindI isVerbose fscope ws input
|
||||
StructuredFindI _fscope ws -> handleStructuredFindI ws
|
||||
StructuredFindReplaceI ws -> handleStructuredFindReplaceI ws
|
||||
@ -1495,7 +1501,7 @@ handleFindI isVerbose fscope ws input = do
|
||||
(mapMaybe (HQ.parseTextWith anythingBeforeHash . Text.pack) qs)
|
||||
pure $ uniqueBy SR.toReferent srs
|
||||
let respondResults results = do
|
||||
Cli.setNumberedArgs $ fmap (searchResultToHQString searchRoot) results
|
||||
Cli.setNumberedArgs $ fmap (searchResultToHQText searchRoot &&& SA.SearchResult searchRoot) results
|
||||
results' <- Cli.runTransaction (Backend.loadSearchResults codebase results)
|
||||
Cli.respond $ ListOfDefinitions fscope suffixifiedPPE isVerbose results'
|
||||
results <- getResults names
|
||||
@ -1550,8 +1556,8 @@ handleDependencies hq = do
|
||||
let types = nubOrdOn snd . Name.sortByText (HQ.toText . fst) $ (join $ fst <$> results)
|
||||
let terms = nubOrdOn snd . Name.sortByText (HQ.toText . fst) $ (join $ snd <$> results)
|
||||
Cli.setNumberedArgs $
|
||||
map (Text.unpack . Reference.toText . snd) types
|
||||
<> map (Text.unpack . Reference.toText . Referent.toReference . snd) terms
|
||||
map ((Reference.toText &&& SA.Ref) . snd) types
|
||||
<> map ((Reference.toText &&& SA.Ref) . Referent.toReference . snd) terms
|
||||
Cli.respond $ ListDependencies suffixifiedPPE lds (fst <$> types) (fst <$> terms)
|
||||
|
||||
handleDependents :: HQ.HashQualified Name -> Cli ()
|
||||
@ -1588,7 +1594,7 @@ handleDependents hq = do
|
||||
let sort = nubOrdOn snd . Name.sortByText (HQ.toText . fst)
|
||||
let types = sort [(n, r) | (False, n, r) <- join results]
|
||||
let terms = sort [(n, r) | (True, n, r) <- join results]
|
||||
Cli.setNumberedArgs $ map (Text.unpack . Reference.toText . view _2) (types <> terms)
|
||||
Cli.setNumberedArgs . map ((Reference.toText &&& SA.Ref) . view _2) $ types <> terms
|
||||
Cli.respond (ListDependents ppe lds (fst <$> types) (fst <$> terms))
|
||||
|
||||
handleDiffNamespaceToPatch :: Text -> DiffNamespaceToPatchInput -> Cli ()
|
||||
@ -1769,9 +1775,7 @@ doShowTodoOutput patch scopePath = do
|
||||
then Cli.respond NoConflictsOrEdits
|
||||
else do
|
||||
Cli.setNumberedArgs
|
||||
( Text.unpack . Reference.toText . view _2
|
||||
<$> fst (TO.todoFrontierDependents todo)
|
||||
)
|
||||
((Reference.toText &&& SA.Ref) . view _2 <$> fst (TO.todoFrontierDependents todo))
|
||||
pped <- Cli.currentPrettyPrintEnvDecl
|
||||
Cli.respondNumbered $ TodoOutput pped todo
|
||||
|
||||
@ -1817,11 +1821,11 @@ confirmedCommand i = do
|
||||
loopState <- State.get
|
||||
pure $ Just i == (loopState ^. #lastInput)
|
||||
|
||||
-- | restores the full hash to these search results, for _numberedArgs purposes
|
||||
searchResultToHQString :: Maybe Path -> SearchResult -> String
|
||||
searchResultToHQString oprefix = \case
|
||||
SR.Tm' n r _ -> Text.unpack $ HQ.toText $ HQ.requalify (addPrefix <$> n) r
|
||||
SR.Tp' n r _ -> Text.unpack $ HQ.toText $ HQ.requalify (addPrefix <$> n) (Referent.Ref r)
|
||||
--- | restores the full hash to these search results, for _numberedArgs purposes
|
||||
searchResultToHQText :: Maybe Path -> SearchResult -> Text
|
||||
searchResultToHQText oprefix = \case
|
||||
SR.Tm' n r _ -> HQ.toText $ HQ.requalify (addPrefix <$> n) r
|
||||
SR.Tp' n r _ -> HQ.toText $ HQ.requalify (addPrefix <$> n) (Referent.Ref r)
|
||||
_ -> error "impossible match failure"
|
||||
where
|
||||
addPrefix :: Name -> Name
|
||||
|
@ -4,6 +4,7 @@ module Unison.Codebase.Editor.HandleInput.FindAndReplace
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Arrow ((&&&))
|
||||
import Control.Lens hiding (at)
|
||||
import Control.Monad.Reader (ask)
|
||||
import Control.Monad.State
|
||||
@ -18,6 +19,7 @@ import Unison.Cli.Pretty qualified as P
|
||||
import Unison.Codebase qualified as Codebase
|
||||
import Unison.Codebase.Branch.Names qualified as Branch
|
||||
import Unison.Codebase.Editor.Output
|
||||
import Unison.Codebase.Editor.StructuredArgument qualified as SA
|
||||
import Unison.HashQualified qualified as HQ
|
||||
import Unison.HashQualified' qualified as HQ'
|
||||
import Unison.Name (Name)
|
||||
@ -87,7 +89,7 @@ handleStructuredFindI rule = do
|
||||
ok t = pure (t, False)
|
||||
results0 <- traverse ok results
|
||||
let results = Alphabetical.sortAlphabeticallyOn fst [(hq, r) | ((hq, r), True) <- results0]
|
||||
let toNumArgs = Text.unpack . Reference.toText . Referent.toReference . view _2
|
||||
let toNumArgs = (Reference.toText &&& SA.Ref) . Referent.toReference . view _2
|
||||
Cli.setNumberedArgs $ map toNumArgs results
|
||||
Cli.respond (ListStructuredFind (fst <$> results))
|
||||
|
||||
|
@ -36,6 +36,7 @@ import Unison.Codebase.Editor.Output.PushPull (PushPull)
|
||||
import Unison.Codebase.Editor.RemoteRepo
|
||||
import Unison.Codebase.Editor.SlurpResult (SlurpResult (..))
|
||||
import Unison.Codebase.Editor.SlurpResult qualified as SR
|
||||
import Unison.Codebase.Editor.StructuredArgument (StructuredArgument)
|
||||
import Unison.Codebase.Editor.TodoOutput qualified as TO
|
||||
import Unison.Codebase.IntegrityCheck (IntegrityResult (..))
|
||||
import Unison.Codebase.Patch (Patch)
|
||||
@ -84,7 +85,12 @@ type ListDetailed = Bool
|
||||
|
||||
type SourceName = Text
|
||||
|
||||
type NumberedArgs = [String]
|
||||
-- |
|
||||
--
|
||||
-- __NB__: This only temporarily holds `Text`. Until all of the inputs are
|
||||
-- updated to handle `StructuredArgument`s, we need to ensure that the
|
||||
-- serialization remains unchanged.
|
||||
type NumberedArgs = [(Text, StructuredArgument)]
|
||||
|
||||
type HashLength = Int
|
||||
|
||||
|
31
unison-cli/src/Unison/Codebase/Editor/StructuredArgument.hs
Normal file
31
unison-cli/src/Unison/Codebase/Editor/StructuredArgument.hs
Normal file
@ -0,0 +1,31 @@
|
||||
module Unison.Codebase.Editor.StructuredArgument where
|
||||
|
||||
import GHC.Generics (Generic)
|
||||
import U.Codebase.HashTags (CausalHash)
|
||||
import Unison.Codebase.Editor.Input
|
||||
import Unison.Codebase.Path (Path, Path')
|
||||
import Unison.Codebase.Path qualified as Path
|
||||
import Unison.HashQualified qualified as HQ
|
||||
import Unison.HashQualified' qualified as HQ'
|
||||
import Unison.Name (Name)
|
||||
import Unison.Parser.Ann (Ann)
|
||||
import Unison.Project (ProjectAndBranch, ProjectBranchName, ProjectName)
|
||||
import Unison.Reference (Reference)
|
||||
import Unison.Server.Backend (ShallowListEntry)
|
||||
import Unison.Server.SearchResult (SearchResult)
|
||||
import Unison.Symbol (Symbol)
|
||||
|
||||
-- | The types that can be referenced by a numeric command argument.
|
||||
data StructuredArgument
|
||||
= AbsolutePath Path.Absolute
|
||||
| Name Name
|
||||
| HashQualified (HQ.HashQualified Name)
|
||||
| Project ProjectName
|
||||
| ProjectBranch (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
|
||||
| Ref Reference
|
||||
| Namespace CausalHash
|
||||
| NameWithBranchPrefix AbsBranchId Name
|
||||
| HashQualifiedWithBranchPrefix AbsBranchId (HQ'.HashQualified Name)
|
||||
| ShallowListEntry Path' (ShallowListEntry Symbol Ann)
|
||||
| SearchResult (Maybe Path) SearchResult
|
||||
deriving (Eq, Generic, Show)
|
@ -173,7 +173,7 @@ expandNumber :: NumberedArgs -> String -> [String]
|
||||
expandNumber numberedArgs s = case expandedNumber of
|
||||
Nothing -> [s]
|
||||
Just nums ->
|
||||
[s | i <- nums, Just s <- [vargs Vector.!? (i - 1)]]
|
||||
[Text.unpack (fst s) | i <- nums, Just s <- [vargs Vector.!? (i - 1)]]
|
||||
where
|
||||
vargs = Vector.fromList numberedArgs
|
||||
rangeRegex = "([0-9]+)-([0-9]+)" :: String
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
module Unison.CommandLine.OutputMessages where
|
||||
|
||||
import Control.Arrow ((&&&))
|
||||
import Control.Lens hiding (at)
|
||||
import Control.Monad.State
|
||||
import Control.Monad.State.Strict qualified as State
|
||||
@ -61,6 +62,8 @@ import Unison.Codebase.Editor.Output.PushPull qualified as PushPull
|
||||
import Unison.Codebase.Editor.RemoteRepo (ShareUserHandle (..), WriteRemoteNamespace (..), WriteShareRemoteNamespace (..))
|
||||
import Unison.Codebase.Editor.RemoteRepo qualified as RemoteRepo
|
||||
import Unison.Codebase.Editor.SlurpResult qualified as SlurpResult
|
||||
import Unison.Codebase.Editor.StructuredArgument (StructuredArgument)
|
||||
import Unison.Codebase.Editor.StructuredArgument qualified as SA
|
||||
import Unison.Codebase.Editor.TodoOutput qualified as TO
|
||||
import Unison.Codebase.GitError
|
||||
import Unison.Codebase.IntegrityCheck (IntegrityResult (..), prettyPrintIntegrityErrors)
|
||||
@ -348,7 +351,7 @@ notifyNumbered = \case
|
||||
]
|
||||
branchHashes :: [CausalHash]
|
||||
branchHashes = (fst <$> reversedHistory) <> tailHashes
|
||||
in (msg, displayBranchHash <$> branchHashes)
|
||||
in (msg, (displayBranchHash &&& SA.Namespace) <$> branchHashes)
|
||||
where
|
||||
toSCH :: CausalHash -> ShortCausalHash
|
||||
toSCH h = SCH.fromHash schLength h
|
||||
@ -407,7 +410,7 @@ notifyNumbered = \case
|
||||
ListEdits patch ppe -> showListEdits patch ppe
|
||||
ListProjects projects ->
|
||||
( P.numberedList (map (prettyProjectName . view #name) projects),
|
||||
map (Text.unpack . into @Text . view #name) projects
|
||||
map ((into @Text &&& SA.Project) . view #name) projects
|
||||
)
|
||||
ListBranches projectName branches ->
|
||||
( P.columnNHeader
|
||||
@ -423,7 +426,13 @@ notifyNumbered = \case
|
||||
]
|
||||
: map (\branch -> ["", "", prettyRemoteBranchInfo branch]) remoteBranches
|
||||
),
|
||||
map (\(branchName, _) -> Text.unpack (into @Text (ProjectAndBranch projectName branchName))) branches
|
||||
map
|
||||
( ( (into @Text . ProjectAndBranch projectName)
|
||||
&&& (SA.ProjectBranch . ProjectAndBranch (pure projectName))
|
||||
)
|
||||
. fst
|
||||
)
|
||||
branches
|
||||
)
|
||||
AmbiguousSwitch project (ProjectAndBranch currentProject branch) ->
|
||||
( P.wrap
|
||||
@ -448,8 +457,11 @@ notifyNumbered = \case
|
||||
<> switch ["2"]
|
||||
<> " to pick one of these."
|
||||
),
|
||||
[ Text.unpack (Text.cons '/' (into @Text branch)),
|
||||
Text.unpack (into @Text (ProjectAndBranch project (UnsafeProjectBranchName "main")))
|
||||
[ (Text.cons '/' . into @Text &&& SA.ProjectBranch . ProjectAndBranch Nothing) branch,
|
||||
( (into @Text . ProjectAndBranch project)
|
||||
&&& (SA.ProjectBranch . ProjectAndBranch (pure project))
|
||||
)
|
||||
$ UnsafeProjectBranchName "main"
|
||||
]
|
||||
)
|
||||
where
|
||||
@ -478,8 +490,8 @@ notifyNumbered = \case
|
||||
<> reset (resetArgs ["2"])
|
||||
<> " to pick one of these."
|
||||
),
|
||||
[ Text.unpack (Text.cons '/' (into @Text branch)),
|
||||
Text.unpack (into @Text (show absPath0))
|
||||
[ (Text.cons '/' . into @Text &&& SA.ProjectBranch . ProjectAndBranch Nothing) branch,
|
||||
(into @Text . show &&& SA.AbsolutePath) absPath0
|
||||
]
|
||||
)
|
||||
where
|
||||
@ -515,13 +527,13 @@ notifyNumbered = \case
|
||||
newNextNum = nextNum + length unnumberedNames
|
||||
in ( newNextNum,
|
||||
( nameToNum <> (Map.fromList (zip unnumberedNames [nextNum ..])),
|
||||
args <> fmap Name.toText unnumberedNames
|
||||
args <> unnumberedNames
|
||||
)
|
||||
)
|
||||
)
|
||||
(1, (mempty, mempty))
|
||||
& snd
|
||||
& over (_2 . mapped) Text.unpack
|
||||
& over (_2 . mapped) (Name.toText &&& SA.Name)
|
||||
externalDepsTable :: Map LabeledDependency (Set Name) -> [(P.Pretty P.ColorText, P.Pretty P.ColorText)]
|
||||
externalDepsTable = ifoldMap $ \ld dependents ->
|
||||
[(prettyLD ld, prettyDependents dependents)]
|
||||
@ -601,7 +613,7 @@ showListEdits patch ppe =
|
||||
let lhsTermName = PPE.termName ppe (Referent.Ref lhsRef)
|
||||
-- We use the shortHash of the lhs rather than its name for numbered args,
|
||||
-- since its name is likely to be "historical", and won't work if passed to a ucm command.
|
||||
let lhsHash = Text.unpack . ShortHash.toText . Reference.toShortHash $ lhsRef
|
||||
let lhsHash = (ShortHash.toText . Reference.toShortHash &&& SA.Ref) $ lhsRef
|
||||
case termEdit of
|
||||
TermEdit.Deprecate -> do
|
||||
lift $ tell ([lhsHash], [])
|
||||
@ -612,7 +624,7 @@ showListEdits patch ppe =
|
||||
TermEdit.Replace rhsRef _typing -> do
|
||||
n2 <- gets snd <* modify (second succ)
|
||||
let rhsTermName = PPE.termName ppe (Referent.Ref rhsRef)
|
||||
lift $ tell ([lhsHash], [Text.unpack (HQ.toText rhsTermName)])
|
||||
lift $ tell ([lhsHash], [(HQ.toText &&& SA.HashQualified) rhsTermName])
|
||||
pure
|
||||
( showNum n1 <> (P.syntaxToColor . prettyHashQualified $ lhsTermName),
|
||||
"-> " <> showNum n2 <> (P.syntaxToColor . prettyHashQualified $ rhsTermName)
|
||||
@ -626,7 +638,7 @@ showListEdits patch ppe =
|
||||
let lhsTypeName = PPE.typeName ppe lhsRef
|
||||
-- We use the shortHash of the lhs rather than its name for numbered args,
|
||||
-- since its name is likely to be "historical", and won't work if passed to a ucm command.
|
||||
let lhsHash = Text.unpack . ShortHash.toText . Reference.toShortHash $ lhsRef
|
||||
let lhsHash = (ShortHash.toText . Reference.toShortHash &&& SA.Ref) $ lhsRef
|
||||
case typeEdit of
|
||||
TypeEdit.Deprecate -> do
|
||||
lift $ tell ([lhsHash], [])
|
||||
@ -637,7 +649,7 @@ showListEdits patch ppe =
|
||||
TypeEdit.Replace rhsRef -> do
|
||||
n2 <- gets snd <* modify (second succ)
|
||||
let rhsTypeName = PPE.typeName ppe rhsRef
|
||||
lift $ tell ([lhsHash], [Text.unpack (HQ.toText rhsTypeName)])
|
||||
lift $ tell ([lhsHash], [(HQ.toText &&& SA.HashQualified) rhsTypeName])
|
||||
pure
|
||||
( showNum n1 <> (P.syntaxToColor . prettyHashQualified $ lhsTypeName),
|
||||
"-> " <> showNum n2 <> (P.syntaxToColor . prettyHashQualified $ rhsTypeName)
|
||||
@ -1651,7 +1663,7 @@ notifyUser dir = \case
|
||||
prettyNamespaceKey dest
|
||||
<> "is already up-to-date with"
|
||||
<> P.group (prettyNamespaceKey src <> ".")
|
||||
DumpNumberedArgs args -> pure . P.numberedList $ fmap P.string args
|
||||
DumpNumberedArgs args -> pure . P.numberedList $ fmap (P.text . fst) args
|
||||
NoConflictsOrEdits ->
|
||||
pure (P.okCallout "No conflicts or edits in progress.")
|
||||
HelpMessage pat -> pure $ IP.showPatternHelp pat
|
||||
@ -2717,7 +2729,7 @@ renderNameConflicts ppe conflictedNames = do
|
||||
P.lines <$> do
|
||||
for (Map.toList conflictedNames) $ \(name, hashes) -> do
|
||||
prettyConflicts <- for hashes \hash -> do
|
||||
n <- addNumberedArg (Text.unpack (HQ.toText hash))
|
||||
n <- addNumberedArg $ (HQ.toText &&& SA.HashQualified) hash
|
||||
pure $ formatNum n <> (P.blue . P.syntaxToColor . prettyHashQualified $ hash)
|
||||
pure . P.wrap $
|
||||
( "The "
|
||||
@ -2749,7 +2761,7 @@ renderEditConflicts ppe Patch {..} = do
|
||||
<> (fmap Right . Map.toList . R.toMultimap . R.filterManyDom $ _termEdits)
|
||||
numberedHQName :: HQ.HashQualified Name -> Numbered Pretty
|
||||
numberedHQName hqName = do
|
||||
n <- addNumberedArg (Text.unpack (HQ.toText hqName))
|
||||
n <- addNumberedArg $ (HQ.toText &&& SA.HashQualified) hqName
|
||||
pure $ formatNum n <> styleHashQualified P.bold hqName
|
||||
formatTypeEdits ::
|
||||
(Reference, Set TypeEdit.TypeEdit) ->
|
||||
@ -2788,9 +2800,9 @@ renderEditConflicts ppe Patch {..} = do
|
||||
Numbered Pretty
|
||||
formatConflict = either formatTypeEdits formatTermEdits
|
||||
|
||||
type Numbered = State.State (Int, Seq.Seq String)
|
||||
type Numbered = State.State (Int, Seq.Seq (Text, StructuredArgument))
|
||||
|
||||
addNumberedArg :: String -> Numbered Int
|
||||
addNumberedArg :: (Text, StructuredArgument) -> Numbered Int
|
||||
addNumberedArg s = do
|
||||
(n, args) <- State.get
|
||||
State.put (n + 1, args Seq.|> s)
|
||||
@ -2862,11 +2874,11 @@ todoOutput ppe todo = runNumbered do
|
||||
todoEdits :: Numbered Pretty
|
||||
todoEdits = do
|
||||
numberedTypes <- for (unscore <$> dirtyTypes) \(ref, displayObj) -> do
|
||||
n <- addNumberedArg (Text.unpack (HQ.toText $ PPE.typeName ppeu ref))
|
||||
n <- addNumberedArg . (HQ.toText &&& SA.HashQualified) $ PPE.typeName ppeu ref
|
||||
pure $ formatNum n <> prettyDeclPair ppeu (ref, displayObj)
|
||||
let filteredTerms = goodTerms (unscore <$> dirtyTerms)
|
||||
termNumbers <- for filteredTerms \(ref, _, _) -> do
|
||||
n <- addNumberedArg (Text.unpack (HQ.toText $ PPE.termName ppeu ref))
|
||||
n <- addNumberedArg . (HQ.toText &&& SA.HashQualified) $ PPE.termName ppeu ref
|
||||
pure $ formatNum n
|
||||
let formattedTerms = TypePrinter.prettySignaturesCT ppes filteredTerms
|
||||
numberedTerms = zipWith (<>) termNumbers formattedTerms
|
||||
@ -3166,7 +3178,7 @@ showDiffNamespace sn ppe oldPath newPath OBD.BranchDiffOutput {..} =
|
||||
[] -> mempty
|
||||
x : ys -> " (" <> P.commas (x <> " updates" : ys) <> ")"
|
||||
pure $ n <> P.bold " patch " <> prettyName name <> message
|
||||
-- 18. patch q
|
||||
-- 18. patch q
|
||||
prettyNamePatch prefix (name, _patchDiff) = do
|
||||
n <- numPatch prefix name
|
||||
pure $ n <> P.bold " patch " <> prettyName name
|
||||
@ -3271,21 +3283,21 @@ showDiffNamespace sn ppe oldPath newPath OBD.BranchDiffOutput {..} =
|
||||
-- DeclPrinter.prettyDeclHeader : HQ -> Either
|
||||
numPatch :: Input.AbsBranchId -> Name -> Numbered Pretty
|
||||
numPatch prefix name =
|
||||
addNumberedArg' $ prefixBranchId prefix name
|
||||
addNumberedArg' $ (prefixBranchId prefix &&& SA.NameWithBranchPrefix prefix) name
|
||||
|
||||
numHQ' :: Input.AbsBranchId -> HQ'.HashQualified Name -> Referent -> Numbered Pretty
|
||||
numHQ' prefix hq r =
|
||||
addNumberedArg' . HQ'.toStringWith (prefixBranchId prefix) . HQ'.requalify hq $ r
|
||||
addNumberedArg' . (HQ'.toTextWith (prefixBranchId prefix) &&& SA.HashQualifiedWithBranchPrefix prefix) $ HQ'.requalify hq r
|
||||
|
||||
-- E.g.
|
||||
-- prefixBranchId "#abcdef" "base.List.map" -> "#abcdef.base.List.map"
|
||||
-- prefixBranchId "#abcdef" "base.List.map" -> "#abcdef:.base.List.map"
|
||||
-- prefixBranchId ".base" "List.map" -> ".base.List.map"
|
||||
prefixBranchId :: Input.AbsBranchId -> Name -> String
|
||||
prefixBranchId :: Input.AbsBranchId -> Name -> Text
|
||||
prefixBranchId branchId name = case branchId of
|
||||
Left sch -> "#" <> SCH.toString sch <> ":" <> Text.unpack (Name.toText (Name.makeAbsolute name))
|
||||
Right pathPrefix -> Text.unpack (Name.toText (Name.makeAbsolute . Path.prefixName pathPrefix $ name))
|
||||
Left sch -> "#" <> SCH.toText sch <> ":" <> Name.toText (Name.makeAbsolute name)
|
||||
Right pathPrefix -> Name.toText (Name.makeAbsolute . Path.prefixName pathPrefix $ name)
|
||||
|
||||
addNumberedArg' :: String -> Numbered Pretty
|
||||
addNumberedArg' :: (Text, StructuredArgument) -> Numbered Pretty
|
||||
addNumberedArg' s = case sn of
|
||||
ShowNumbers -> do
|
||||
n <- addNumberedArg s
|
||||
@ -3540,7 +3552,7 @@ numberedArgsForEndangerments (PPED.unsuffixifiedPPE -> ppe) m =
|
||||
m
|
||||
& Map.elems
|
||||
& concatMap toList
|
||||
& fmap (Text.unpack . HQ.toText . PPE.labeledRefName ppe)
|
||||
& fmap ((HQ.toText &&& SA.HashQualified) . PPE.labeledRefName ppe)
|
||||
|
||||
-- | Format and render all dependents which are endangered by references going extinct.
|
||||
endangeredDependentsTable ::
|
||||
|
@ -6,6 +6,8 @@ where
|
||||
import Control.Lens
|
||||
import EasyTest
|
||||
import Unison.Cli.Monad qualified as Cli
|
||||
import Unison.Codebase.Editor.StructuredArgument qualified as SA
|
||||
import Unison.Reference qualified as Reference
|
||||
|
||||
test :: Test ()
|
||||
test =
|
||||
@ -16,13 +18,13 @@ test =
|
||||
Cli.runCli dummyEnv dummyLoopState do
|
||||
Cli.label \goto -> do
|
||||
Cli.label \_ -> do
|
||||
Cli.setNumberedArgs ["foo"]
|
||||
Cli.setNumberedArgs [SA.Ref $ Reference.ReferenceBuiltin "foo"]
|
||||
goto (1 :: Int)
|
||||
pure 2
|
||||
-- test that 'goto' short-circuits, as expected
|
||||
expectEqual' (Cli.Success 1) r
|
||||
-- test that calling 'goto' doesn't lose state changes made along the way
|
||||
expectEqual' ["foo"] (state ^. #numberedArgs)
|
||||
expectEqual' [SA.Ref $ Reference.ReferenceBuiltin "foo"] (state ^. #numberedArgs)
|
||||
ok
|
||||
]
|
||||
|
||||
|
@ -93,6 +93,7 @@ library
|
||||
Unison.Codebase.Editor.Slurp
|
||||
Unison.Codebase.Editor.SlurpComponent
|
||||
Unison.Codebase.Editor.SlurpResult
|
||||
Unison.Codebase.Editor.StructuredArgument
|
||||
Unison.Codebase.Editor.TodoOutput
|
||||
Unison.Codebase.Editor.UCMVersion
|
||||
Unison.Codebase.Editor.UriParser
|
||||
|
Loading…
Reference in New Issue
Block a user