Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 488530 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/api/ternServer.js (-1 / +13 lines)
Lines 1-6 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * @license
2
 * @license
3
 * Copyright (c) 2015 IBM Corporation and others.
3
 * Copyright (c) 2015, 2016 IBM Corporation and others.
4
 * All rights reserved. This program and the accompanying materials are made 
4
 * All rights reserved. This program and the accompanying materials are made 
5
 * available under the terms of the Eclipse Public License v1.0 
5
 * available under the terms of the Eclipse Public License v1.0 
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
Lines 527-532 Link Here
527
					defNames = jsonOptions.defs;
527
					defNames = jsonOptions.defs;
528
					ddir = jsonOptions.defsDir;
528
					ddir = jsonOptions.defsDir;
529
				}
529
				}
530
				if(Array.isArray(jsonOptions.loadEagerly) && jsonOptions.loadEagerly.length > 0) {
531
					options.loadEagerly = jsonOptions.loadEagerly;
532
				}
530
				if (typeof jsonOptions.ecmaVersion === 'number'){
533
				if (typeof jsonOptions.ecmaVersion === 'number'){
531
					options.ecmaVersion = jsonOptions.ecmaVersion;
534
					options.ecmaVersion = jsonOptions.ecmaVersion;
532
				}
535
				}
Lines 534-543 Link Here
534
					options.dependencyBudget = jsonOptions.dependencyBudget;
537
					options.dependencyBudget = jsonOptions.dependencyBudget;
535
				}
538
				}
536
	        }
539
	        }
540
	        function _loadFiles(ternserver, options) {
541
	        	if(Array.isArray(options.loadEagerly)) {
542
	        		options.loadEagerly.forEach(function(file) {
543
	        			ternserver.addFile(file);
544
	        		});
545
	        	}
546
	        }
537
	        function defaultStartUp(err) {
547
	        function defaultStartUp(err) {
538
				options.plugins = plugins;
548
				options.plugins = plugins;
539
				options.defs = defs;
549
				options.defs = defs;
540
				ternserver = new Tern.Server(options);
550
				ternserver = new Tern.Server(options);
551
				_loadFiles(ternserver, options);
541
				callback(err);
552
				callback(err);
542
	        }
553
	        }
543
	        if(!options.plugins && (!defNames || defNames.length < 1)) {
554
	        if(!options.plugins && (!defNames || defNames.length < 1)) {
Lines 547-552 Link Here
547
					Deferred.all(loadDefs(defNames, ddir)).then(function(json) {
558
					Deferred.all(loadDefs(defNames, ddir)).then(function(json) {
548
							options.defs = json;
559
							options.defs = json;
549
							ternserver = new Tern.Server(options);
560
							ternserver = new Tern.Server(options);
561
							_loadFiles(ternserver, options);
550
							callback();
562
							callback();
551
						}, defaultStartUp);
563
						}, defaultStartUp);
552
		        }, defaultStartUp);
564
		        }, defaultStartUp);
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js (-29 / +50 lines)
Lines 1-6 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * @license
2
 * @license
3
 * Copyright (c) 2015 IBM Corporation and others.
3
 * Copyright (c) 2015, 2016 IBM Corporation and others.
4
 * All rights reserved. This program and the accompanying materials are made
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0
5
 * available under the terms of the Eclipse Public License v1.0
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
Lines 58-67 Link Here
58
        var pluginsDir = defaultOptions.pluginsDir;
58
        var pluginsDir = defaultOptions.pluginsDir;
59
        var defNames, plugins, projectLoc;
59
        var defNames, plugins, projectLoc;
60
        if (jsonOptions) {
60
        if (jsonOptions) {
61
        	projectLoc = jsonOptions.projectLoc;
61
			projectLoc = jsonOptions.projectLoc;
62
        	plugins = jsonOptions.plugins;
62
			plugins = jsonOptions.plugins;
63
			pluginsDir = jsonOptions.pluginsDir;
63
			pluginsDir = jsonOptions.pluginsDir;
64
			defNames = jsonOptions.libs;
64
			defNames = jsonOptions.libs;
65
			if(Array.isArray(jsonOptions.loadEagerly) && jsonOptions.loadEagerly.length > 0) {
66
				options.loadEagerly = jsonOptions.loadEagerly;
67
			}
65
			if (typeof jsonOptions.ecmaVersion === 'number') {
68
			if (typeof jsonOptions.ecmaVersion === 'number') {
66
				options.ecmaVersion = jsonOptions.ecmaVersion;
69
				options.ecmaVersion = jsonOptions.ecmaVersion;
67
			}
70
			}
Lines 82-102 Link Here
82
			}
85
			}
