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

REPL: add wildcard to autocompletion #27337

Closed
BridgeAR opened this issue Apr 21, 2019 · 10 comments
Closed

REPL: add wildcard to autocompletion #27337

BridgeAR opened this issue Apr 21, 2019 · 10 comments
Labels
feature request Issues that request new features to be added to Node.js. repl Issues and PRs related to the REPL subsystem.

Comments

@BridgeAR
Copy link
Member

BridgeAR commented Apr 21, 2019

In most terminals it's possible to use an asterix (*) to indicate a wildcard search (as filter).

It would be great to add something like this to our REPL as well, e.g., using the current autocompletion with util.types.is*F results in the globals that start with an F. Instead, it would be great to print all is functions that start with is and that have an F somewhere in their name.

Using the asterix at the end should print everything as if it's not there (it currently prints nothing).

@BridgeAR BridgeAR added repl Issues and PRs related to the REPL subsystem. feature request Issues that request new features to be added to Node.js. labels Apr 21, 2019
@devsnek
Copy link
Member

devsnek commented Apr 21, 2019

I don't like that this would override the completion of a multiplication expression. -1 for the moment.

@BridgeAR
Copy link
Member Author

@devsnek I suggest to only filter the former in case there's no whitespace in-between the variables. With whitespace, the multiplication expression would still have the completion as before.

@devsnek
Copy link
Member

devsnek commented Apr 21, 2019

I mean without whitespace it's still multiplication, and people aren't generally aiming for perfect formatting when typing in a repl. (and some people consider no spaces perfect formatting so...)

@addaleax
Copy link
Member

How does this work as auto-completion? It’s one thing to print all possibilities, but how would you pick the right one?

This seems like an unusual feature for an auto-completion system – I don’t think I know of any precedent. So, if we were to implement this, I think we have the option to not use an asterisk, which would be good for the reason @devsnek mentions.

@devsnek
Copy link
Member

devsnek commented Apr 21, 2019

one thing you could consider is doing a fuzzy match on the last item instead of a start of string match, so x.string's completions would include toString

@BridgeAR
Copy link
Member Author

It's actually a filter in this case. I some times use this to match files.

E.g., if you have a file named foobar.js in your current dir and write: node *.js\t results in the first match that ends with .js in the current directory e.g., node foobar.js.

In this case I would like it to work as filter. It matches against all parts before the asterix and then filters the entries with the part after the asterix.

It is actually also possible to distinguish multiplications in case no whitespace is used by checking if the part before the asterix is a variable. If it is, the filter should not be triggered and it should work as it does right now (we could even check for type number).

@mscdex
Copy link
Contributor

mscdex commented Apr 22, 2019

-1 this seems too magical and unexpected

@BridgeAR
Copy link
Member Author

@mscdex since it's an opt-in, is there a downside? There are similar implementations in at least some unix terminals, so I guess it's mainly beneficial for people who know it from there as well.

@mscdex
Copy link
Contributor

mscdex commented Apr 22, 2019

What do you mean opt-in? A command-line flag? I doubt many people would opt-in to this kind behavior. It might be popular behavior for *nix shells because the role of a shell is a bit wider in scope than just any old programming language REPL. I've also never seen/heard of this behavior being implemented in any other language's REPL.

@BridgeAR
Copy link
Member Author

BridgeAR commented May 7, 2020

I am going to close this as there are quite a few more important things for the REPL on my TODO list. If I get to it, I'll just open a PR and see what people think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants