Node: Tab completion for block-scoped variables doesn't work in REPL

Created on 27 Feb 2015  路  28Comments  路  Source: nodejs/node

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.

confirmed-bug help wanted repl

All 28 comments

A test (run with --use_strict):

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

summoning @domenic.

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.

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.

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

@vkurchatkin it appears that it is.

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.

Is this actually an issue then?

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.

Appears to be fixed in master. Closing.

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

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

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

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.

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?

@nodejs/v8?

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.

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 ?

Just confirmed this still doesn't work on master.

cc @fhinkel

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

ping @fhinkel did you get anywhere here?

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

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

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

This appears to no longer be an issue.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willnwhite picture willnwhite  路  3Comments

ksushilmaurya picture ksushilmaurya  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

srl295 picture srl295  路  3Comments