Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 513616

Summary: Content assist gives strange proposal in a dictionary object
Product: [ECD] Orion Reporter: Remy Suen <remy.suen>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public, Michael_Rennie, pahnke.sebastian
Version: 13.0   
Target Milestone: 15.0   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Attachments:
Description Flags
Image describing the error in question. none

Description Remy Suen CLA 2017-03-14 05:11:34 EDT
Created attachment 267248 [details]
Image describing the error in question.

orion.eclipse.org

1. Create a project.
2. Create a test.js file.
3. Put the following content in it.

var markdowns = {
						// assist here
};

var s = "abc";

return markdowns[s];

4. Invoke content assist where the comment is.
5. You'll get a strange suggestion: <i>
6. Wrapping it in a function so it's more "realistic" doesn't help. You'll get the same problem.

function x() {
	var markdowns = {
							// assist here
	};
	
	var s = "abc";
	
	return markdowns[s];
}
Comment 1 Curtis Windatt CLA 2017-03-14 10:16:27 EDT
I don't get any proposals inside markdowns. Tern must be suggesting it from some pattern seen previously (possibly in a different file).
Comment 2 Sebastian Pahnke CLA 2017-03-14 11:49:13 EDT
I can reproduce in the CodeEditWidget.

The key is include the line
markdowns[s]

If you just have the empty markdowns object, no proposals are shown (good).
If you add the statement markdowns["abc"] you get the proposal "abc" inside the object literal (good).
But with indirection step through the variable "s" you get the <i> proposal inside the object literal (bad).
Comment 3 Michael Rennie CLA 2017-03-14 12:15:52 EDT
(In reply to Sebastian Pahnke from comment #2)
> I can reproduce in the CodeEditWidget.
> 
> The key is include the line
> markdowns[s]
> 

The problem can also be easily reproduced using the demo page: http://ternjs.net/doc/demo/index.html#simple

and the snippet:

var markdowns = {
  // assist here
};

var s = "abc";
return markdowns[s];

The underlying reason looks like a combination of:
1. when the object is inferred, a placeholder property is added for 's', and,
2. when we ask for proposals, we also accept guessed proposals, which end up including the '<i>' stand-in.

I'll open a bug against Tern to see if this is by design, or a bug that we can get fixed there.
Comment 4 Michael Rennie CLA 2017-03-14 12:20:02 EDT
The Tern bug:

https://github.com/ternjs/tern/issues/894
Comment 5 Michael Rennie CLA 2017-03-14 13:32:46 EDT
(In reply to Michael Rennie from comment #4)
> The Tern bug:
> 
> https://github.com/ternjs/tern/issues/894

The Tern bug has been fixed already. We can adopt the changes in our code for now until we update to a version of Tern with the fix in it.