module Unison.Codebase.Editor.Input
  ( Input (..),
    BranchSourceI (..),
    PullSourceTarget (..),
    PushRemoteBranchInput (..),
    PushSourceTarget (..),
    PushSource (..),
    TestInput (..),
    Event (..),
    OutputLocation (..),
    PatchPath,
    BranchIdG (..),
    BranchId,
    BranchId2,
    AbsBranchId,
    UnresolvedProjectBranch,
    parseBranchId,
    parseBranchId2,
    parseShortCausalHash,
    HashOrHQSplit',
    Insistence (..),
    PullMode (..),
    OptionalPatch (..),
    FindScope (..),
    ShowDefinitionScope (..),
    IsGlobal,
    DeleteOutput (..),
    DeleteTarget (..),
  )
where

import Data.List.NonEmpty (NonEmpty)
import Data.Text qualified as Text
import Data.These (These)
import Unison.Codebase.Branch.Merge qualified as Branch
import Unison.Codebase.Editor.RemoteRepo (ReadRemoteNamespace)
import Unison.Codebase.Path (Path, Path')
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.Path.Parse qualified as Path
import Unison.Codebase.ProjectPath (ProjectPath)
import Unison.Codebase.PushBehavior (PushBehavior)
import Unison.Codebase.ShortCausalHash (ShortCausalHash)
import Unison.Codebase.ShortCausalHash qualified as SCH
import Unison.CommandLine.BranchRelativePath (BranchRelativePath, parseBranchRelativePath)
import Unison.HashQualified qualified as HQ
import Unison.Name (Name)
import Unison.NameSegment (NameSegment)
import Unison.Prelude
import Unison.Project (ProjectAndBranch, ProjectAndBranchNames, ProjectBranchName, ProjectBranchNameOrLatestRelease, ProjectName, Semver)
import Unison.ShortHash (ShortHash)
import Unison.Util.Pretty qualified as P

data Event
  = UnisonFileChanged SourceName Source
  deriving stock (Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Event -> ShowS
showsPrec :: Int -> Event -> ShowS
$cshow :: Event -> String
show :: Event -> String
$cshowList :: [Event] -> ShowS
showList :: [Event] -> ShowS
Show)

type Source = Text -- "id x = x\nconst a b = a"

type SourceName = Text -- "foo.u" or "buffer 7"

type PatchPath = Path.Split'

data OptionalPatch = NoPatch | DefaultPatch | UsePatch PatchPath
  deriving (OptionalPatch -> OptionalPatch -> Bool
(OptionalPatch -> OptionalPatch -> Bool)
-> (OptionalPatch -> OptionalPatch -> Bool) -> Eq OptionalPatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OptionalPatch -> OptionalPatch -> Bool
== :: OptionalPatch -> OptionalPatch -> Bool
$c/= :: OptionalPatch -> OptionalPatch -> Bool
/= :: OptionalPatch -> OptionalPatch -> Bool
Eq, Eq OptionalPatch
Eq OptionalPatch =>
(OptionalPatch -> OptionalPatch -> Ordering)
-> (OptionalPatch -> OptionalPatch -> Bool)
-> (OptionalPatch -> OptionalPatch -> Bool)
-> (OptionalPatch -> OptionalPatch -> Bool)
-> (OptionalPatch -> OptionalPatch -> Bool)
-> (OptionalPatch -> OptionalPatch -> OptionalPatch)
-> (OptionalPatch -> OptionalPatch -> OptionalPatch)
-> Ord OptionalPatch
OptionalPatch -> OptionalPatch -> Bool
OptionalPatch -> OptionalPatch -> Ordering
OptionalPatch -> OptionalPatch -> OptionalPatch
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: OptionalPatch -> OptionalPatch -> Ordering
compare :: OptionalPatch -> OptionalPatch -> Ordering
$c< :: OptionalPatch -> OptionalPatch -> Bool
< :: OptionalPatch -> OptionalPatch -> Bool
$c<= :: OptionalPatch -> OptionalPatch -> Bool
<= :: OptionalPatch -> OptionalPatch -> Bool
$c> :: OptionalPatch -> OptionalPatch -> Bool
> :: OptionalPatch -> OptionalPatch -> Bool
$c>= :: OptionalPatch -> OptionalPatch -> Bool
>= :: OptionalPatch -> OptionalPatch -> Bool
$cmax :: OptionalPatch -> OptionalPatch -> OptionalPatch
max :: OptionalPatch -> OptionalPatch -> OptionalPatch
$cmin :: OptionalPatch -> OptionalPatch -> OptionalPatch
min :: OptionalPatch -> OptionalPatch -> OptionalPatch
Ord, Int -> OptionalPatch -> ShowS
[OptionalPatch] -> ShowS
OptionalPatch -> String
(Int -> OptionalPatch -> ShowS)
-> (OptionalPatch -> String)
-> ([OptionalPatch] -> ShowS)
-> Show OptionalPatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OptionalPatch -> ShowS
showsPrec :: Int -> OptionalPatch -> ShowS
$cshow :: OptionalPatch -> String
show :: OptionalPatch -> String
$cshowList :: [OptionalPatch] -> ShowS
showList :: [OptionalPatch] -> ShowS
Show)

data BranchIdG p
  = BranchAtSCH ShortCausalHash
  | BranchAtPath p
  | BranchAtProjectPath ProjectPath
  deriving stock (BranchIdG p -> BranchIdG p -> Bool
(BranchIdG p -> BranchIdG p -> Bool)
-> (BranchIdG p -> BranchIdG p -> Bool) -> Eq (BranchIdG p)
forall p. Eq p => BranchIdG p -> BranchIdG p -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall p. Eq p => BranchIdG p -> BranchIdG p -> Bool
== :: BranchIdG p -> BranchIdG p -> Bool
$c/= :: forall p. Eq p => BranchIdG p -> BranchIdG p -> Bool
/= :: BranchIdG p -> BranchIdG p -> Bool
Eq, Int -> BranchIdG p -> ShowS
[BranchIdG p] -> ShowS
BranchIdG p -> String
(Int -> BranchIdG p -> ShowS)
-> (BranchIdG p -> String)
-> ([BranchIdG p] -> ShowS)
-> Show (BranchIdG p)
forall p. Show p => Int -> BranchIdG p -> ShowS
forall p. Show p => [BranchIdG p] -> ShowS
forall p. Show p => BranchIdG p -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall p. Show p => Int -> BranchIdG p -> ShowS
showsPrec :: Int -> BranchIdG p -> ShowS
$cshow :: forall p. Show p => BranchIdG p -> String
show :: BranchIdG p -> String
$cshowList :: forall p. Show p => [BranchIdG p] -> ShowS
showList :: [BranchIdG p] -> ShowS
Show, (forall a b. (a -> b) -> BranchIdG a -> BranchIdG b)
-> (forall a b. a -> BranchIdG b -> BranchIdG a)
-> Functor BranchIdG
forall a b. a -> BranchIdG b -> BranchIdG a
forall a b. (a -> b) -> BranchIdG a -> BranchIdG b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> BranchIdG a -> BranchIdG b
fmap :: forall a b. (a -> b) -> BranchIdG a -> BranchIdG b
$c<$ :: forall a b. a -> BranchIdG b -> BranchIdG a
<$ :: forall a b. a -> BranchIdG b -> BranchIdG a
Functor, (forall m. Monoid m => BranchIdG m -> m)
-> (forall m a. Monoid m => (a -> m) -> BranchIdG a -> m)
-> (forall m a. Monoid m => (a -> m) -> BranchIdG a -> m)
-> (forall a b. (a -> b -> b) -> b -> BranchIdG a -> b)
-> (forall a b. (a -> b -> b) -> b -> BranchIdG a -> b)
-> (forall b a. (b -> a -> b) -> b -> BranchIdG a -> b)
-> (forall b a. (b -> a -> b) -> b -> BranchIdG a -> b)
-> (forall a. (a -> a -> a) -> BranchIdG a -> a)
-> (forall a. (a -> a -> a) -> BranchIdG a -> a)
-> (forall a. BranchIdG a -> [a])
-> (forall a. BranchIdG a -> Bool)
-> (forall a. BranchIdG a -> Int)
-> (forall a. Eq a => a -> BranchIdG a -> Bool)
-> (forall a. Ord a => BranchIdG a -> a)
-> (forall a. Ord a => BranchIdG a -> a)
-> (forall a. Num a => BranchIdG a -> a)
-> (forall a. Num a => BranchIdG a -> a)
-> Foldable BranchIdG
forall a. Eq a => a -> BranchIdG a -> Bool
forall a. Num a => BranchIdG a -> a
forall a. Ord a => BranchIdG a -> a
forall m. Monoid m => BranchIdG m -> m
forall a. BranchIdG a -> Bool
forall a. BranchIdG a -> Int
forall a. BranchIdG a -> [a]
forall a. (a -> a -> a) -> BranchIdG a -> a
forall m a. Monoid m => (a -> m) -> BranchIdG a -> m
forall b a. (b -> a -> b) -> b -> BranchIdG a -> b
forall a b. (a -> b -> b) -> b -> BranchIdG a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => BranchIdG m -> m
fold :: forall m. Monoid m => BranchIdG m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> BranchIdG a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> BranchIdG a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> BranchIdG a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> BranchIdG a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> BranchIdG a -> b
foldr :: forall a b. (a -> b -> b) -> b -> BranchIdG a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> BranchIdG a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> BranchIdG a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> BranchIdG a -> b
foldl :: forall b a. (b -> a -> b) -> b -> BranchIdG a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> BranchIdG a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> BranchIdG a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> BranchIdG a -> a
foldr1 :: forall a. (a -> a -> a) -> BranchIdG a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> BranchIdG a -> a
foldl1 :: forall a. (a -> a -> a) -> BranchIdG a -> a
$ctoList :: forall a. BranchIdG a -> [a]
toList :: forall a. BranchIdG a -> [a]
$cnull :: forall a. BranchIdG a -> Bool
null :: forall a. BranchIdG a -> Bool
$clength :: forall a. BranchIdG a -> Int
length :: forall a. BranchIdG a -> Int
$celem :: forall a. Eq a => a -> BranchIdG a -> Bool
elem :: forall a. Eq a => a -> BranchIdG a -> Bool
$cmaximum :: forall a. Ord a => BranchIdG a -> a
maximum :: forall a. Ord a => BranchIdG a -> a
$cminimum :: forall a. Ord a => BranchIdG a -> a
minimum :: forall a. Ord a => BranchIdG a -> a
$csum :: forall a. Num a => BranchIdG a -> a
sum :: forall a. Num a => BranchIdG a -> a
$cproduct :: forall a. Num a => BranchIdG a -> a
product :: forall a. Num a => BranchIdG a -> a
Foldable, Functor BranchIdG
Foldable BranchIdG
(Functor BranchIdG, Foldable BranchIdG) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> BranchIdG a -> f (BranchIdG b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    BranchIdG (f a) -> f (BranchIdG a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> BranchIdG a -> m (BranchIdG b))
-> (forall (m :: * -> *) a.
    Monad m =>
    BranchIdG (m a) -> m (BranchIdG a))
-> Traversable BranchIdG
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
BranchIdG (m a) -> m (BranchIdG a)
forall (f :: * -> *) a.
Applicative f =>
BranchIdG (f a) -> f (BranchIdG a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> BranchIdG a -> m (BranchIdG b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> BranchIdG a -> f (BranchIdG b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> BranchIdG a -> f (BranchIdG b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> BranchIdG a -> f (BranchIdG b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
BranchIdG (f a) -> f (BranchIdG a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
BranchIdG (f a) -> f (BranchIdG a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> BranchIdG a -> m (BranchIdG b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> BranchIdG a -> m (BranchIdG b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
BranchIdG (m a) -> m (BranchIdG a)
sequence :: forall (m :: * -> *) a.
Monad m =>
BranchIdG (m a) -> m (BranchIdG a)
Traversable)

instance (From p Text) => From (BranchIdG p) Text where
  from :: BranchIdG p -> Text
from = \case
    BranchAtSCH ShortCausalHash
h -> Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ShortCausalHash -> Text
SCH.toText ShortCausalHash
h
    BranchAtPath p
p -> p -> Text
forall source target. From source target => source -> target
from p
p
    BranchAtProjectPath ProjectPath
pp -> ProjectPath -> Text
forall source target. From source target => source -> target
from ProjectPath
pp

type BranchId = BranchIdG Path'

type BranchId2 = Either ShortCausalHash BranchRelativePath

type AbsBranchId = BranchIdG Path.Absolute

-- | An unambiguous project branch name, use the current project name if not provided.
type UnresolvedProjectBranch = ProjectAndBranch (Maybe ProjectName) ProjectBranchName

type HashOrHQSplit' = Either ShortHash Path.HQSplit'

-- | Should we force the operation or not?
data Insistence = Force | Try
  deriving (Int -> Insistence -> ShowS
[Insistence] -> ShowS
Insistence -> String
(Int -> Insistence -> ShowS)
-> (Insistence -> String)
-> ([Insistence] -> ShowS)
-> Show Insistence
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Insistence -> ShowS
showsPrec :: Int -> Insistence -> ShowS
$cshow :: Insistence -> String
show :: Insistence -> String
$cshowList :: [Insistence] -> ShowS
showList :: [Insistence] -> ShowS
Show, Insistence -> Insistence -> Bool
(Insistence -> Insistence -> Bool)
-> (Insistence -> Insistence -> Bool) -> Eq Insistence
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Insistence -> Insistence -> Bool
== :: Insistence -> Insistence -> Bool
$c/= :: Insistence -> Insistence -> Bool
/= :: Insistence -> Insistence -> Bool
Eq)

parseBranchId :: String -> Either Text BranchId
parseBranchId :: String -> Either Text BranchId
parseBranchId (Char
'#' : String
s) = case Text -> Maybe ShortCausalHash
SCH.fromText (String -> Text
Text.pack String
s) of
  Maybe ShortCausalHash
Nothing -> Text -> Either Text BranchId
forall a b. a -> Either a b
Left Text
"Invalid hash, expected a base32hex string."
  Just ShortCausalHash
h -> BranchId -> Either Text BranchId
forall a. a -> Either Text a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BranchId -> Either Text BranchId)
-> BranchId -> Either Text BranchId
forall a b. (a -> b) -> a -> b
$ ShortCausalHash -> BranchId
forall p. ShortCausalHash -> BranchIdG p
BranchAtSCH ShortCausalHash
h
parseBranchId String
s = Path' -> BranchId
forall p. p -> BranchIdG p
BranchAtPath (Path' -> BranchId) -> Either Text Path' -> Either Text BranchId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Either Text Path'
Path.parsePath' String
s

parseBranchId2 :: String -> Either (P.Pretty P.ColorText) (Either ShortCausalHash BranchRelativePath)
parseBranchId2 :: String
-> Either
     (Pretty ColorText) (Either ShortCausalHash BranchRelativePath)
parseBranchId2 (Char
'#' : String
s) = case Text -> Maybe ShortCausalHash
SCH.fromText (String -> Text
Text.pack String
s) of
  Maybe ShortCausalHash
Nothing -> Pretty ColorText
-> Either
     (Pretty ColorText) (Either ShortCausalHash BranchRelativePath)
forall a b. a -> Either a b
Left Pretty ColorText
"Invalid hash, expected a base32hex string."
  Just ShortCausalHash
h -> Either ShortCausalHash BranchRelativePath
-> Either
     (Pretty ColorText) (Either ShortCausalHash BranchRelativePath)
forall a b. b -> Either a b
Right (ShortCausalHash -> Either ShortCausalHash BranchRelativePath
forall a b. a -> Either a b
Left ShortCausalHash
h)
parseBranchId2 String
s = BranchRelativePath -> Either ShortCausalHash BranchRelativePath
forall a b. b -> Either a b
Right (BranchRelativePath -> Either ShortCausalHash BranchRelativePath)
-> Either (Pretty ColorText) BranchRelativePath
-> Either
     (Pretty ColorText) (Either ShortCausalHash BranchRelativePath)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Either (Pretty ColorText) BranchRelativePath
parseBranchRelativePath String
s

parseShortCausalHash :: String -> Either String ShortCausalHash
parseShortCausalHash :: String -> Either String ShortCausalHash
parseShortCausalHash (Char
'#' : String
s) | Just ShortCausalHash
sch <- Text -> Maybe ShortCausalHash
SCH.fromText (String -> Text
Text.pack String
s) = ShortCausalHash -> Either String ShortCausalHash
forall a b. b -> Either a b
Right ShortCausalHash
sch
parseShortCausalHash String
_ = String -> Either String ShortCausalHash
forall a b. a -> Either a b
Left String
"Invalid hash, expected a base32hex string."

data PullMode
  = PullWithHistory
  | PullWithoutHistory
  deriving (PullMode -> PullMode -> Bool
(PullMode -> PullMode -> Bool)
-> (PullMode -> PullMode -> Bool) -> Eq PullMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PullMode -> PullMode -> Bool
== :: PullMode -> PullMode -> Bool
$c/= :: PullMode -> PullMode -> Bool
/= :: PullMode -> PullMode -> Bool
Eq, Int -> PullMode -> ShowS
[PullMode] -> ShowS
PullMode -> String
(Int -> PullMode -> ShowS)
-> (PullMode -> String) -> ([PullMode] -> ShowS) -> Show PullMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PullMode -> ShowS
showsPrec :: Int -> PullMode -> ShowS
$cshow :: PullMode -> String
show :: PullMode -> String
$cshowList :: [PullMode] -> ShowS
showList :: [PullMode] -> ShowS
Show)

type IsGlobal = Bool

data Input
  = -- names stuff:
    -- directory ops
    -- `Link` must describe a repo and a source path within that repo.
    -- clone w/o merge, error if would clobber
    ForkLocalBranchI (Either ShortCausalHash BranchRelativePath) BranchRelativePath
  | -- merge first causal into destination
    MergeLocalBranchI BranchRelativePath (Maybe BranchRelativePath) Branch.MergeMode
  | PreviewMergeLocalBranchI BranchRelativePath (Maybe BranchRelativePath)
  | DiffNamespaceI BranchId2 BranchId2 -- old new
  | PullI !PullSourceTarget !PullMode
  | PushRemoteBranchI PushRemoteBranchInput
  | ResetI (BranchId2 {- namespace to reset it to -}) (Maybe UnresolvedProjectBranch {- ProjectBranch to reset -})
  -- todo: Q: Does it make sense to publish to not-the-root of a Github repo?
  | --          Does it make sense to fork from not-the-root of a Github repo?
    -- used in Welcome module to give directions to user
    CreateMessage (P.Pretty P.ColorText)
  | -- Change directory.
    SwitchBranchI Path'
  | UpI
  | PopBranchI
  | -- > names foo
    -- > names foo.bar
    -- > names .foo.bar
    -- > names .foo.bar#asdflkjsdf
    -- > names #sdflkjsdfhsdf
    NamesI IsGlobal (HQ.HashQualified Name)
  | AliasTermI !Bool HashOrHQSplit' Path.Split' -- bool = force?
  | AliasTypeI !Bool HashOrHQSplit' Path.Split' -- bool = force?
  | AliasManyI [Path.HQSplit] Path'
  | MoveAllI Path.Path' Path.Path'
  | -- Move = Rename; It's an HQSplit' not an HQSplit', meaning the arg has to have a name.
    MoveTermI Path.HQSplit' Path.Split'
  | MoveTypeI Path.HQSplit' Path.Split'
  | MoveBranchI Path.Path' Path.Path'
  | -- delete = unname
    DeleteI DeleteTarget
  | -- edits stuff:
    LoadI (Maybe FilePath)
  | ClearI
  | AddI (Set Name)
  | PreviewAddI (Set Name)
  | UpdateI OptionalPatch (Set Name)
  | Update2I
  | PreviewUpdateI (Set Name)
  | TodoI
  | UndoI
  | -- First `Maybe Int` is cap on number of results, if any
    -- Second `Maybe Int` is cap on diff elements shown, if any
    HistoryI (Maybe Int) (Maybe Int) BranchId
  | -- execute an IO thunk with args
    ExecuteI (HQ.HashQualified Name) [String]
  | -- save the result of a previous Execute
    SaveExecuteResultI Name
  | -- execute an IO [Result]
    IOTestI (HQ.HashQualified Name)
  | -- execute all in-scope IO tests
    IOTestAllI
  | -- make a standalone binary file
    MakeStandaloneI String (HQ.HashQualified Name)
  | -- execute an IO thunk using scheme
    ExecuteSchemeI (HQ.HashQualified Name) [String]
  | -- compile to a scheme file; profiling flag
    CompileSchemeI Bool Text (HQ.HashQualified Name)
  | TestI TestInput
  | CreateAuthorI NameSegment {- identifier -} Text {- name -}
  | -- Display provided definitions.
    DisplayI OutputLocation (NonEmpty (HQ.HashQualified Name))
  | -- Display docs for provided terms.
    DocsI (NonEmpty Name)
  | -- other
    FindI Bool FindScope [String] -- FindI isVerbose findScope query
  | FindShallowI Path'
  | StructuredFindI FindScope (HQ.HashQualified Name) -- sfind findScope query
  | StructuredFindReplaceI (HQ.HashQualified Name) -- sfind.replace rewriteQuery
  | TextFindI Bool [String] -- TextFindI allowLib tokens
  | -- Show provided definitions.
    ShowDefinitionI OutputLocation ShowDefinitionScope (NonEmpty (HQ.HashQualified Name))
  | ShowRootReflogI {- Deprecated -}
  | ShowGlobalReflogI
  | ShowProjectReflogI (Maybe ProjectName)
  | ShowProjectBranchReflogI (Maybe (ProjectAndBranch (Maybe ProjectName) ProjectBranchName))
  | UpdateBuiltinsI
  | MergeBuiltinsI (Maybe Path)
  | MergeIOBuiltinsI (Maybe Path)
  | ListDependenciesI (HQ.HashQualified Name)
  | ListDependentsI (HQ.HashQualified Name)
  | -- | List all external dependencies of a given namespace, or the current namespace if
    -- no path is provided.
    NamespaceDependenciesI (Maybe Path')
  | DebugTabCompletionI [String] -- The raw arguments provided
  | DebugLSPNameCompletionI Text -- The raw arguments provided
  | DebugFuzzyOptionsI String [String] -- cmd and arguments
  | DebugFormatI
  | DebugNumberedArgsI
  | DebugTypecheckedUnisonFileI
  | DebugDumpNamespacesI
  | DebugDumpNamespaceSimpleI
  | DebugTermI (Bool {- Verbose mode -}) (HQ.HashQualified Name)
  | DebugTypeI (HQ.HashQualified Name)
  | DebugLSPFoldRangesI
  | DebugClearWatchI
  | DebugDoctorI
  | DebugNameDiffI ShortCausalHash ShortCausalHash
  | QuitI
  | ApiI
  | UiI Path'
  | DocToMarkdownI Name
  | DocsToHtmlI BranchRelativePath FilePath
  | AuthLoginI
  | VersionI
  | ProjectCreateI Bool {- try downloading base? -} (Maybe ProjectName)
  | ProjectRenameI ProjectName
  | ProjectSwitchI ProjectAndBranchNames
  | ProjectsI
  | BranchI BranchSourceI (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
  | BranchRenameI ProjectBranchName
  | BranchesI (Maybe ProjectName)
  | CloneI ProjectAndBranchNames (Maybe ProjectAndBranchNames)
  | ReleaseDraftI Semver
  | UpgradeI !NameSegment !NameSegment
  | EditNamespaceI [Path.Path]
  | -- New merge algorithm: merge the given project branch into the current one.
    MergeI (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
  | LibInstallI
      !Bool -- Remind the user to use `lib.install` next time, not `pull`?
      !(ProjectAndBranch ProjectName (Maybe ProjectBranchNameOrLatestRelease))
  | UpgradeCommitI
  | MergeCommitI
  | DebugSynhashTermI !Name
  deriving (Input -> Input -> Bool
(Input -> Input -> Bool) -> (Input -> Input -> Bool) -> Eq Input
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Input -> Input -> Bool
== :: Input -> Input -> Bool
$c/= :: Input -> Input -> Bool
/= :: Input -> Input -> Bool
Eq, Int -> Input -> ShowS
[Input] -> ShowS
Input -> String
(Int -> Input -> ShowS)
-> (Input -> String) -> ([Input] -> ShowS) -> Show Input
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Input -> ShowS
showsPrec :: Int -> Input -> ShowS
$cshow :: Input -> String
show :: Input -> String
$cshowList :: [Input] -> ShowS
showList :: [Input] -> ShowS
Show)

-- | The source of a `branch` command: what to make the new branch from.
data BranchSourceI
  = -- | Create a branch from the current context
    BranchSourceI'CurrentContext
  | -- | Create an empty branch
    BranchSourceI'Empty
  | -- | Create a branch from this other branch
    BranchSourceI'UnresolvedProjectBranch UnresolvedProjectBranch
  deriving stock (BranchSourceI -> BranchSourceI -> Bool
(BranchSourceI -> BranchSourceI -> Bool)
-> (BranchSourceI -> BranchSourceI -> Bool) -> Eq BranchSourceI
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BranchSourceI -> BranchSourceI -> Bool
== :: BranchSourceI -> BranchSourceI -> Bool
$c/= :: BranchSourceI -> BranchSourceI -> Bool
/= :: BranchSourceI -> BranchSourceI -> Bool
Eq, Int -> BranchSourceI -> ShowS
[BranchSourceI] -> ShowS
BranchSourceI -> String
(Int -> BranchSourceI -> ShowS)
-> (BranchSourceI -> String)
-> ([BranchSourceI] -> ShowS)
-> Show BranchSourceI
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BranchSourceI -> ShowS
showsPrec :: Int -> BranchSourceI -> ShowS
$cshow :: BranchSourceI -> String
show :: BranchSourceI -> String
$cshowList :: [BranchSourceI] -> ShowS
showList :: [BranchSourceI] -> ShowS
Show)

-- | Pull source and target: either neither is specified, or only a source, or both.
data PullSourceTarget
  = PullSourceTarget0
  | PullSourceTarget1 (ReadRemoteNamespace (These ProjectName ProjectBranchNameOrLatestRelease))
  | PullSourceTarget2 (ReadRemoteNamespace (These ProjectName ProjectBranchNameOrLatestRelease)) (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
  deriving stock (PullSourceTarget -> PullSourceTarget -> Bool
(PullSourceTarget -> PullSourceTarget -> Bool)
-> (PullSourceTarget -> PullSourceTarget -> Bool)
-> Eq PullSourceTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PullSourceTarget -> PullSourceTarget -> Bool
== :: PullSourceTarget -> PullSourceTarget -> Bool
$c/= :: PullSourceTarget -> PullSourceTarget -> Bool
/= :: PullSourceTarget -> PullSourceTarget -> Bool
Eq, Int -> PullSourceTarget -> ShowS
[PullSourceTarget] -> ShowS
PullSourceTarget -> String
(Int -> PullSourceTarget -> ShowS)
-> (PullSourceTarget -> String)
-> ([PullSourceTarget] -> ShowS)
-> Show PullSourceTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PullSourceTarget -> ShowS
showsPrec :: Int -> PullSourceTarget -> ShowS
$cshow :: PullSourceTarget -> String
show :: PullSourceTarget -> String
$cshowList :: [PullSourceTarget] -> ShowS
showList :: [PullSourceTarget] -> ShowS
Show)

data PushSource
  = ProjySource (These ProjectName ProjectBranchName)
  deriving stock (PushSource -> PushSource -> Bool
(PushSource -> PushSource -> Bool)
-> (PushSource -> PushSource -> Bool) -> Eq PushSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PushSource -> PushSource -> Bool
== :: PushSource -> PushSource -> Bool
$c/= :: PushSource -> PushSource -> Bool
/= :: PushSource -> PushSource -> Bool
Eq, Int -> PushSource -> ShowS
[PushSource] -> ShowS
PushSource -> String
(Int -> PushSource -> ShowS)
-> (PushSource -> String)
-> ([PushSource] -> ShowS)
-> Show PushSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PushSource -> ShowS
showsPrec :: Int -> PushSource -> ShowS
$cshow :: PushSource -> String
show :: PushSource -> String
$cshowList :: [PushSource] -> ShowS
showList :: [PushSource] -> ShowS
Show)

-- | Push source and target: either neither is specified, or only a target, or both.
data PushSourceTarget
  = PushSourceTarget0
  | PushSourceTarget1 (These ProjectName ProjectBranchName)
  | PushSourceTarget2 PushSource (These ProjectName ProjectBranchName)
  deriving stock (PushSourceTarget -> PushSourceTarget -> Bool
(PushSourceTarget -> PushSourceTarget -> Bool)
-> (PushSourceTarget -> PushSourceTarget -> Bool)
-> Eq PushSourceTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PushSourceTarget -> PushSourceTarget -> Bool
== :: PushSourceTarget -> PushSourceTarget -> Bool
$c/= :: PushSourceTarget -> PushSourceTarget -> Bool
/= :: PushSourceTarget -> PushSourceTarget -> Bool
Eq, Int -> PushSourceTarget -> ShowS
[PushSourceTarget] -> ShowS
PushSourceTarget -> String
(Int -> PushSourceTarget -> ShowS)
-> (PushSourceTarget -> String)
-> ([PushSourceTarget] -> ShowS)
-> Show PushSourceTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PushSourceTarget -> ShowS
showsPrec :: Int -> PushSourceTarget -> ShowS
$cshow :: PushSourceTarget -> String
show :: PushSourceTarget -> String
$cshowList :: [PushSourceTarget] -> ShowS
showList :: [PushSourceTarget] -> ShowS
Show)

data PushRemoteBranchInput = PushRemoteBranchInput
  { PushRemoteBranchInput -> PushSourceTarget
sourceTarget :: PushSourceTarget,
    PushRemoteBranchInput -> PushBehavior
pushBehavior :: PushBehavior
  }
  deriving stock (PushRemoteBranchInput -> PushRemoteBranchInput -> Bool
(PushRemoteBranchInput -> PushRemoteBranchInput -> Bool)
-> (PushRemoteBranchInput -> PushRemoteBranchInput -> Bool)
-> Eq PushRemoteBranchInput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PushRemoteBranchInput -> PushRemoteBranchInput -> Bool
== :: PushRemoteBranchInput -> PushRemoteBranchInput -> Bool
$c/= :: PushRemoteBranchInput -> PushRemoteBranchInput -> Bool
/= :: PushRemoteBranchInput -> PushRemoteBranchInput -> Bool
Eq, Int -> PushRemoteBranchInput -> ShowS
[PushRemoteBranchInput] -> ShowS
PushRemoteBranchInput -> String
(Int -> PushRemoteBranchInput -> ShowS)
-> (PushRemoteBranchInput -> String)
-> ([PushRemoteBranchInput] -> ShowS)
-> Show PushRemoteBranchInput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PushRemoteBranchInput -> ShowS
showsPrec :: Int -> PushRemoteBranchInput -> ShowS
$cshow :: PushRemoteBranchInput -> String
show :: PushRemoteBranchInput -> String
$cshowList :: [PushRemoteBranchInput] -> ShowS
showList :: [PushRemoteBranchInput] -> ShowS
Show)

data TestInput = TestInput
  { -- | Should we run tests in the `lib` namespace?
    TestInput -> Bool
includeLibNamespace :: Bool,
    -- | Relative path to run the tests in. Ignore if `includeLibNamespace` is True - that means test everything.
    TestInput -> Path
path :: Path,
    TestInput -> Bool
showFailures :: Bool,
    TestInput -> Bool
showSuccesses :: Bool
  }
  deriving stock (TestInput -> TestInput -> Bool
(TestInput -> TestInput -> Bool)
-> (TestInput -> TestInput -> Bool) -> Eq TestInput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestInput -> TestInput -> Bool
== :: TestInput -> TestInput -> Bool
$c/= :: TestInput -> TestInput -> Bool
/= :: TestInput -> TestInput -> Bool
Eq, Int -> TestInput -> ShowS
[TestInput] -> ShowS
TestInput -> String
(Int -> TestInput -> ShowS)
-> (TestInput -> String)
-> ([TestInput] -> ShowS)
-> Show TestInput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestInput -> ShowS
showsPrec :: Int -> TestInput -> ShowS
$cshow :: TestInput -> String
show :: TestInput -> String
$cshowList :: [TestInput] -> ShowS
showList :: [TestInput] -> ShowS
Show)

-- Some commands, like `view`, can dump output to either console or a file.
data OutputLocation
  = ConsoleLocation
  | LatestFileLocation
  | FileLocation FilePath
  -- ClipboardLocation
  deriving (OutputLocation -> OutputLocation -> Bool
(OutputLocation -> OutputLocation -> Bool)
-> (OutputLocation -> OutputLocation -> Bool) -> Eq OutputLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OutputLocation -> OutputLocation -> Bool
== :: OutputLocation -> OutputLocation -> Bool
$c/= :: OutputLocation -> OutputLocation -> Bool
/= :: OutputLocation -> OutputLocation -> Bool
Eq, Int -> OutputLocation -> ShowS
[OutputLocation] -> ShowS
OutputLocation -> String
(Int -> OutputLocation -> ShowS)
-> (OutputLocation -> String)
-> ([OutputLocation] -> ShowS)
-> Show OutputLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OutputLocation -> ShowS
showsPrec :: Int -> OutputLocation -> ShowS
$cshow :: OutputLocation -> String
show :: OutputLocation -> String
$cshowList :: [OutputLocation] -> ShowS
showList :: [OutputLocation] -> ShowS
Show)

data FindScope
  = FindLocal Path'
  | FindLocalAndDeps Path'
  | FindGlobal
  deriving stock (FindScope -> FindScope -> Bool
(FindScope -> FindScope -> Bool)
-> (FindScope -> FindScope -> Bool) -> Eq FindScope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FindScope -> FindScope -> Bool
== :: FindScope -> FindScope -> Bool
$c/= :: FindScope -> FindScope -> Bool
/= :: FindScope -> FindScope -> Bool
Eq, Int -> FindScope -> ShowS
[FindScope] -> ShowS
FindScope -> String
(Int -> FindScope -> ShowS)
-> (FindScope -> String)
-> ([FindScope] -> ShowS)
-> Show FindScope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FindScope -> ShowS
showsPrec :: Int -> FindScope -> ShowS
$cshow :: FindScope -> String
show :: FindScope -> String
$cshowList :: [FindScope] -> ShowS
showList :: [FindScope] -> ShowS
Show)

data ShowDefinitionScope
  = ShowDefinitionLocal
  | ShowDefinitionGlobal
  deriving stock (ShowDefinitionScope -> ShowDefinitionScope -> Bool
(ShowDefinitionScope -> ShowDefinitionScope -> Bool)
-> (ShowDefinitionScope -> ShowDefinitionScope -> Bool)
-> Eq ShowDefinitionScope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShowDefinitionScope -> ShowDefinitionScope -> Bool
== :: ShowDefinitionScope -> ShowDefinitionScope -> Bool
$c/= :: ShowDefinitionScope -> ShowDefinitionScope -> Bool
/= :: ShowDefinitionScope -> ShowDefinitionScope -> Bool
Eq, Int -> ShowDefinitionScope -> ShowS
[ShowDefinitionScope] -> ShowS
ShowDefinitionScope -> String
(Int -> ShowDefinitionScope -> ShowS)
-> (ShowDefinitionScope -> String)
-> ([ShowDefinitionScope] -> ShowS)
-> Show ShowDefinitionScope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShowDefinitionScope -> ShowS
showsPrec :: Int -> ShowDefinitionScope -> ShowS
$cshow :: ShowDefinitionScope -> String
show :: ShowDefinitionScope -> String
$cshowList :: [ShowDefinitionScope] -> ShowS
showList :: [ShowDefinitionScope] -> ShowS
Show)

data DeleteOutput
  = DeleteOutput'Diff
  | DeleteOutput'NoDiff
  deriving stock (DeleteOutput -> DeleteOutput -> Bool
(DeleteOutput -> DeleteOutput -> Bool)
-> (DeleteOutput -> DeleteOutput -> Bool) -> Eq DeleteOutput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DeleteOutput -> DeleteOutput -> Bool
== :: DeleteOutput -> DeleteOutput -> Bool
$c/= :: DeleteOutput -> DeleteOutput -> Bool
/= :: DeleteOutput -> DeleteOutput -> Bool
Eq, Int -> DeleteOutput -> ShowS
[DeleteOutput] -> ShowS
DeleteOutput -> String
(Int -> DeleteOutput -> ShowS)
-> (DeleteOutput -> String)
-> ([DeleteOutput] -> ShowS)
-> Show DeleteOutput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteOutput -> ShowS
showsPrec :: Int -> DeleteOutput -> ShowS
$cshow :: DeleteOutput -> String
show :: DeleteOutput -> String
$cshowList :: [DeleteOutput] -> ShowS
showList :: [DeleteOutput] -> ShowS
Show)

data DeleteTarget
  = DeleteTarget'TermOrType DeleteOutput [Path.HQSplit']
  | DeleteTarget'Term DeleteOutput [Path.HQSplit']
  | DeleteTarget'Type DeleteOutput [Path.HQSplit']
  | DeleteTarget'Namespace Insistence (Maybe Path.Split)
  | DeleteTarget'ProjectBranch (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
  | DeleteTarget'Project ProjectName
  deriving stock (DeleteTarget -> DeleteTarget -> Bool
(DeleteTarget -> DeleteTarget -> Bool)
-> (DeleteTarget -> DeleteTarget -> Bool) -> Eq DeleteTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DeleteTarget -> DeleteTarget -> Bool
== :: DeleteTarget -> DeleteTarget -> Bool
$c/= :: DeleteTarget -> DeleteTarget -> Bool
/= :: DeleteTarget -> DeleteTarget -> Bool
Eq, Int -> DeleteTarget -> ShowS
[DeleteTarget] -> ShowS
DeleteTarget -> String
(Int -> DeleteTarget -> ShowS)
-> (DeleteTarget -> String)
-> ([DeleteTarget] -> ShowS)
-> Show DeleteTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteTarget -> ShowS
showsPrec :: Int -> DeleteTarget -> ShowS
$cshow :: DeleteTarget -> String
show :: DeleteTarget -> String
$cshowList :: [DeleteTarget] -> ShowS
showList :: [DeleteTarget] -> ShowS
Show)