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

Improve error messages on un-resolvable fuzzy command invocations #4573

Merged
merged 10 commits into from Jan 4, 2024

Conversation

ChrisPenner
Copy link
Contributor

@ChrisPenner ChrisPenner commented Jan 4, 2024

Overview

For fuzzy finds with no options

Before

.empty> view
.empty>

After

.empty> view

⚠️

Sorry, I was expecting an argument for the definition to view, and I couldn't find any to suggest to you. 😅
.empty>

For fuzzy finds with no resolvers and a missing arg

Before:

.> move.term

<fzf select a term to rename, then since there's no resolver for the second arg, the command just fails and goes back to the prompt>

.> 

After:

.> move.term
`move.term foo bar` renames `foo` to `bar`.

Without this patch some command invocations can behave unintuitively, e.g. running move.term without any args will fuzzy search for the first arg, but then will silently not run anything because there's no fzf resolver for the new name argument which is required.

This changes it so we validate that we have resolvers for all required arguments before we actually invoke any of them.

It also will fail with a nice message if a fuzzy-finder is invoked but doesn't have any options to select from.

Implementation notes

  • Collect all the required fzf resolvers in one loop, then actually run them in a second loop so that we don't start fuzzy-finding unless we know we have resolvers for every argument we need them for.
  • Change the error handling for resolvers so we know why fuzzy resolve failed and print an error accordingly.
  • Change the transcript parser to accept argument parse errors as valid errors w/r to ucm:error
  • Adds argument names to every arg in InputPatterns so we can tell the user which arg they're selecting. These arg names may also be handy in the future for generating help messages or something like it.

Test coverage

Added a couple transcript cases

@ChrisPenner ChrisPenner marked this pull request as ready for review January 4, 2024 00:42
Base automatically changed from cp/fzf-args to trunk January 4, 2024 01:14
@@ -33,7 +53,7 @@ Definition args

.> debug.fuzzy-options view _

Select a definition:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately generic articles are complicated in English (a vs an), but I think things read okay without it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll be good to improve this at some point to be consistent with the minimally-robotic UCM message style, but not going to delay the PR.

@@ -9,6 +9,15 @@ module Unison.CommandLine.FZFResolvers
projectBranchOptionsWithinCurrentProject,
fuzzySelectFromList,
multiResolver,
definitionResolver,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we don't need custom arg descriptions in each resolver, we can just export the whole resolver type :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ormolu

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ormolu

@@ -358,7 +358,14 @@ run verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion
let getRoot = fmap Branch.head . atomically $ readTMVar rootVar
liftIO (parseInput codebase getRoot curPath numberedArgs patternMap args) >>= \case
-- invalid command is treated as a failure
Left msg -> liftIO (dieWithMsg $ Pretty.toPlain terminalWidth msg)
Left msg -> do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously a failure in argument parsing would crash the transcript even if inside a ucm:error block, now it prints the error the output but proceeds if it was an expected error.

@@ -38,48 +47,44 @@ import Unison.Util.Relation qualified as Relation
type OptionFetcher = Codebase IO Symbol Ann -> ProjectContext -> Branch0 IO -> IO [Text]

data FZFResolver = FZFResolver
{ argDescription :: Text,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need a description in the resolver since we have one on each arg.

@aryairani aryairani added the ready-to-merge Apply this to a PR and it will get merged automatically once CI passes and 1 reviewer has approved label Jan 4, 2024
@mergify mergify bot merged commit 014b3fc into trunk Jan 4, 2024
7 checks passed
@mergify mergify bot deleted the cp/fzf-better-errs branch January 4, 2024 21:58
@mergify mergify bot removed the ready-to-merge Apply this to a PR and it will get merged automatically once CI passes and 1 reviewer has approved label Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants