diff --git a/unison-cli/src/Unison/CommandLine/FZFResolvers.hs b/unison-cli/src/Unison/CommandLine/FZFResolvers.hs index b1cb9ac863..495025f3f2 100644 --- a/unison-cli/src/Unison/CommandLine/FZFResolvers.hs +++ b/unison-cli/src/Unison/CommandLine/FZFResolvers.hs @@ -4,6 +4,7 @@ module Unison.CommandLine.FZFResolvers termDefinitionOptions, typeDefinitionOptions, namespaceOptions, + projectDependencyResolver, projectNameOptions, projectBranchOptions, projectBranchOptionsWithinCurrentProject, @@ -24,6 +25,7 @@ where import Control.Lens import Data.List.Extra qualified as List +import Data.Map qualified as Map import Data.Set qualified as Set import Data.Text qualified as Text import U.Codebase.Sqlite.Project as SqliteProject @@ -35,6 +37,7 @@ import Unison.Codebase.Branch qualified as Branch import Unison.Codebase.Path (Path, Path' (..)) import Unison.Codebase.Path qualified as Path import Unison.Name qualified as Name +import Unison.NameSegment qualified as NameSegment import Unison.Names qualified as Names import Unison.Parser.Ann (Ann) import Unison.Position qualified as Position @@ -94,6 +97,19 @@ namespaceOptions _codebase _projCtx searchBranch0 = do & map (Path.toText' . intoPath') & pure +-- | Lists all dependencies of the current project. +-- +-- E.g. if the current project has `lib.base` and `lib.distributed`, it will list: +-- ["base", "distributed"] +projectDependencyOptions :: OptionFetcher +projectDependencyOptions _codebase _projCtx searchBranch0 = do + searchBranch0 + & Branch.getAt0 (Path.singleton Name.libSegment) + & Branch.nonEmptyChildren + & Map.keys + & fmap NameSegment.toText + & pure + -- | Select a namespace from the given branch. -- Returned Path's will match the provided 'Position' type. fuzzySelectFromList :: [Text] -> FZFResolver @@ -123,6 +139,9 @@ namespaceResolver = FZFResolver {getOptions = namespaceOptions} namespaceOrDefinitionResolver :: FZFResolver namespaceOrDefinitionResolver = multiResolver [definitionOptions, namespaceOptions] +projectDependencyResolver :: FZFResolver +projectDependencyResolver = FZFResolver {getOptions = projectDependencyOptions} + -- | A project name, branch name, or both. projectAndOrBranchArg :: FZFResolver projectAndOrBranchArg = multiResolver [projectBranchOptions, projectNameOptions] diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index f3f04c28a4..2afaa9f601 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -3006,7 +3006,7 @@ upgrade = { patternName = "upgrade", aliases = [], visibility = I.Visible, - args = [], + args = [("dependency to upgrade", Required, dependencyArg), ("dependency to upgrade to", Required, dependencyArg)], help = P.wrap $ "`upgrade old new` upgrades library dependency `lib.old` to `lib.new`, and, if successful, deletes `lib.old`.", @@ -3267,6 +3267,17 @@ namespaceOrDefinitionArg = Just Resolvers.namespaceOrDefinitionResolver } +-- | A dependency name. E.g. if your project has `lib.base`, `base` would be a dependency +-- name. +dependencyArg :: ArgumentType +dependencyArg = + ArgumentType + { typeName = "project dependency", + suggestions = \q cb _http p -> Codebase.runTransaction cb do + prefixCompleteNamespace q (p Path.:> Name.libSegment), + fzfResolver = Just Resolvers.projectDependencyResolver + } + -- | Names of child branches of the branch, only gives options for one 'layer' deeper at a time. childNamespaceNames :: Branch.Branch0 m -> [Text] childNamespaceNames b = NameSegment.toText <$> Map.keys (Branch.nonEmptyChildren b) diff --git a/unison-src/transcripts/upgrade-happy-path.md b/unison-src/transcripts/upgrade-happy-path.md index f0ea141737..ef469408c9 100644 --- a/unison-src/transcripts/upgrade-happy-path.md +++ b/unison-src/transcripts/upgrade-happy-path.md @@ -10,8 +10,19 @@ lib.new.foo = 18 thingy = lib.old.foo + 10 ``` + ```ucm proj/main> add +``` + +Test tab completion and fzf options of upgrade command. +```ucm +proj/main> debug.tab-complete upgrade ol +proj/main> debug.fuzzy-options upgrade _ +proj/main> debug.fuzzy-options upgrade old _ +``` + +```ucm proj/main> upgrade old new proj/main> ls lib proj/main> view thingy diff --git a/unison-src/transcripts/upgrade-happy-path.output.md b/unison-src/transcripts/upgrade-happy-path.output.md index 3f3cf54ac6..94de6f3049 100644 --- a/unison-src/transcripts/upgrade-happy-path.output.md +++ b/unison-src/transcripts/upgrade-happy-path.output.md @@ -28,6 +28,29 @@ proj/main> add lib.old.foo : Nat thingy : Nat +``` +Test tab completion and fzf options of upgrade command. +```ucm +proj/main> debug.tab-complete upgrade ol + + old + +proj/main> debug.fuzzy-options upgrade _ + + Select a dependency to upgrade: + * builtin + * new + * old + +proj/main> debug.fuzzy-options upgrade old _ + + Select a dependency to upgrade to: + * builtin + * new + * old + +``` +```ucm proj/main> upgrade old new I upgraded old to new, and removed old.