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

feat: add fuzzy completions extension in the REPL #2493

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

Conversation

Snehil-Shah
Copy link
Member

Resolves #1845

Description

What is the purpose of this pull request?

This pull request:

  • adds fuzzy completions in cases when there are no exact matches.
  • No more than 10 fuzzy completions are displayed at a time.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

fuzzy.mp4

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
@Snehil-Shah Snehil-Shah added Enhancement Issue or pull request for enhancing existing functionality. REPL Issue or pull request specific to the project REPL. labels Jul 1, 2024
@Planeshifter Planeshifter self-requested a review July 2, 2024 15:53
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

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

@Snehil-Shah Finally got around to taking a closer look. Not seeing any major issues and looks good overall.

There is a bit of code duplication in the various complete functions. Do you see any way of abstracting away some of it into a reusable function?

lib/node_modules/@stdlib/repl/lib/complete_expression.js Outdated Show resolved Hide resolved
lib/node_modules/@stdlib/repl/lib/complete_fs.js Outdated Show resolved Hide resolved
lib/node_modules/@stdlib/repl/lib/complete_expression.js Outdated Show resolved Hide resolved
lib/node_modules/@stdlib/repl/lib/complete_settings.js Outdated Show resolved Hide resolved
lib/node_modules/@stdlib/repl/lib/complete_require.js Outdated Show resolved Hide resolved
lib/node_modules/@stdlib/repl/lib/fuzzy_match.js Outdated Show resolved Hide resolved
lib/node_modules/@stdlib/repl/lib/fuzzy_match.js Outdated Show resolved Hide resolved
Snehil-Shah and others added 4 commits September 10, 2024 17:00
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Copy link
Member Author

Choose a reason for hiding this comment

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

@Planeshifter Do you mean a file like this w.r.t code duplication?

Copy link
Member

Choose a reason for hiding this comment

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

@Snehil-Shah Yes, was wondering whether we can consolidate some of it. Your call!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, but I'm kinda confused with how we can abstract those😅. Do you have something in mind?

Copy link
Member

@Planeshifter Planeshifter Sep 12, 2024

Choose a reason for hiding this comment

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

@Snehil-Shah

Couldn't we define a helper function like

function collectCompletions( items, filter, isFuzzy ) {
	var fuzzyResults = [];
	var out = [];
	var match;
	var item;
	var i;

	for ( i = 0; i < items.length; i++ ) {
		item = items[ i ];
		if ( startsWith( item, filter ) ) {
			out.push( item );
		}
	}
	out.sort();

	// Only perform fuzzy search if no exact matches are found...
	if ( !isFuzzy || out.length !== 0 ) {
		return out;
	}
	for ( i = 0; i < items.length; i++ ) {
		item = items[ i ];
		match = fuzzyMatch( item, filter );
		if ( match ) {
			fuzzyResults.push( match );
		}
	}
	fuzzyResults = sortFuzzyCompletions( fuzzyResults );
	for ( i = 0; i < fuzzyResults.length; i++ ) {
		out.push( fuzzyResults[ i ] );
	}
	return out;
}

and then use them in the various completers? E.g., for complete_settings.js, could directly invoke

var completions = collectCompletions( SETTINGS_NAMES, value, isFuzzy );

and then push the completions to the out array. I realize that some of the completers have additional logic like the file system one, but may be worth exploring...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Issue or pull request for enhancing existing functionality. REPL Issue or pull request specific to the project REPL.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add fuzzy auto-completion in REPL
2 participants