ternjs / tern

A JavaScript code analyzer for deep, cross-editor language support
https://ternjs.net/
MIT License
4.25k stars 378 forks source link

[Bug] The autocompletion for prototype #1030

Closed weixiongmei closed 5 years ago

weixiongmei commented 5 years ago

Repeatable Link: https://ternjs.net/doc/demo/index.html#simple Revision: 0.24.1

// Use ctrl-space to complete something
co
document.body.a

// Put the cursor in or after an expression, press ctrl-i to
// find its type

var foo = ["array", "of", "strings"]
var bar = foo.slice(0, 2).join("").split("a")[0]

// Works for locally defined types too.

function CTor() { this.size = 10 }
CTor.prototype.hallo = "hallo"
CTor.prototype.//====BUG====
CTor.prototype.//====NO BUG AFTER SECOND PROPERTY DEFINED====
var baz = new CTor
baz.

// You can press ctrl-q when the cursor is on a variable
// name to rename it. Try it with CTor...

// When the cursor is in an argument list, the arguments
// are shown below the editor.

[1].reduce(  )

Bug: (refer to the ====BUG==== tag in the code above) When trying to do the autocompletion for defining the second property of the prototype, it always automatically insert the name of the first property that's defined. But after the second property is defined, this bug seems not going to happen anymore.

marijnh commented 5 years ago

This is definitely not a bug in Tern, and probably not a bug generally. If you're planning to type a new property name, don't activate autocompletion. Tern correctly reports a single property here, and CodeMirror's autocompletion completes those immediately by default.

weixiongmei commented 5 years ago

Still wondering if this is not a bug, why it wouldn’t happen when defining the first property or the third property and so on? Why it only happens on the second property? Thanks

marijnh commented 5 years ago

As I mentioned, CodeMirror's autocompletion will by default complete right away when there's only one option. That's what you're seeing here.