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 completion preview #30907

Closed
wants to merge 12 commits into from
Closed

Conversation

@BridgeAR
Copy link
Member

BridgeAR commented Dec 11, 2019

This mainly adds the next step to our the newly added preview: (tab) completion preview. It is now also automatically inserted when moving the cursor right when being at the end of the current input instead of only when pushing tab.

See it in action:
https://asciinema.org/a/ePQx0GfCYQGdnQTzwlnSIyxbN

This also fixes at least two small issues:

  1. image
    This is caused by the nested REPL tab completion. This was not detected earlier, since it's a rare case and only fails for syntax errors and similar. It was important to prevent syntax errors in the tab completion, otherwise the auto completion would have triggered those frequently.
  2. It also fixes an issue with the former preview implementation where long lines could have caused similar REPL confusion.

Please have a look at the individual commits messages for further details.

// cc: @nodejs/repl

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
@nodejs-github-bot

This comment was marked as outdated.

@targos

This comment was marked as resolved.

Copy link
Member

targos commented Dec 11, 2019

The asciinema link requires login.

@BridgeAR

This comment was marked as resolved.

Copy link
Member Author

BridgeAR commented Dec 11, 2019

@targos thanks, fixed.

@BridgeAR BridgeAR force-pushed the BridgeAR:repl-completion-preview branch from 3414ff7 to 8ff770e Dec 11, 2019
@nodejs-github-bot

This comment was marked as outdated.

Copy link

nodejs-github-bot commented Dec 11, 2019

@nodejs-github-bot

This comment was marked as outdated.

Copy link

nodejs-github-bot commented Dec 11, 2019

@targos
targos approved these changes Dec 12, 2019
lib/internal/readline/utils.js Outdated Show resolved Hide resolved
lib/internal/repl/utils.js Outdated Show resolved Hide resolved
lib/internal/repl/utils.js Outdated Show resolved Hide resolved
lib/readline.js Outdated Show resolved Hide resolved
@BridgeAR BridgeAR force-pushed the BridgeAR:repl-completion-preview branch from 8ff770e to 9e1fd58 Dec 13, 2019
@BridgeAR

This comment has been minimized.

Copy link
Member Author

BridgeAR commented Dec 13, 2019

@targos I addressed your nits and added one more commit that improves the coverage significantly. This should cover almost all regular preview usage plus edge cases.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@BridgeAR BridgeAR force-pushed the BridgeAR:repl-completion-preview branch from 0fb2bd5 to 8f1921e Dec 13, 2019
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

Copy link

nodejs-github-bot commented Dec 13, 2019

@BridgeAR BridgeAR requested review from antsmartian and lance Dec 13, 2019
**Default:** `true`. Always `false` in case `terminal` is falsy.
* `preview` {boolean} Defines if the repl prints autocomplete and output
previews or not. **Default:** `true`. Always `false` in case `terminal` is
falsy.

This comment has been minimized.

Copy link
@Trott

Trott Dec 13, 2019

Member

Does that mean the default is true if terminal is truthy and false if terminal is falsy? If that's the case then I think the text can be clarified a little, but that's a nit and not a blocking comment.

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Dec 13, 2019

Author Member

It's actually not only about the default. If the terminal is false, the preview is always deactivated. I am happy for suggestions to better word this :)

This comment has been minimized.

Copy link
@Trott

Trott Dec 14, 2019

Member

Maybe instead of this

Always `false` in case `terminal` is falsy.

...this?:

If `terminal` is falsy, then there are no previews and the value of `preview` has no effect.
@Trott
Trott approved these changes Dec 13, 2019
@Trott Trott added the author ready label Dec 13, 2019
BridgeAR added 4 commits Dec 10, 2019
The .scope command was used only in the old debugger. Since that's
not part of core anymore it's does not have any use. I tried to
replicate the expected behavior but it even results in just exiting
the repl immediately when using the completion similar to the removed
test case.
This simplifies calling `filteredOwnPropertyNames()`. The context
is not used in that function, so there's no need to call the function
as such.
This simplifies some repl code and removes a coe branch that is
unreachable.
This updates the used regular expression to the latest version.
It includes a number of additional escape codes.
@BridgeAR

This comment has been minimized.

Copy link
Member Author

BridgeAR commented Dec 15, 2019

Landed in 67ed526...ba29e27 🎉