83
        }
86
        }
84
        if(typeof plugins !== 'object') {
87
        if(typeof plugins !== 'object') {
85
        	plugins = null;
88
			plugins = null;
86
        } else {
89
        } else {
87
        	Objects.mixin(options.plugins, plugins);
90
			Objects.mixin(options.plugins, plugins);
88
        }
91
        }
89
        if(!Array.isArray(defNames)) {
92
        if(!Array.isArray(defNames)) {
90
        	defNames = null;
93
			defNames = null;
91
        }
94
        }
92
        /**
95
        /**
93
         * A subtlety - if the user provides no plugins entry at all, they get all the defaults,
96
         * A subtlety - if the user provides no plugins entry at all, they get all the defaults,
94
         * if they provide an empty object they still need the required ones only for a default startup
97
         * if they provide an empty object they still need the required ones only for a default startup
95
         */
98
         */
96
        var requiredOnly = plugins && Object.keys(plugins).length < 1; 
99
        var requiredOnly = plugins && Object.keys(plugins).length < 1; 
100
        /**
101
         * @description Start the server with the default options
102
         * @param {Error} err The error object from the failed deferred
103
         */
97
        function defaultStartUp(err) {
104
        function defaultStartUp(err) {
98
        	options.plugins = defaultOptions.plugins.required;
105
        		options.plugins = defaultOptions.plugins.required;
99
        	if(!requiredOnly) {
106
        		if(!requiredOnly) {
100
				Objects.mixin(options.plugins, defaultOptions.plugins.optional);
107
				Objects.mixin(options.plugins, defaultOptions.plugins.optional);
101
			}
108
			}
102
			options.defs = defaultOptions.defs;
109
			options.defs = defaultOptions.defs;
Lines 105-144 Link Here
105
				post(Serialize.serializeError(err));
112
				post(Serialize.serializeError(err));
106
	        }
113
	        }
107
        }
114
        }
115
        /**
116
         * @description Starts the tern server wit the given options
117
         * @param {Object} options The options to start the server with
118
         */
108
        function startAndMessage(options) {
119
        function startAndMessage(options) {
109
        	ternserver = new Tern.Server(options);
120
			ternserver = new Tern.Server(options);
121
			if(Array.isArray(options.loadEagerly) && options.loadEagerly.length > 0) {
122
				options.loadEagerly.forEach(function(file) {
123
					ternserver.addFile(file);
124
				});
125
			}
110
			callback({request: 'start_server', state: "server_ready"}); //$NON-NLS-1$ //$NON-NLS-2$
126
			callback({request: 'start_server', state: "server_ready"}); //$NON-NLS-1$ //$NON-NLS-2$
111
        
127
		}
112
        }
128
		if((!plugins || requiredOnly) && !defNames) {
113
        if((!plugins || requiredOnly) && !defNames) {
114
			defaultStartUp();
129
			defaultStartUp();
115
        } else {
130
		} else {
116
			Deferred.all(loadPlugins(options.plugins, pluginsDir)).then(/* @callback */ function(plugins) {
131
			Deferred.all(loadPlugins(options.plugins, pluginsDir)).then(/* @callback */ function(plugins) {
117
				if(defNames) {
132
				if(defNames) {
118
					if(defNames.length < 1) {
133
					if(defNames.length < 1) {
119
						startAndMessage(options);
134
						startAndMessage(options);
120
					} else {
135
					} else {
121
						Deferred.all(loadDefs(defNames, projectLoc)).then(function(json) {
136
						Deferred.all(loadDefs(defNames, projectLoc)).then(function(json) {
122
								options.defs = json;
137
							options.defs = json;
123
								startAndMessage(options);
138
							startAndMessage(options);
124
							}, defaultStartUp);
139
						}, defaultStartUp);
125
					}
140
					}
126
				} else {
141
				} else {
127
					startAndMessage(options);
142
					startAndMessage(options);
128
				}
143
				}
129
	        }, defaultStartUp);
144
			}, defaultStartUp);
130
        }
145
		}
