From 54e9056d3ece5a94f517c9517cc121b2eccc963c Mon Sep 17 00:00:00 2001 From: sixfourtwelve Date: Mon, 9 Oct 2023 20:59:01 +0100 Subject: [PATCH 1/5] quick fix for delete.type #4315 for next steps --- .../src/Unison/CommandLine/InputPatterns.hs | 18 ++++----- unison-src/transcripts/tab-completion.md | 16 +++++++- .../transcripts/tab-completion.output.md | 40 ++++++++++++++++++- 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index 4537bfedf3..c48282353e 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 exactDefinitionTermQueryArg "term or type" (DeleteTarget'TermOrType DeleteOutput'NoDiff) deleteVerbose :: InputPattern -deleteVerbose = deleteGen (Just "verbose") "term or type" (DeleteTarget'TermOrType DeleteOutput'Diff) +deleteVerbose = deleteGen (Just "verbose") exactDefinitionArg "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" diff --git a/unison-src/transcripts/tab-completion.md b/unison-src/transcripts/tab-completion.md index 08b3c8f0bd..13ba5f955a 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.type add +``` diff --git a/unison-src/transcripts/tab-completion.output.md b/unison-src/transcripts/tab-completion.output.md index f7dc865e63..78086c39b9 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 @@ -134,4 +132,42 @@ unique type subnamespace.AType = A | B * subnamespace.someName * 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.type add + + + ``` From f4f9670fbc9740a8a9a1f045bb8a13cf48529be2 Mon Sep 17 00:00:00 2001 From: sixfourtwelve Date: Mon, 9 Oct 2023 21:04:55 +0100 Subject: [PATCH 2/5] change subcommand --- unison-src/transcripts/tab-completion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unison-src/transcripts/tab-completion.md b/unison-src/transcripts/tab-completion.md index 13ba5f955a..8075887b3c 100644 --- a/unison-src/transcripts/tab-completion.md +++ b/unison-src/transcripts/tab-completion.md @@ -63,5 +63,5 @@ add b = b ```ucm .> update .> debug.tab-complete delete.type Foo -.> debug.tab-complete delete.type add +.> debug.tab-complete delete.term add ``` From ab1a39e613a8011ab9fc4ab5a35991207b40b54c Mon Sep 17 00:00:00 2001 From: sixfourtwelve Date: Tue, 10 Oct 2023 07:19:09 +0100 Subject: [PATCH 3/5] update query args and push up transcript output --- unison-cli/src/Unison/CommandLine/InputPatterns.hs | 14 +++++++++++--- unison-src/transcripts/tab-completion.output.md | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index c48282353e..5e550e22e0 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -730,7 +730,7 @@ delete :: InputPattern delete = deleteGen Nothing exactDefinitionTermQueryArg "term or type" (DeleteTarget'TermOrType DeleteOutput'NoDiff) deleteVerbose :: InputPattern -deleteVerbose = deleteGen (Just "verbose") exactDefinitionArg "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") exactDefinitionTermQueryArg "term" (DeleteTarget'Term DeleteOutput'NoDiff) @@ -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 @@ -3097,7 +3105,7 @@ projectAndBranchNamesArg includeCurrentBranch = } where handleAmbiguousComplete :: - MonadIO m => + (MonadIO m) => Text -> Codebase m v a -> Path.Absolute -> @@ -3184,7 +3192,7 @@ projectAndBranchNamesArg includeCurrentBranch = then projectCompletions else branchCompletions ++ projectCompletions - handleBranchesComplete :: MonadIO m => Text -> Codebase m v a -> Path.Absolute -> m [Completion] + handleBranchesComplete :: (MonadIO m) => Text -> Codebase m v a -> Path.Absolute -> m [Completion] handleBranchesComplete branchName codebase path = do branches <- case preview ProjectUtils.projectBranchPathPrism path of diff --git a/unison-src/transcripts/tab-completion.output.md b/unison-src/transcripts/tab-completion.output.md index 78086c39b9..cf09b229fb 100644 --- a/unison-src/transcripts/tab-completion.output.md +++ b/unison-src/transcripts/tab-completion.output.md @@ -166,8 +166,8 @@ add b = b * Foo Foo. -.> debug.tab-complete delete.type add +.> debug.tab-complete delete.term add - + * add ``` From a802da17ff6fd84e646723a2628add91aa90f32e Mon Sep 17 00:00:00 2001 From: sixfourtwelve Date: Tue, 10 Oct 2023 07:19:59 +0100 Subject: [PATCH 4/5] update query args and push up transcript output --- unison-cli/src/Unison/CommandLine/InputPatterns.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index 5e550e22e0..d64733a960 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -727,7 +727,7 @@ deleteGen suffix queryCompletionArg target mkTarget = ) delete :: InputPattern -delete = deleteGen Nothing exactDefinitionTermQueryArg "term or type" (DeleteTarget'TermOrType DeleteOutput'NoDiff) +delete = deleteGen Nothing exactDefinitionTypeOrTermQueryArg "term or type" (DeleteTarget'TermOrType DeleteOutput'NoDiff) deleteVerbose :: InputPattern deleteVerbose = deleteGen (Just "verbose") exactDefinitionTypeOrTermQueryArg "term or type" (DeleteTarget'TermOrType DeleteOutput'Diff) From 252dbed6d6888261ff1652f62cb4b7ae816432dc Mon Sep 17 00:00:00 2001 From: sixfourtwelve Date: Tue, 10 Oct 2023 07:21:27 +0100 Subject: [PATCH 5/5] fix autosave format --- unison-cli/src/Unison/CommandLine/InputPatterns.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index d64733a960..c278217b32 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -3105,7 +3105,7 @@ projectAndBranchNamesArg includeCurrentBranch = } where handleAmbiguousComplete :: - (MonadIO m) => + MonadIO m => Text -> Codebase m v a -> Path.Absolute -> @@ -3192,7 +3192,7 @@ projectAndBranchNamesArg includeCurrentBranch = then projectCompletions else branchCompletions ++ projectCompletions - handleBranchesComplete :: (MonadIO m) => Text -> Codebase m v a -> Path.Absolute -> m [Completion] + handleBranchesComplete :: MonadIO m => Text -> Codebase m v a -> Path.Absolute -> m [Completion] handleBranchesComplete branchName codebase path = do branches <- case preview ProjectUtils.projectBranchPathPrism path of