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

Bug 512964

Summary: Computed environment causes unexpected behaviour when .tern-project file is present
Product: [ECD] Orion Reporter: Michael Rennie <Michael_Rennie>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: curtis.windatt.public, pahnke.sebastian, steve_northover
Version: 13.0Flags: curtis.windatt.public: review+
Target Milestone: 14.0   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Michael Rennie CLA 2017-03-02 09:06:22 EST
A report came in against the latest tooling in our mattermost channel:

"Why do I get completions for commonjs, node and browser environments with the following .tern-project file? It happens in Orion and the CodeEditWidget. It's a rather new behavior which I don't expect. Instead I expect to get completions for ECMA5 and the additional Big.js library only. This is a breaking change for me.

I only expect to see additional browser completion if I add "browser" to the libs list."

The example .tern-project file used:

{
    "plugins": {},
    "libs": [".definitions/big"],
    "ecmaVersion": 5
}

We should re-examine how all the computed information is merged together. Perhaps to maintain backwards compatibility with the idea that ".tern-project files drive project configuration", we should only use whats in the .tern-project iff:

1. there is a .tern-project file present
2. there is no package.json
3. there is no node_modules
Comment 1 Steve Northover CLA 2017-03-02 09:17:40 EST
First cut:  If the person is smart enough to have a .tern-project file, we should use it first and then other indications in environment.  We should NEVER create the .tern-project file for free.

So, if they guy has no .tern-project, we assume browser and Node (and compute other things from the various files).  Otherwise, we use .tern-project.

Thoughts?
Comment 2 Michael Rennie CLA 2017-03-02 10:24:46 EST
(In reply to Steve Northover from comment #1)
> First cut:  If the person is smart enough to have a .tern-project file, we
> should use it first and then other indications in environment.  We should
> NEVER create the .tern-project file for free.
> 
> So, if they guy has no .tern-project, we assume browser and Node (and
> compute other things from the various files).  Otherwise, we use
> .tern-project.
> 
> Thoughts?

Also: if they have a .tern-project, and a package.json file and have not added the node plugin, we should auto-add that.
Comment 3 Steve Northover CLA 2017-03-02 10:33:56 EST
Yes, package.json implies Node.
Comment 4 Sebastian Pahnke CLA 2017-03-02 10:42:36 EST
Sounds good to me. This way it's backward compatible and convenient for new users :)
Comment 5 Michael Rennie CLA 2017-03-02 11:56:50 EST
Pushed fix to:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=93b526124a20d2bef7498c338173c5f0ff255e97

Sebastian, Curtis, please review.
Comment 6 Sebastian Pahnke CLA 2017-03-02 12:20:52 EST
In Orion it works now as expected, only completions for Big.js and ECMA5 are shown. In the CodeEditWidget I still get commonjs and node completions (bad), but the browser completions are now hidden (good). And by adding "browser" to "libs" I can enable them if I need (good). Maybe something to do with the in memory file system?
Comment 7 Michael Rennie CLA 2017-03-02 13:55:43 EST
(In reply to Sebastian Pahnke from comment #6)
> In Orion it works now as expected, only completions for Big.js and ECMA5 are
> shown. In the CodeEditWidget I still get commonjs and node completions
> (bad), but the browser completions are now hidden (good). And by adding
> "browser" to "libs" I can enable them if I need (good). Maybe something to
> do with the in memory file system?

I bet the code widget does not support the new fileClient API for getProject. Thanks for trying it Sebastian, I'll check the widget code now.
Comment 8 Michael Rennie CLA 2017-03-02 14:18:30 EST
(In reply to Michael Rennie from comment #7)
> (In reply to Sebastian Pahnke from comment #6)
> > In Orion it works now as expected, only completions for Big.js and ECMA5 are
> > shown. In the CodeEditWidget I still get commonjs and node completions
> > (bad), but the browser completions are now hidden (good). And by adding
> > "browser" to "libs" I can enable them if I need (good). Maybe something to
> > do with the in memory file system?
> 
> I bet the code widget does not support the new fileClient API for
> getProject. Thanks for trying it Sebastian, I'll check the widget code now.

Yup, that was the problem. Added the support in:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=84ce231245e9e2b4bdf0b711919c011da24a60ff.

Libing is double-checking the other support to load files in the widget, just to make sure everything is still working properly.
Comment 9 Michael Rennie CLA 2017-03-02 14:37:35 EST
I also added support for read-if-exists to the in-memory file client:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=b470861097f28d9039bac66fe51023ee580ab65c
Comment 10 Sebastian Pahnke CLA 2017-03-02 15:00:58 EST
I just did a quick test and it seems to work now. Will test it more tomorrow.

Thanks Michael, looking forward to using version 14!
Comment 11 Curtis Windatt CLA 2017-03-02 16:16:11 EST
+1 for this change in 14.0, Sebastian please verify with your application.
Comment 12 Sebastian Pahnke CLA 2017-03-03 04:09:18 EST
This works for me.
Comment 13 Michael Rennie CLA 2017-03-03 10:07:53 EST
(In reply to Sebastian Pahnke from comment #12)
> This works for me.

Thank you for verifying!

Closing fixed.