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

readline: show completions only after 2nd TAB #7754

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
7 participants
@addaleax
Member

addaleax commented Jul 15, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

readline

Description of change

Show TAB completion suggestions only after the user has pressed TAB twice in a row, so that the full list of suggestions doesn’t present a distraction. The first time a TAB key is pressed, only partial longest-common-prefix completion is performed.

This moves the readline autocompletion a lot closer to what e.g. bash does.

Fixes: #7665

This is arguably an exclusively human-facing part of the readline functionality, so the semver-major label is up for debate.

@Trott

This comment has been minimized.

Member

Trott commented Jul 15, 2016

Code LGTM if CI is OK.

@addaleax

This comment has been minimized.

Member

addaleax commented Jul 15, 2016

Thanks for the reminder. ;)

CI: https://ci.nodejs.org/job/node-test-commit/4129/ (edit: It’s green.)

@trevnorris

This comment has been minimized.

Contributor

trevnorris commented Jul 16, 2016

LGTM

@princejwesley

View changes

lib/readline.js Outdated
{

This comment has been minimized.

@princejwesley

princejwesley Jul 16, 2016

Contributor

Do we need { block } here ? Seems unnecessary

This comment has been minimized.

@addaleax

addaleax Jul 16, 2016

Member

It’s just to keep the diff small, I don’t feel strongly about it.

This comment has been minimized.

@yorkie

yorkie Aug 1, 2016

Member

@princejwesley @addaleax I think using let on the following 2 line could make the block start scoping there.

This comment has been minimized.

@addaleax

addaleax Aug 1, 2016

Member

@yorkie Sorry, I’m not entirely sure what you’re suggesting – would you like to see the block removed? let vs var shouldn’t matter (but I would change var -> let if the block is removed, yes)

This comment has been minimized.

@yorkie

yorkie Aug 1, 2016

Member

let vs var shouldn’t matter

I don't think so because here the brackets would create a scope with let declaration but not for var. For example:

{
  var f = completions.filter(function(e) { if (e) return e; });
  var prefix = commonPrefix(f);
}
// here we actually can access `f` and `prefix`, this is not what we expect by brackets.
// using `let` instead of `var` can make it expected result.

Actually my suggestion is not removing brackets here and changing var -> let.

This comment has been minimized.

@trevnorris

trevnorris Aug 2, 2016

Contributor

any performance difference between let vs var is measured in nanoseconds (approaching a microsecond in one really strange past case, but has been fixed), and either way shouldn't be a consideration for this PR.

This comment has been minimized.

@yorkie

yorkie Aug 2, 2016

Member

So I think here using let with block would reduce the possibility to produce bugs, because the variables are isolated to top scope.

This comment has been minimized.

@trevnorris

trevnorris Aug 2, 2016

Contributor

To summarize, if we use var then remove the block scope. If we keep the block scope then switch to let. Personally I don't care either way. @addaleax Let's do one or the other, but I'll leave that up to you.

This comment has been minimized.

@addaleax

addaleax Aug 2, 2016

Member

I’ve removed the extra block scope here and const’ed the variables, that should be okay (but if anyone wants something else very strongly, I’ll change that again. I don’t really care that much either).

This comment has been minimized.

@yorkie

yorkie Aug 2, 2016

Member

const variables looks good to me, too :-)

@bnoordhuis

View changes

test/parallel/test-readline-undefined-columns.js Outdated
iStream.write('process.s\t');
assert(/process.std\b/.test(output)); // Completion works.
assert(!/stdout/.test(output)); // Completion doesn’t show all results yet.

This comment has been minimized.

@bnoordhuis

bnoordhuis Jul 16, 2016

Member

Tiny style nit: two spaces before //.

This comment has been minimized.

@addaleax
@bnoordhuis

This comment has been minimized.

Member

bnoordhuis commented Jul 16, 2016

LGTM

As to semver-minor vs. semver-major, this change could conceivably break scripted uses of the readline module.

I don't know if anyone actually does that (besides us, in our test suite) but I'd err on the side of caution.

@addaleax addaleax force-pushed the addaleax:readline-tab-2nd-completion branch Jul 16, 2016

@jasnell

This comment has been minimized.

Member

jasnell commented Aug 1, 2016

This LGTM. One thing we may want to consider as a follow on for this is to put some kind of time-limit for the second TAB press... that may be overkill tho.

@trevnorris trevnorris referenced this pull request Aug 2, 2016

Closed

repl: Add editor mode support #7275

4 of 4 tasks complete
readline: show completions only after 2nd TAB
Show `TAB` completion suggestions only after the user has pressed `TAB`
twice in a row, so that the full list of suggestions doesn’t present
a distraction. The first time a `TAB` key is pressed, only partial
longest-common-prefix completion is performed.

This moves the `readline` autocompletion a lot closer to what e.g.
`bash` does.

Fixes: #7665

@addaleax addaleax force-pushed the addaleax:readline-tab-2nd-completion branch to dca1f27 Aug 2, 2016

}
// If there is a common prefix to all matches, then apply that portion.
const f = completions.filter(function(e) { if (e) return e; });

This comment has been minimized.

@princejwesley

princejwesley Aug 2, 2016

Contributor

@addaleax
we don't need to run this block of code when completions.length === 1, right?
I mean, self._insertString(completions[0].slice(completeOn.length)) is sufficient.

This comment has been minimized.

@addaleax

addaleax Aug 2, 2016

Member

@princejwesley Yeah… I’m not sure if that’s worth it, at least for tab completion. ;) If you want, I can add a strings.length === 1 shortcut case to commonPrefix(), that’s probably where most of the unnecessary work would happen otherwise?

This comment has been minimized.

@princejwesley

princejwesley Aug 2, 2016

Contributor

@addaleax Yes. Its good to add length check in commonPrefix().

This comment has been minimized.

@addaleax

addaleax Aug 2, 2016

Member

@princejwesley Done! :)

@jasnell

This comment has been minimized.

Member

jasnell commented Aug 4, 2016

addaleax added a commit that referenced this pull request Aug 4, 2016

readline: show completions only after 2nd TAB
Show `TAB` completion suggestions only after the user has pressed `TAB`
twice in a row, so that the full list of suggestions doesn’t present
a distraction. The first time a `TAB` key is pressed, only partial
longest-common-prefix completion is performed.

This moves the `readline` autocompletion a lot closer to what e.g.
`bash` does.

Fixes: #7665
PR-URL: #7754
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax

This comment has been minimized.

Member

addaleax commented Aug 4, 2016

Landed in 1a9e247

@addaleax addaleax closed this Aug 4, 2016

@addaleax addaleax deleted the addaleax:readline-tab-2nd-completion branch Aug 4, 2016

@gibfahn gibfahn referenced this pull request Jun 15, 2017

Closed

Auditing for 6.11.1 #230

2 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment