Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

feat: improved user experience for detached instances with prefix matching and suggestions #4199

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

jeffsmale90
Copy link
Contributor

@jeffsmale90 jeffsmale90 commented Feb 1, 2023

Detached instances are pretty awesome, but they have long names that you have to type all the time!

With fuzzy matching (and some helpful suggestions), you can get by without typing so much:

$ ganache instances stop hot_lim_cheesecacke

hot_lim_cheesecacke found.

Did you mean:
 - hot_lime_cheesecake
 - hot_lemon_loaf

$ ganache instances stop hot_li
hot_lime_cheesecake stopped

note: now you only need to enter the unique prefix of the instance name. Ganache will use this prefix to identify the instance.

@jeffsmale90
Copy link
Contributor Author

This will have more thorough testing added after #3735 is merged

@leeoniya
Copy link

leeoniya commented Feb 1, 2023

maybe a bit late for a pitch, but https://github.com/leeoniya/uFuzzy#a-biased-appraisal-of-similar-work

@jeffsmale90
Copy link
Contributor Author

https://github.com/leeoniya/uFuzzy#a-biased-appraisal-of-similar-work

Thanks for the suggestion! I intentionally didn't introduce a library for this feature, in an effort to limit the impact on the bundle size.

In addition, I'm not sure this is a good fit for your library, based on your comment "match a relatively short search phrase (needle) against a large list of short-to-medium phrases (haystack)" whereas this use case is a very short search phrase against a small list of very short phrases.

I'll keep it in mind for future work though.

@jeffsmale90 jeffsmale90 marked this pull request as ready for review February 2, 2023 02:37
@jeffsmale90 jeffsmale90 marked this pull request as draft March 10, 2023 01:42
@jeffsmale90 jeffsmale90 changed the title feat: Fuzzy matching for detached instance names feat: improved user experience for detached instances with prefix matching and suggestions Apr 4, 2023
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 5, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4ce7169
Status: ✅  Deploy successful!
Preview URL: https://e4fca558.ganache.pages.dev
Branch Preview URL: https://feat-detach-fuzzy-matching.ganache.pages.dev

View logs

@@ -19,6 +19,8 @@ export type DetachedInstance = {
version: string;
};

const MAX_SUGGESTIONS = 4;
const MAX_LEVENSHTEIN_DISTANCE = 10;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a huge distance. I'm unsure about how to tune this.

I'd rather we give false positives, than false negatives - if I forget the name of the instance, and get something that's truly wrong, I'd still like a recommendation.

I'm open to suggestions on this. At the same time, it's something that we can tune later, and hopefully we'll get some user feedback on the experience.

Copy link
Member

Choose a reason for hiding this comment

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

agreed. we can tune it later.

@jeffsmale90 jeffsmale90 marked this pull request as ready for review April 5, 2023 02:37
@@ -19,6 +19,8 @@ export type DetachedInstance = {
version: string;
};

const MAX_SUGGESTIONS = 4;
const MAX_LEVENSHTEIN_DISTANCE = 10;
Copy link
Member

Choose a reason for hiding this comment

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

agreed. we can tune it later.

* @returns {{ match: string } | { suggestions: string[] }} an object
* containiner either a single exact `match` or a number of `suggestions`
*/
async function getSimilarInstanceNames(
Copy link
Member

Choose a reason for hiding this comment

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

Oh man I really want to optimize this function! haha. But since the actual number of files is typically going to be on the order of 1 I'll hold back! haha

p.s., using our findInsertPosition util function is always a good time.

@@ -181,7 +192,8 @@ if (argv.action === "start") {
})
.catch(err => {
// the child process would have output its error to stdout, so no need to
// output anything more
// do anything more other than set the exitCode
process.exitCode = 1;
Copy link
Member

Choose a reason for hiding this comment

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

smart!

console.log(`${porscheColor(instanceName)} not found.`);
if (instanceOrSuggestions.suggestions?.length > 0) {
console.log();
console.log("Did you mean:");
Copy link
Member

Choose a reason for hiding this comment

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

Since this isn't interactive (oh that'd be cool!), and the user can't actually answer the question. Should we use a different phrase here? git uses The most similar command is.

image

src/packages/cli/src/detach.ts Outdated Show resolved Hide resolved
*
* @param {string} a - The first string to compare.
* @param {string} b - The second string to compare.
* @return {number} The Levenshtein distance between the two strings.
Copy link
Member

Choose a reason for hiding this comment

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

I think I've mentioned this before, but including the types in these definitions are kinda redundant. I don't think you need to remove them, but I don't think you need to add them in the first place either.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants