Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick fix for delete.type #4315 for next steps #4342

Merged
merged 5 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions unison-cli/src/Unison/CommandLine/InputPatterns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -717,7 +717,7 @@ deleteGen suffix target mkTarget =
cmd
[]
I.Visible
[(OnePlus, exactDefinitionTermQueryArg)]
[(OnePlus, queryCompletionArg)]
info
( \case
[] -> Left . P.warnCallout $ P.wrap warn
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions unison-src/transcripts/tab-completion.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Tab Completion


Test that tab completion works as expected.


## Tab Complete Command Names

```ucm
Expand Down Expand Up @@ -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
```
40 changes: 38 additions & 2 deletions unison-src/transcripts/tab-completion.output.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Tab Completion


Test that tab completion works as expected.


## Tab Complete Command Names

```ucm
Expand Down Expand Up @@ -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

```