131
    }
146
	}
132
	post({request: "worker_ready"}); //$NON-NLS-1$
147
	post({request: "worker_ready"}); //$NON-NLS-1$
133
148
134
	var handlers = {
149
	var handlers = {
150
		/* start_server message handler */
135
		'start_server': function(args, callback){
151
		'start_server': function(args, callback){
136
			startServer(args.options, callback);	
152
			startServer(args.options, callback);	
137
		},
153
		},
154
		/* addFile message handler */
138
		'addFile': function(args, callback) {
155
		'addFile': function(args, callback) {
139
			ternserver.addFile(args.file, args.source);
156
			ternserver.addFile(args.file, args.source);
140
			callback({request: 'addFile'}); //$NON-NLS-1$
157
			callback({request: 'addFile'}); //$NON-NLS-1$
141
		},
158
		},
159
		/* completions message handler */
142
		'completions': function(args, callback) {
160
		'completions': function(args, callback) {
143
			if(ternserver) {
161
			if(ternserver) {
144
		       ternserver.request({
162
		       ternserver.request({
Lines 170-175 Link Here
170
		       callback({request: 'completions', message: Messages['failedToComputeProposalsNoServer']}); //$NON-NLS-1$
188
		       callback({request: 'completions', message: Messages['failedToComputeProposalsNoServer']}); //$NON-NLS-1$
171
		   }
189
		   }
172
		},
190
		},
191
		/* definition message handler */
173
		'definition': function(args, callback) {
192
		'definition': function(args, callback) {
174
			if(ternserver) {
193
			if(ternserver) {
175
		       ternserver.request({
194
		       ternserver.request({
Lines 194-199 Link Here
194
		       callback({request: 'definition', message: Messages['failedToComputeDeclNoServer']}); //$NON-NLS-1$
213
		       callback({request: 'definition', message: Messages['failedToComputeDeclNoServer']}); //$NON-NLS-1$
195
		   }
214
		   }
196
		},
215
		},
216
		/* delFile message handler */
197
		'delFile': function(args, callback) {
217
		'delFile': function(args, callback) {
198
			if(ternserver && typeof args.file === 'string') {
218
			if(ternserver && typeof args.file === 'string') {
199
	            ternserver.delFile(args.file);
219
	            ternserver.delFile(args.file);
Lines 202-207 Link Here
202
				callback({request: 'delFile', message: i18nUtil.formatMessage(Messages['failedDeleteRequest'], args.file)}); //$NON-NLS-1$
222
				callback({request: 'delFile', message: i18nUtil.formatMessage(Messages['failedDeleteRequest'], args.file)}); //$NON-NLS-1$
203
	        }
223
	        }
204
		},
224
		},
225
		/* documentation message handler */
205
		'documentation': function(args, callback) {
226
		'documentation': function(args, callback) {
206
			if(ternserver) {
227
			if(ternserver) {
207
		       ternserver.request({
228
		       ternserver.request({
Lines 225-233 Link Here
225
		       callback({request: 'documentation', message: Messages['failedToComputeDocNoServer']}); //$NON-NLS-1$
246
		       callback({request: 'documentation', message: Messages['failedToComputeDocNoServer']}); //$NON-NLS-1$
226
		   }
247
		   }
227
		},
248
		},
228
		/**
249
		/* environments message handler */
229
		 * @callback
230
		 */
231
		'environments': function(args, callback) {
250
		'environments': function(args, callback) {
232
			if(ternserver) {
251
			if(ternserver) {
233
		       ternserver.request({
252
		       ternserver.request({
Lines 248-253 Link Here
248
		       callback({request: 'environments', message: Messages['failedGetEnvsNoServer']}); //$NON-NLS-1$
267
		       callback({request: 'environments', message: Messages['failedGetEnvsNoServer']}); //$NON-NLS-1$
249
		   }
268
		   }
250
		},
269
		},
270
		/* implementation message handler */
251
		'implementation': function(args, callback) {
271
		'implementation': function(args, callback) {
252
			if(ternserver) {
272
			if(ternserver) {
253
		       ternserver.request({
273
		       ternserver.request({
Lines 272-280 Link Here
272
		       callback({request: 'implementation', message: Messages['failedToComputeImplNoServer']}); //$NON-NLS-1$
292
		       callback({request: 'implementation', message: Messages['failedToComputeImplNoServer']}); //$NON-NLS-1$
273
		   }
293
		   }
274
		},
294
		},
275
		/**
295
		/* installed_plugins message handler */
276
		 * @callback
277
		 */
278
		'installed_plugins': function(args, callback) {
296
		'installed_plugins': function(args, callback) {
279
			if(ternserver) {
297
			if(ternserver) {
280
		       ternserver.request({
298
		       ternserver.request({
Lines 295-303 Link Here
295
		       callback({request: 'installed_plugins', message: Messages['failedGetInstalledPluginsNoServer']}); //$NON-NLS-1$
313
		       callback({request: 'installed_plugins', message: Messages['failedGetInstalledPluginsNoServer']}); //$NON-NLS-1$
296
		   }
314
		   }
297
		},
315
		},
298
		/**
316
		/* installed_defs message handler */
299
		 * @callback
300
		 */
301
		'installed_defs': function(args, callback) {
317
		'installed_defs': function(args, callback) {
302
			if(ternserver) {
318
			if(ternserver) {
303
		       ternserver.request({
319
		       ternserver.request({
Lines 318-323 Link Here
318
		       callback({request: 'installed_defs', message: Messages['failedGetInstalledDefsNoServer']}); //$NON-NLS-1$
334
		       callback({request: 'installed_defs', message: Messages['failedGetInstalledDefsNoServer']}); //$NON-NLS-1$
319
		   }
335
		   }
320
		},
336
		},
337
		/* rename message handler */
321
		'rename': function(args, callback) {
338
		'rename': function(args, callback) {
322
			if(ternserver) {
339
			if(ternserver) {
323
		       ternserver.request({
340
		       ternserver.request({
Lines 341-346 Link Here
341
		       callback({request: 'rename', message: Messages['failedRenameNoServer']}); //$NON-NLS-1$
358
		       callback({request: 'rename', message: Messages['failedRenameNoServer']}); //$NON-NLS-1$
342
		   }
359
		   }
343
		},
360
		},
361
		/* type message handler */
344
		'type': function(args, callback) {
362
		'type': function(args, callback) {
345
			ternserver.request({
363
			ternserver.request({
346
		           query: {
364
		           query: {
Lines 356-361 Link Here
356
		               }
374
		               }
357
		           });
375
		           });
358
		},
376
		},
377
		/* checkRef message handler */
359
		'checkRef': function(args, callback) {
378
		'checkRef': function(args, callback) {
360
			ternserver.request({
379
			ternserver.request({
361
		           query: {
380
		           query: {
Lines 373-378 Link Here
373
		               }
392
		               }
374
		           });
393
		           });
375
		},
394
		},
395
		/* lint message handler */
376
		'lint': function(args, callback) {
396
		'lint': function(args, callback) {
377
			var query =
397
			var query =
378
				{
398
				{
Lines 401-406 Link Here
401
					}
421
					}
402
				});
422
				});
403
		},
423
		},
424
		/* outline message handler */
404
		'outline': function(args, callback) {
425
		'outline': function(args, callback) {
405
			ternserver.request({
426
			ternserver.request({
406
					query: {
427
					query: {
Lines 632-638 Link Here
632
		}
653
		}
633
		return _defs;
654
		return _defs;
634
    }
655
    }
635
    
656
636
    /**
657
    /**
637
     * @description Delegate to actually load a definition
658
     * @description Delegate to actually load a definition
638
     * @private
659
     * @private
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js (-7 / +12 lines)
Lines 1-6 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * @license
2
 * @license
3
 * Copyright (c) 2015 IBM Corporation and others.
3
 * Copyright (c) 2015, 2016 IBM Corporation and others.
4
 * All rights reserved. This program and the accompanying materials are made
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0
5
 * available under the terms of the Eclipse Public License v1.0
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
Lines 165-174 Link Here
165
		 * @param jsonOptions {Object} options to load into Tern
165
		 * @param jsonOptions {Object} options to load into Tern
166
		 */
166
		 */
167
		loadTernProjectOptions: function(jsonOptions) {
167
		loadTernProjectOptions: function(jsonOptions) {
168
			this.ternWorker.postMessage({request: "start_server", args: {options: jsonOptions}}); //$NON-NLS-1$
169
			if (Array.isArray(jsonOptions.loadEagerly)) {
168
			if (Array.isArray(jsonOptions.loadEagerly)) {
170
				var fileLoadPromises = [];
169
				var fileLoadPromises = [];
171
				this._fileLoadWarnings = [];
170
				this._fileLoadWarnings = [];
171
				var filesToLoad = [];
172
				for (var i = 0; i < jsonOptions.loadEagerly.length; i++) {
172
				for (var i = 0; i < jsonOptions.loadEagerly.length; i++) {
173
					var filename = jsonOptions.loadEagerly[i];
173
					var filename = jsonOptions.loadEagerly[i];
174
					var ext = 'js'; //$NON-NLS-1$
174
					var ext = 'js'; //$NON-NLS-1$
Lines 182-190 Link Here
182
							if (files.length > 1) {
182
							if (files.length > 1) {
183
								this._fileLoadWarnings.push(i18nUtil.formatMessage(Messages['multipleFileMatchesProblem'], _filename, files[0].location));
183
								this._fileLoadWarnings.push(i18nUtil.formatMessage(Messages['multipleFileMatchesProblem'], _filename, files[0].location));
184
							}
184
							}
185
							this.ternWorker.postMessage(
185
							filesToLoad.push(files[0].location);
186
								{request:'addFile', args:{file: files[0].location}} //$NON-NLS-1$
187
							);
188
						} else {
186
						} else {
189
							this._fileLoadWarnings.push(i18nUtil.formatMessage(Messages['noFileMatchProblem'], _filename));
187
							this._fileLoadWarnings.push(i18nUtil.formatMessage(Messages['noFileMatchProblem'], _filename));
190
						}
188
						}
Lines 193-199 Link Here
193
				if (!this._hasValidationProblem){
191
				if (!this._hasValidationProblem){
194
					this.registry.getService("orion.page.message").setProgressMessage(Messages['fileMatchProgress']); //$NON-NLS-1$
192
					this.registry.getService("orion.page.message").setProgressMessage(Messages['fileMatchProgress']); //$NON-NLS-1$
195
				}
193
				}
196
				return Deferred.all(fileLoadPromises).then(function(){
194
				var currentOptions = jsonOptions;
195
				currentOptions.loadEagerly = filesToLoad;
196
				if(fileLoadPromises.length > 0) {
197
					Deferred.all(fileLoadPromises).then(function(){
197
					if (!this._hasValidationProblem){  // Don't hide validation warnings
198
					if (!this._hasValidationProblem){  // Don't hide validation warnings
198
						this.registry.getService("orion.page.message").close(); //$NON-NLS-1$
199
						this.registry.getService("orion.page.message").close(); //$NON-NLS-1$
199
						if (this._fileLoadWarnings.length > 0){
200
						if (this._fileLoadWarnings.length > 0){
Lines 208-214 Link Here
208
						}
209
						}
209
					}
210
					}
210
					this._fileLoadWarnings = [];
211
					this._fileLoadWarnings = [];
212
					this.ternWorker.postMessage({request: "start_server", args: {options: currentOptions}}); //$NON-NLS-1$
211
				}.bind(this));
213
				}.bind(this));
214
				} else {
215
					this.ternWorker.postMessage({request: "start_server", args: {options: currentOptions}}); //$NON-NLS-1$
216
				}
212
			}
217
			}
213
		},
218
		},
214
		
219
		
Lines 240-243 Link Here
240
	return {
245
	return {
241
		TernProjectManager : TernProjectManager
246
		TernProjectManager : TernProjectManager
242
	};
247
	};
243
});
248
});

Return to bug 488530