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 465610 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js (-39 / +36 lines)
Lines 117-123 Link Here
117
    			this.worker = new Worker(wUrl.href);
117
    			this.worker = new Worker(wUrl.href);
118
    			this.worker.onmessage = onMessage;
118
    			this.worker.onmessage = onMessage;
119
    			this.worker.onerror = onError;
119
    			this.worker.onerror = onError;
120
    			this.worker.postMessage('');
120
    			this.worker.postMessage('start_server'); //$NON-NLS-1$
121
    	//	}
121
    	//	}
122
    	}
122
    	}
123
    	
123
    	
Lines 134-139 Link Here
134
    	};
134
    	};
135
    	
135
    	
136
    	var prefService = core.serviceRegistry.getService("orion.core.preference"); //$NON-NLS-1$
136
    	var prefService = core.serviceRegistry.getService("orion.core.preference"); //$NON-NLS-1$
137
    	/**
138
    	 * Object of contributed environments
139
    	 * 
140
    	 * TODO will need to listen to updated tern plugin settings once enbaled to clear this cache
141
    	 */
142
    	var contributedEnvs;
137
    	
143
    	
138
    	// Start the worker
144
    	// Start the worker
139
    	var ternWorker = new WrappedWorker("ternWorker.js",  //$NON-NLS-1$
145
    	var ternWorker = new WrappedWorker("ternWorker.js",  //$NON-NLS-1$
Lines 172-189 Link Here
172
		    					}
178
		    					}
173
		    					break;
179
		    					break;
174
		    				}
180
		    				}
181
		    				case 'installed_plugins': {
182
		    					var plugins = _d.plugins;
183
		    					return prefService ? prefService.getPreferences("/cm/configurations").then(function(prefs){ //$NON-NLS-1$
184
									var props = prefs.get("tern/plugins"); //$NON-NLS-1$
185
									if (!props) {
186
										props = Object.create(null);
187
									} else if(typeof(props) === 'string') {
188
										props = JSON.parse(props);
189
									}
190
									var keys = Object.keys(plugins);
191
									for(var i = 0; i < keys.length; i++) {
192
										var key = keys[i];
193
										props[key] = plugins[key];
194
									}
195
									prefs.put("tern/plugins", JSON.stringify(props)); //$NON-NLS-1$
196
									prefs.sync(true);
197
								}) : new Deferred().resolve();
198
								break;
199
		    				}
200
		    				case 'environments': {
201
		    					contributedEnvs = _d.envs;
202
		    					break;
203
		    				}
175
		    			}
204
		    			}
176
		    		}
205
		    		} else if(typeof(evnt.data) === 'string') {
206
			    		if(evnt.data === 'server_ready') {
207
			    			ternWorker.postMessage({request: 'installed_plugins'}); //$NON-NLS-1$
208
		    				ternWorker.postMessage({request: 'environments'}); //$NON-NLS-1$
209
			    		}
210
			    	}
177
		    	}, 
211
		    	}, 
178
		    	function(err) {
212
		    	function(err) {
179
		    		Logger.log(err);	
213
		    		Logger.log(err);	
180
		    	});
214
		    	});
181
    	/**
182
    	 * Object of contributed environments
183
    	 * 
184
    	 * TODO will need to listen to updated tern plugin settings once enbaled to clear this cache
185
    	 */
186
    	var contributedEnvs;
187
    	
215
    	
188
    	/**
216
    	/**
189
	     * @description Queries the Tern server to return all contributed environment names from the installed plugins
217
	     * @description Queries the Tern server to return all contributed environment names from the installed plugins
Lines 209-245 Link Here
209
    		}
237
    		}
210
    		return envDeferred;
238
    		return envDeferred;
211
    	}
239
    	}
212
    	
213
    	//this handler is for ferrying preferences to and from the Tern server
214
    	ternWorker.addEventListener('message', function(evnt) {
215
			if(typeof(evnt.data) === 'object') {
216
    			var _d  = evnt.data;
217
    			switch(_d.request) {
218
    				case 'installed_plugins': {
219
    					var plugins = _d.plugins;
220
    					return prefService ? prefService.getPreferences("/cm/configurations").then(function(prefs){ //$NON-NLS-1$
221
							var props = prefs.get("tern/plugins"); //$NON-NLS-1$
222
							if (!props) {
223
								props = Object.create(null);
224
							} else if(typeof(props) === 'string') {
225
								props = JSON.parse(props);
226
							}
227
							var keys = Object.keys(plugins);
228
							for(var i = 0; i < keys.length; i++) {
229
								var key = keys[i];
230
								props[key] = plugins[key];
231
							}
232
							prefs.put("tern/plugins", JSON.stringify(props)); //$NON-NLS-1$
233
							prefs.sync(true);
234
						}) : new Deferred().resolve();
235
    				}
236
    			}
237
	    	} else if(typeof(evnt.data) === 'string') {
238
	    		if(evnt.data === 'server_ready') {
239
	    			ternWorker.postMessage({request: 'installed_plugins'}); //$NON-NLS-1$
240
	    		}
241
	    	}
242
    	}, false);
243
    	
240
    	
244
    	provider.registerService("orion.edit.contentassist", new TernAssist.TernContentAssist(astManager, ternWorker, getEnvironments),  //$NON-NLS-1$
241
    	provider.registerService("orion.edit.contentassist", new TernAssist.TernContentAssist(astManager, ternWorker, getEnvironments),  //$NON-NLS-1$
245
    			{
242
    			{

Return to bug 465610