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

Tab completion for block-scoped variables doesn't work in REPL #983

Closed
RB14 opened this issue Feb 27, 2015 · 28 comments
Closed

Tab completion for block-scoped variables doesn't work in REPL #983

RB14 opened this issue Feb 27, 2015 · 28 comments
Assignees
Labels
confirmed-bug Issues with confirmed bugs. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. repl Issues and PRs related to the REPL subsystem.

Comments

@RB14
Copy link

RB14 commented Feb 27, 2015

Using version 1.4.1 REPL mode, it seems that tab completion for block-scoped variables (i.e. let and const statements) doesn't show suggestions, while tab completion for variables declared with var or otherwise just assigned a value without a deceleration, does show up a list of suggestions.

Of course, this happens in strict mode, or else I couldn't use let and const.

@micnic micnic added the repl Issues and PRs related to the REPL subsystem. label Feb 27, 2015
@vkurchatkin
Copy link
Contributor

A test (run with --use_strict):

require('assert').equal(require('vm').runInNewContext(`
  let a = 42;
  this.a
`), 42);

summoning @domenic.

@benjamingr
Copy link
Member

I can reproduce this on v1.4.1 on OSX.

$ ./iojs --use_strict

let foobar = 40;
var bazbar = 100;
foo // hit tab, no autocomplete
baz // hit tab, autocompletes to bazbar

The test @vkurchatkin posted also fails.

@bnoordhuis
Copy link
Member

I think this can be explained because of how the REPL does autocompletion: it spawns a nested VM context that contains a copy of the globals from the parent context. var bindings have global scope but let bindings don't, i.e.:

> var x = 1; typeof global['x']  // 'number'
> let y = 1; typeof global['y']  // 'undefined'

I can't think of a good fix off the top of my head.

@vkurchatkin
Copy link
Contributor

the question is, this the correct behaviour according to spec?

@RB14 RB14 closed this as completed Feb 27, 2015
@RB14 RB14 reopened this Feb 27, 2015
@benjamingr
Copy link
Member

@vkurchatkin it appears that it is.

@domenic
Copy link
Contributor

domenic commented Mar 1, 2015

Right, indeed, let and const and class don't add to the global object, but instead to a separate scope contour. Unsure how to deal with this given the implementation details @bnoordhuis mentions.

@Fishrock123
Copy link
Contributor

Is this actually an issue then?

@RB14
Copy link
Author

RB14 commented Jul 1, 2015

Well, as the one who opened this ticket, I still find it odd that auto-complete in REPL would work for only var (or should I say old-style) variables, and not for the new kinds of declarations.
Since auto-complete is a feature of io.js (and node.js), and it's a very useful feature if you ask me, I think this behavior should be fixed (if possible of course).. so I think it should still be considered as an issue.

@Trott Trott added help wanted Issues that need assistance from volunteers or PRs that need help to proceed. confirmed-bug Issues with confirmed bugs. labels Mar 11, 2016
@jasnell
Copy link
Member

jasnell commented Apr 2, 2016

Appears to be fixed in master. Closing.

@jasnell jasnell closed this as completed Apr 2, 2016
@cjihrig
Copy link
Contributor

cjihrig commented Apr 2, 2016

Is this actually closed? Tab completion of let and const variables isn't working for me.

@philj0st
Copy link

neither is it for me. I'm on node v6.2.0

@bnoordhuis
Copy link
Member

I'll reopen, it doesn't work with master either.

@bnoordhuis bnoordhuis reopened this May 30, 2016
@kaicataldo
Copy link
Contributor

Can confirm that tab completion isn't working for const or let for me in the latest release (v6.2.2), but interestingly, const (but not let) works in v5.11.1.

@Fishrock123
Copy link
Contributor

Anyone know if there is a way to hook into what variables are in the current scope? VM hacks count.

Would running in/hooking into a new vm module context have this info?

@addaleax
Copy link
Member

@nodejs/v8?

@bnoordhuis
Copy link
Member

Anyone know if there is a way to hook into what variables are in the current scope?

You can through the debugger API but you have to fake a breakpoint.

Interestingly though, tab completion for let and const bindings seems to work with master.

@targos
Copy link
Member

targos commented Sep 20, 2016

Interestingly though, tab completion for let and const bindings seems to work with master.

It doesn't seem to work for me. What did you try ?

@Fishrock123
Copy link
Contributor

Just confirmed this still doesn't work on master.

@Fishrock123
Copy link
Contributor

cc @fhinkel

@fhinkel
Copy link
Member

fhinkel commented Oct 18, 2016

I'll check what the debugger does, since it works there.

If that doesn't work for us, here's a workaround we might try: Since vm intercepts all variable declarations anyways (and REPL sends everything through vm), we could also store the variable names in a list, and then do tab completion using that list. /cc @AnnaMag

@Fishrock123
Copy link
Contributor

ping @fhinkel did you get anywhere here?

@fhinkel
Copy link
Member

fhinkel commented Nov 23, 2016

Sorry, didn't get too much time on this yet.

@Fishrock123
Copy link
Contributor

ping @fhinkel, were you ever able to look into this? :D

@robahl
Copy link

robahl commented May 22, 2017

Help us @fhinkel, you're our only hope!

@jasnell
Copy link
Member

jasnell commented May 30, 2017

This appears to no longer be an issue.

@jasnell jasnell closed this as completed May 30, 2017
@targos
Copy link
Member

targos commented May 30, 2017

@jasnell I think it's still an issue. Note that Chrome devtools are also unable to provide completion for let or const variables.

@targos targos reopened this May 30, 2017
@jasnell
Copy link
Member

jasnell commented May 30, 2017

hmm.... yep, quick verification test shows that I was testing the wrong thing. Thanks for reopening @targos

@jgranduel
Copy link

Hi,
node-8.5.0 REPL win10... seems to still be an issue. Any news?

targos added a commit to targos/node that referenced this issue Dec 21, 2017
Use the V8 inspector protocol, if available, to query the list of
lexically scoped variables (defined with `let`, `const` or `class`).

PR-URL: nodejs#16591
Fixes: nodejs#983
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@targos targos closed this as completed in 416c0ec Dec 21, 2017
MylesBorins pushed a commit that referenced this issue Jan 8, 2018
Use the V8 inspector protocol, if available, to query the list of
lexically scoped variables (defined with `let`, `const` or `class`).

PR-URL: #16591
Fixes: #983
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this issue Jan 9, 2018
Use the V8 inspector protocol, if available, to query the list of
lexically scoped variables (defined with `let`, `const` or `class`).

PR-URL: #16591
Fixes: #983
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this issue Jan 9, 2018
Use the V8 inspector protocol, if available, to query the list of
lexically scoped variables (defined with `let`, `const` or `class`).

PR-URL: #16591
Fixes: #983
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this issue Jan 10, 2018
Use the V8 inspector protocol, if available, to query the list of
lexically scoped variables (defined with `let`, `const` or `class`).

PR-URL: #16591
Fixes: #983
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests