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

Bug 489952

Summary: Content assist automatically fills in the "wrong thing" (assumes a single method and pastes it in)
Product: [ECD] Orion Reporter: Steve Northover <steve_northover>
Component: ClientAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: curtis.windatt.public, Silenio_Quarti
Version: 12.0   
Target Milestone: 13.0   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/69477
Whiteboard:
Attachments:
Description Flags
Working fine for me
none
proposed fix none

Description Steve Northover CLA 2016-03-18 11:19:23 EDT
1) Get minesweeper-objects from GitHub (it has the tern file)
2) Click on main.js
3) Place the on line 27 after the "." in counter1 (ie counter1.)
4) Hit Ctrl+Space (ask for code assist)
5) BUG: setValue() is automatically filled in

To see why this is wrong, on a new line right after line 27, type "counter1." and hit Ctrl+Space.  You get a list of choices.

My first thought is that we should never automatically fill something in.  It just makes me have to delete it when the guess is wrong.
Comment 2 Steve Northover CLA 2016-03-21 17:47:21 EDT
The same problem is happening for me with app.js when you place the cursor just before ".use".  It automatically puts in "listen".  Can you confirm this is happening for you?
Comment 3 Michael Rennie CLA 2016-03-22 10:26:37 EDT
Created attachment 260484 [details]
Working fine for me

No, I cannot reproduce. I always get the list.
Comment 4 Steve Northover CLA 2016-03-22 12:13:39 EDT
> Get minesweeper-objects from GitHub

It is the .tern-project file thing.  Without out it works, with one, it inserts "listen" because it saw "listen" once in the file.  I thought that was changed by fixing this bug?  Anyhow, I think because JavaScript is so fuzzy and gets things wrong, when there is one thing, we probably should not just insert it.
Comment 5 Steve Northover CLA 2016-03-29 13:30:38 EDT
1) Root/org.eclipse.orion.client/modules/orionode/server.js
2) Line 121, put the cursor after "nextWindow."
3) Invoke Code Assist
4) BUG: nextWindow.webContents is automatically filled in
Comment 6 Eclipse Genie CLA 2016-03-29 15:36:28 EDT
New Gerrit change created: https://git.eclipse.org/r/69477
Comment 7 Michael Rennie CLA 2016-03-29 16:30:01 EDT
(In reply to Steve Northover from comment #5)
> 1) Root/org.eclipse.orion.client/modules/orionode/server.js
> 2) Line 121, put the cursor after "nextWindow."
> 3) Invoke Code Assist
> 4) BUG: nextWindow.webContents is automatically filled in

This is happening because nextWindow has no type information - it is inferred as 'any' so the best we can do is offer something we have seen before. It doesn't have anything to do with .tern-project or any other setting, its that we don't know what 'new electron.BrowserWindow' makes.

If you place the cursor right before 'return nextWindow;' on line 139, you'll see what I mean - you will get two proposals 'loadURL' and 'webContents'.

The missing type information will be fixed with bug 481271 (properly looking up libs in node_modules). But showing proposals for things we have seen before is kind of handy (and better than nothing).

> New Gerrit change created: https://git.eclipse.org/r/69477

The proposed fix simply torches the auto apply flag. I don't think we should be doing that. Silenio would know more.
Comment 8 Steve Northover CLA 2016-03-29 16:36:19 EDT
Ok, so we are getting rid of "if there is only one possibility, use it" because in a JavaScript world, there are almost always many possibilities.  That sounds right.
Comment 9 Michael Rennie CLA 2016-06-09 15:55:34 EDT
Created attachment 262349 [details]
proposed fix

This patch adds a provider-level option to allow / disallow auto-applying proposals
Comment 10 Michael Rennie CLA 2016-06-09 15:56:10 EDT
Curtis, Silenio, please review the patch.
Comment 11 Curtis Windatt CLA 2016-06-09 16:53:44 EDT
The patch works as stated (turns off auto apply).  However, I'm not a big fan of this because a lot of the time the single completion available is the right one.  I would prefer the behaviour remains as is until we have better UI around guessed proposals.

I know it would be much harder to implement, but I would rather auto apply stays on, but doesn't happen if the single completion was a guess by Tern.  This combined with tagging guess proposals with some indicator for the user would be awesome.
Comment 12 Steve Northover CLA 2016-06-10 07:49:13 EDT
Please determine what other editors do in this case for comparison.
Comment 13 Steve Northover CLA 2016-06-10 07:49:26 EDT
Please determine what other editors do in this case for comparison.
Comment 14 Michael Rennie CLA 2016-06-10 10:45:47 EDT
(In reply to Steve Northover from comment #13)
> Please determine what other editors do in this case for comparison.

None of the other editors automatically apply a proposal - they all will show the single one. 

I chose to turn it off for the mentioned reason, the fact that when we show guesses we will have to show it, and the fact that auto-apply annoys me - I'm of the camp that I always want to see what is being proposed before it is applied.
Comment 15 Steve Northover CLA 2016-06-10 11:08:09 EDT
Ok, I think we are in agreement.  I hate when the wrong thing gets filled in automatically and I have to delete it.

Does the released code every auto-fill?  It's hard to detangle the discussion
Comment 16 Michael Rennie CLA 2016-06-10 12:54:54 EDT
(In reply to Steve Northover from comment #15)
> Ok, I think we are in agreement.  I hate when the wrong thing gets filled in
> automatically and I have to delete it.
> 
> Does the released code every auto-fill?  It's hard to detangle the discussion

The released code does not prevent the auto-fill. The patch adds a new provider-level option to enable or disable auto-fill (and also contains the change to the JS provider to not auto-fill).
Comment 17 Steve Northover CLA 2016-06-10 12:58:25 EDT
Please stop the auto-fill (unless we are absolutely sure) the content assist is correct.  This is consistent with the other editors.
Comment 18 Michael Rennie CLA 2016-08-10 15:49:59 EDT
Pushed the patch to master:
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=3af99b860793c46aaa563df74f4c33d5602f5ec4

All tests pass (JS, core and UI).