@BridgeAR BridgeAR closed this Dec 15, 2019
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2019
The .scope command was used only in the old debugger. Since that's
not part of core anymore it's does not have any use. I tried to
replicate the expected behavior but it even results in just exiting
the repl immediately when using the completion similar to the removed
test case.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2019
This simplifies calling `filteredOwnPropertyNames()`. The context
is not used in that function, so there's no need to call the function
as such.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2019
This simplifies some repl code and removes a code branch that is
unreachable.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2019
This updates the used regular expression to the latest version.
It includes a number of additional escape codes.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2019
This renames some variables for clarity and moves the common substring
part into a shared file. One algorithm was more efficient than the
other but the functionality itself was identical.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit that referenced this pull request Dec 15, 2019
This just refactors code without changing the behavior. Especially
the REPL code is difficult to read and deeply indented. This reduces
the indentation to improve that.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2019
This improves the completion output by removing the nested special
handling. It never fully worked as expected and required a lot of
hacks to even keep it working halfway reliable. Our tests did not
cover syntax errors though and those can not be handled by this
implementation. Those break the layout and confuse the REPL.

Besides that the completion now also works in case the current line
has leading whitespace.

Also improve the error output in case the completion fails.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit that referenced this pull request Dec 15, 2019
This improves the already existing preview functionality by also
checking for the input completion. In case there's only a single
completion, it will automatically be visible to the user in grey.
If colors are deactivated, it will be visible as comment.

This also changes some keys by automatically accepting the preview
by moving the cursor behind the current input end.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2019
This addresses an issue that is caused by lines that exceed the
current window columns. That would cause the preview to confuse the
REPL. This is meant as hot fix. The preview should be able to handle
these cases appropriately as well later on.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit that referenced this pull request Dec 15, 2019
This improves the coverage for the preview feature signficantly.
Quite a few edge cases get testet here to prevent regressions.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
The .scope command was used only in the old debugger. Since that's
not part of core anymore it's does not have any use. I tried to
replicate the expected behavior but it even results in just exiting
the repl immediately when using the completion similar to the removed
test case.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This simplifies calling `filteredOwnPropertyNames()`. The context
is not used in that function, so there's no need to call the function
as such.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This simplifies some repl code and removes a code branch that is
unreachable.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This updates the used regular expression to the latest version.
It includes a number of additional escape codes.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This renames some variables for clarity and moves the common substring
part into a shared file. One algorithm was more efficient than the
other but the functionality itself was identical.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This just refactors code without changing the behavior. Especially
the REPL code is difficult to read and deeply indented. This reduces
the indentation to improve that.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This improves the completion output by removing the nested special
handling. It never fully worked as expected and required a lot of
hacks to even keep it working halfway reliable. Our tests did not
cover syntax errors though and those can not be handled by this
implementation. Those break the layout and confuse the REPL.

Besides that the completion now also works in case the current line
has leading whitespace.

Also improve the error output in case the completion fails.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This improves the already existing preview functionality by also
checking for the input completion. In case there's only a single
completion, it will automatically be visible to the user in grey.
If colors are deactivated, it will be visible as comment.

This also changes some keys by automatically accepting the preview
by moving the cursor behind the current input end.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This addresses an issue that is caused by lines that exceed the
current window columns. That would cause the preview to confuse the
REPL. This is meant as hot fix. The preview should be able to handle
these cases appropriately as well later on.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This improves the coverage for the preview feature signficantly.
Quite a few edge cases get testet here to prevent regressions.

PR-URL: #30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Dec 17, 2019
MylesBorins added a commit that referenced this pull request Dec 18, 2019
Notable Changes:

* cli:
  * add --trace-exit cli option (legendecas)
    #30516
* http,https:
  * increase server headers timeout (Tim Costa)
    #30071
* readline:
  * update ansi-regex (Ruben Bridgewater)
    #30907
  * promote \_getCursorPos to public api (Jeremy Albright)
    #30687
* repl:
  * add completion preview (Ruben Bridgewater)
    #30907
* util:
  * add Set and map size to inspect output (Ruben Bridgewater)
    #30225
* wasi:
  * require CLI flag to require() wasi module (Colin Ihrig)
    #30963

PR-URL: #31010
MylesBorins added a commit that referenced this pull request Dec 18, 2019
Notable Changes:

* cli:
  * add --trace-exit cli option (legendecas)
    #30516
* http,https:
  * increase server headers timeout (Tim Costa)
    #30071
* readline:
  * update ansi-regex (Ruben Bridgewater)
    #30907
  * promote \_getCursorPos to public api (Jeremy Albright)
    #30687
* repl:
  * add completion preview (Ruben Bridgewater)
    #30907
* util:
  * add Set and map size to inspect output (Ruben Bridgewater)
    #30225
* wasi:
  * require CLI flag to require() wasi module (Colin Ihrig)
    #30963

PR-URL: #31010
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 19, 2019
This improves the coverage for the preview feature signficantly.
Quite a few edge cases get testet here to prevent regressions.

PR-URL: nodejs#30907
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jan 12, 2020
2 of 2 tasks complete
@BridgeAR BridgeAR deleted the BridgeAR:repl-completion-preview branch Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.