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

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js (-45 / +37 lines)
Lines 99-107 Link Here
99
99
100
		var ternReady = false,
100
		var ternReady = false,
101
			workerReady = false,
101
			workerReady = false,
102
			startCount = 0,
102
			pendingStart,
103
			TRACE,
103
			TRACE = localStorage.js_message_trace === "true",
104
			pendingStart = Object.create(null),
105
			messageQueue = [], // for all other requests
104
			messageQueue = [], // for all other requests
106
			modifyQueue = []; // for add and removes only
105
			modifyQueue = []; // for add and removes only
107
		
106
		
Lines 130-149 Link Here
130
	 * @callback 
129
	 * @callback 
131
	 */
130
	 */
132
	WrappedWorker.prototype.postMessage = function(msg, f) {
131
	WrappedWorker.prototype.postMessage = function(msg, f) {
133
		var starting = msg.request === "start_server";
132
		if(ternReady || msg.request === 'read') { //configuration reads can happen while the server is starting
134
		if(starting) {
135
			if(!workerReady) {
136
				pendingStart.msg = msg;
137
				pendingStart.f = f;
138
				return; //don't queue start_server requests
139
			}
140
			if(startCount > 0 && msg.args.initial) {
141
				return;
142
			}
143
			startCount++;
144
			ternReady = false;
145
		}
146
		if(ternReady || starting || msg.request === 'read') { //configuration reads can happen while the server is starting
147
			if(msg !== null && typeof msg === 'object') {
133
			if(msg !== null && typeof msg === 'object') {
148
				if(typeof msg.messageID !== 'number' && typeof msg.ternID !== 'number') {
134
				if(typeof msg.messageID !== 'number' && typeof msg.ternID !== 'number') {
149
					//don't overwrite an id from a tern-side request
135
					//don't overwrite an id from a tern-side request
Lines 152-168 Link Here
152
				}
138
				}
153
			}
139
			}
154
			if(TRACE) {
140
			if(TRACE) {
155
				console.log("postMessage ("+this.messageId+") - SENT "+JSON.stringify(msg)); //$NON-NLS-1$ //$NON-NLS-2$
141
				console.log("postMessage ("+this.messageId+") - SENT "+msg.request); //$NON-NLS-1$ //$NON-NLS-2$
156
			}
142
			}
157
			this.worker.postMessage(msg);
143
			this.worker.postMessage(msg);
144
		} else if(msg.request === "start_server") {
145
			if(!workerReady) {
146
				pendingStart = {msg: msg, f: f};
147
			} else {
148
				if(TRACE) {
149
					console.log("postMessage ("+this.messageId+") - START "+JSON.stringify(msg.args)); //$NON-NLS-1$ //$NON-NLS-2$
150
				}
151
				this.worker.postMessage(msg);
152
			}
158
		} else if (msg.request === "addFile" || msg.request === "delFile") {
153
		} else if (msg.request === "addFile" || msg.request === "delFile") {
159
			if(TRACE) {
154
			if(TRACE) {
160
				console.log("postMessage ("+this.messageId+") - MODIFY QUEUED: "+JSON.stringify(msg)); //$NON-NLS-1$ //$NON-NLS-2$
155
				console.log("postMessage ("+this.messageId+") - MODIFY QUEUED: "+msg.request); //$NON-NLS-1$ //$NON-NLS-2$
161
			}
156
			}
162
			modifyQueue.push({msg: msg, f: f});
157
			modifyQueue.push({msg: msg, f: f});
163
		} else {
158
		} else {
164
			if(TRACE) {
159
			if(TRACE) {
165
				console.log("postMessage ("+this.messageId+") - MESSAGE QUEUED: "+JSON.stringify(msg)); //$NON-NLS-1$ //$NON-NLS-2$
160
				console.log("postMessage ("+this.messageId+") - MESSAGE QUEUED: "+msg.request); //$NON-NLS-1$ //$NON-NLS-2$
166
			}
161
			}
167
			messageQueue.push({msg: msg, f: f});
162
			messageQueue.push({msg: msg, f: f});
168
		}
163
		}
Lines 184-203 Link Here
184
			 */
179
			 */
185
			'worker_ready': function(response) {
180
			'worker_ready': function(response) {
186
				if(TRACE) {
181
				if(TRACE) {
187
					console.log("worker_ready ("+ternWorker.messageId+"): "+JSON.stringify(response)); //$NON-NLS-1$ //$NON-NLS-2$
182
					console.log("worker_ready ("+ternWorker.messageId+"): "+response.request); //$NON-NLS-1$ //$NON-NLS-2$
188
				}
183
				}
189
				workerReady = true;
184
				workerReady = true;
190
				if (!pendingStart.msg || !pendingStart.msg.request){
185
				if(pendingStart) {
191
					pendingStart.msg = {request: "start_server", args: {initial: true}}; //$NON-NLS-1$
186
					ternWorker.postMessage(pendingStart.msg, pendingStart.f);
187
					pendingStart = null;
192
				}
188
				}
193
				ternWorker.postMessage(pendingStart.msg, pendingStart.f);
194
			},
189
			},
195
			/**
190
			/**
196
			 * @callback
191
			 * @callback
197
			 */
192
			 */
198
			'start_server': function(response) {
193
			'start_server': function(response) {
199
				if(TRACE) {
194
				if(TRACE) {
200
					console.log("server_ready ("+ternWorker.messageId+"): "+JSON.stringify(response)); //$NON-NLS-1$ //$NON-NLS-2$
195
					console.log("server_ready ("+ternWorker.messageId+"): "+response.request); //$NON-NLS-1$ //$NON-NLS-2$
201
				}
196
				}
202
				serverReady();
197
				serverReady();
203
			}
198
			}
Lines 292-319 Link Here
292
		 * @since 10.0
287
		 * @since 10.0
293
		 */
288
		 */
294
		function serverReady() {
289
		function serverReady() {
295
			startCount--;
290
			ternReady = true;
296
			if(startCount === 0) {
291
			// process all add/remove first
297
				ternReady = true;
292
			for(var i = 0, len = modifyQueue.length; i < len; i++) {
298
				// process all add/remove first
293
				var item = modifyQueue[i];
299
				for(var i = 0, len = modifyQueue.length; i < len; i++) {
294
				if(TRACE) {
300
					var item = modifyQueue[i];
295
					console.log("clearing MODIFY queue: "+item.msg.request); //$NON-NLS-1$
301
					if(TRACE) {
302
						console.log("clearing MODIFY queue: "+JSON.stringify(item.msg)); //$NON-NLS-1$
303
					}
304
					ternWorker.postMessage(item.msg, item.f);
305
				}
296
				}
306
				modifyQueue = [];
297
				ternWorker.postMessage(item.msg, item.f);
307
				// process remaining pending requests
308
				for(i = 0, len = messageQueue.length; i < len; i++) {
309
					item = messageQueue[i];
310
					if(TRACE) {
311
						console.log("clearing MESSAGE queue: "+JSON.stringify(item.msg)); //$NON-NLS-1$
312
					}
313
					ternWorker.postMessage(item.msg, item.f);
314
				}
315
				messageQueue = [];
316
			}
298
			}
299
			modifyQueue = [];
300
			// process remaining pending requests
301
			for(i = 0, len = messageQueue.length; i < len; i++) {
302
				item = messageQueue[i];
303
				if(TRACE) {
304
					console.log("clearing MESSAGE queue: "+item.msg.request); //$NON-NLS-1$
305
				}
306
				ternWorker.postMessage(item.msg, item.f);
307
			}
308
			messageQueue = [];
317
		}
309
		}
318
310
319
    	/**
311
    	/**
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js (-6 / +9 lines)
Lines 241-256 Link Here
241
					this.projectLocation = project.Location;
241
					this.projectLocation = project.Location;
242
					this.scriptResolver.setSearchLocation(project.Location);
242
					this.scriptResolver.setSearchLocation(project.Location);
243
					var c = project.Children;
243
					var c = project.Children;
244
					var tpf;
244
					for(var i = 0, len = c.length; i < len; i++) {
245
					for(var i = 0, len = c.length; i < len; i++) {
245
						if(".tern-project" === c[i].Name) {
246
						if(".tern-project" === c[i].Name) {
246
							this.currentFile = c[i].Location;
247
							tpf = c[i].Location;
247
							this.starting();
248
							break;
248
							return this.parseTernJSON(this.currentFile).then(function(jsonOptions){
249
								this.json = jsonOptions;
250
								return this.loadTernProjectOptions(jsonOptions);
251
							}.bind(this));
252
						}
249
						}
253
					}
250
					}
251
					if(typeof tpf === 'string') {
252
						this.refresh(tpf);
253
					} else {
254
						//no .tern-project - request default startup
255
						this.loadTernProjectOptions();
256
					}
254
				}
257
				}
255
			}
258
			}
256
		}
259
		}

Return to bug 488906