stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

feat: add UX to cycle through completions in the REPL

Open Snehil-Shah opened this issue 1 year ago • 4 comments

Subtask of #1845

Description

What is the purpose of this pull request?

This pull request:

  • replaces readline's built-in completer with a new UX that allows highlighting and navigating completions.

Related Issues

Does this pull request have any related issues?

This pull request:

  • subtask of #1845
  • updates #1855

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.

Recording of new behavior:

https://github.com/stdlib-js/stdlib/assets/130062020/6ce1e4d8-076e-412b-9e2c-ad8f44c94877

Checklist

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


@stdlib-js/reviewers

Snehil-Shah avatar Jun 26 '24 12:06 Snehil-Shah

@Planeshifter I updated the code, now one can only traverse what they see. And as we also support interactive terminal window sizes, they can always resize. Here's a video demonstrating this:

https://github.com/stdlib-js/stdlib/assets/130062020/6e8b4756-f7a4-4be4-b5cf-819ebd4dc2c4

Snehil-Shah avatar Jun 28 '24 20:06 Snehil-Shah

@Snehil-Shah Pulled down the latest and played around. Works nicely. Thanks for working on this.

One comment: currently, when I enter co and then TAB, I get a list of potential matches. When I enter the next letter, such as n, the list of potential matches disappears and I need to hit TAB again to see the updated list. I then need to repeat this sequence for each new character until I've completed an identifier.

What I wonder is whether we should eliminate the need for repeatedly hitting TAB in order to see the list of potential matches. In terms of UX, one thing I do when seeing completion possibilities is use the list to help guide my spelling, having immediate feedback that I've misspelled something when the list disappears due to a spelling mistake.

In which case, I wonder if hitting TAB and triggering a completion list should trigger a "completion mode" in which the list of completions is continually displayed and updated as I enter new characters, without needing to explicitly hit TAB after every entered character.

Not sure how feasible this suggestion is.

kgryte avatar Jun 29 '24 09:06 kgryte

@kgryte Done. It works from how much I've tried. Can you confirm if this is the behavior you were suggesting so I can write tests for this?

  • Once you trigger the completions panel using TAB, you can only turn it off using TAB, ENTER, SIGINT events, or an up arrow when on the current line.
  • normal typing including backspaces and arrow movements sustains and updates the completions panel.
  • If you end up typing something with no completions to show, it doesn't automatically close the completer. Meaning you can go back and fix your spelling mistakes without needing to toggle the completer again

Snehil-Shah avatar Jun 29 '24 11:06 Snehil-Shah

@Snehil-Shah Yes, this is what I was thinking. Thanks for the updates. The only other small niggle is that, when I type con and hit TAB, the completions display. When I continue typing const, the completions disappear due to an exact match with const; however, const may not be what I want, but I am no longer able to see the possibilities until I hit the next character consta. I wonder if it would make sense to keep the completion options still visible even when an exact match.

kgryte avatar Jun 29 '24 22:06 kgryte

@kgryte The new UX doesn't make the completions disappear due to an exact match. Turns out it's a bug in the completer callback and not the completerEngine, and it is only specific to const. For example, typing conj while in tab completions view, correctly displays both conj and conjf.

image

I will investigate this and fix it in a separate patch PR.

Snehil-Shah avatar Jun 30 '24 22:06 Snehil-Shah

Also, wrote the test for this and the specific case you mentioned of an exact match.

Snehil-Shah avatar Jun 30 '24 22:06 Snehil-Shah