diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index 4537bfedf3..c278217b32 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -682,8 +682,8 @@ renameType = "`rename.type` takes two arguments, like `rename.type oldname newname`." ) -deleteGen :: Maybe String -> String -> ([Path.HQSplit'] -> DeleteTarget) -> InputPattern -deleteGen suffix target mkTarget = +deleteGen :: Maybe String -> ArgumentType -> String -> ([Path.HQSplit'] -> DeleteTarget) -> InputPattern +deleteGen suffix queryCompletionArg target mkTarget = let cmd = maybe "delete" ("delete." <>) suffix info = P.wrapColumn2 @@ -717,7 +717,7 @@ deleteGen suffix target mkTarget = cmd [] I.Visible - [(OnePlus, exactDefinitionTermQueryArg)] + [(OnePlus, queryCompletionArg)] info ( \case [] -> Left . P.warnCallout $ P.wrap warn @@ -727,22 +727,22 @@ deleteGen suffix target mkTarget = ) delete :: InputPattern -delete = deleteGen Nothing "term or type" (DeleteTarget'TermOrType DeleteOutput'NoDiff) +delete = deleteGen Nothing exactDefinitionTypeOrTermQueryArg "term or type" (DeleteTarget'TermOrType DeleteOutput'NoDiff) deleteVerbose :: InputPattern -deleteVerbose = deleteGen (Just "verbose") "term or type" (DeleteTarget'TermOrType DeleteOutput'Diff) +deleteVerbose = deleteGen (Just "verbose") exactDefinitionTypeOrTermQueryArg "term or type" (DeleteTarget'TermOrType DeleteOutput'Diff) deleteTerm :: InputPattern -deleteTerm = deleteGen (Just "term") "term" (DeleteTarget'Term DeleteOutput'NoDiff) +deleteTerm = deleteGen (Just "term") exactDefinitionTermQueryArg "term" (DeleteTarget'Term DeleteOutput'NoDiff) deleteTermVerbose :: InputPattern -deleteTermVerbose = deleteGen (Just "term.verbose") "term" (DeleteTarget'Term DeleteOutput'Diff) +deleteTermVerbose = deleteGen (Just "term.verbose") exactDefinitionTermQueryArg "term" (DeleteTarget'Term DeleteOutput'Diff) deleteType :: InputPattern -deleteType = deleteGen (Just "type") "type" (DeleteTarget'Type DeleteOutput'NoDiff) +deleteType = deleteGen (Just "type") exactDefinitionTypeQueryArg "type" (DeleteTarget'Type DeleteOutput'NoDiff) deleteTypeVerbose :: InputPattern -deleteTypeVerbose = deleteGen (Just "type.verbose") "type" (DeleteTarget'Type DeleteOutput'Diff) +deleteTypeVerbose = deleteGen (Just "type.verbose") exactDefinitionTypeQueryArg "type" (DeleteTarget'Type DeleteOutput'Diff) deleteTermReplacementCommand :: String deleteTermReplacementCommand = "delete.term-replacement" @@ -2954,6 +2954,14 @@ exactDefinitionTypeQueryArg = globTargets = Set.fromList [Globbing.Type] } +exactDefinitionTypeOrTermQueryArg :: ArgumentType +exactDefinitionTypeOrTermQueryArg = + ArgumentType + { typeName = "type or term definition query", + suggestions = \q cb _http p -> Codebase.runTransaction cb (prefixCompleteTermOrType q p), + globTargets = Set.fromList [Globbing.Term] + } + exactDefinitionTermQueryArg :: ArgumentType exactDefinitionTermQueryArg = ArgumentType diff --git a/unison-src/transcripts/tab-completion.md b/unison-src/transcripts/tab-completion.md index 08b3c8f0bd..8075887b3c 100644 --- a/unison-src/transcripts/tab-completion.md +++ b/unison-src/transcripts/tab-completion.md @@ -1,9 +1,7 @@ # Tab Completion - Test that tab completion works as expected. - ## Tab Complete Command Names ```ucm @@ -53,3 +51,17 @@ unique type subnamespace.AType = A | B .> debug.tab-complete io.test subnamespace .> debug.tab-complete io.test subnamespace. ``` + +Tab Complete Delete Subcommands + +```unison +unique type Foo = A | B +add : a -> a +add b = b +``` + +```ucm +.> update +.> debug.tab-complete delete.type Foo +.> debug.tab-complete delete.term add +``` diff --git a/unison-src/transcripts/tab-completion.output.md b/unison-src/transcripts/tab-completion.output.md index f7dc865e63..cf09b229fb 100644 --- a/unison-src/transcripts/tab-completion.output.md +++ b/unison-src/transcripts/tab-completion.output.md @@ -1,9 +1,7 @@ # Tab Completion - Test that tab completion works as expected. - ## Tab Complete Command Names ```ucm @@ -135,3 +133,41 @@ unique type subnamespace.AType = A | B * subnamespace.someOtherName ``` +Tab Complete Delete Subcommands + +```unison +unique type Foo = A | B +add : a -> a +add b = b +``` + +```ucm + + I found and typechecked these definitions in scratch.u. If you + do an `add` or `update`, here's how your codebase would + change: + + ⍟ These new definitions are ok to `add`: + + unique type Foo + add : a -> a + +``` +```ucm +.> update + + ⍟ I've added these definitions: + + unique type Foo + add : a -> a + +.> debug.tab-complete delete.type Foo + + * Foo + Foo. + +.> debug.tab-complete delete.term add + + * add + +```