Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit d96d73d

Browse files
committed
cleanup jslint warnings
1 parent 3eee0be commit d96d73d

File tree

6 files changed

+203
-198
lines changed

6 files changed

+203
-198
lines changed

src/extensions/default/JavaScriptCodeHints/HintUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ define(function (require, exports, module) {
9494
function splitPath(path) {
9595
var index = path.lastIndexOf("/"),
9696
dir = path.substring(0, index),
97-
file = path.substring(index+1, path.length);
97+
file = path.substring(index + 1, path.length);
9898

9999
return {dir: dir, file: file };
100100
}

src/extensions/default/JavaScriptCodeHints/ScopeManager.js

Lines changed: 134 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ define(function (require, exports, module) {
124124
}
125125
}
126126

127+
/**
128+
* Send a message to the tern worker - if the worker is being initialized,
129+
* the message will not be posted until initialization is complete
130+
*/
131+
function postMessage(msg) {
132+
ternPromise.done(function (ternWorker) {
133+
ternWorker.postMessage(msg);
134+
});
135+
}
136+
137+
127138
/**
128139
* Get a Promise for the definition from TernJS, for the file & offset passed in.
129140
* @return {jQuery.Promise} - a promise that will resolve to definition when
@@ -132,10 +143,10 @@ define(function (require, exports, module) {
132143
function getJumptoDef(dir, file, offset, text) {
133144
postMessage({
134145
type: HintUtils.TERN_JUMPTODEF_MSG,
135-
dir:dir,
136-
file:file,
137-
offset:offset,
138-
text:text
146+
dir: dir,
147+
file: file,
148+
offset: offset,
149+
text: text
139150
});
140151

141152
var $deferredJump = $.Deferred();
@@ -160,7 +171,7 @@ define(function (require, exports, module) {
160171

161172
var ternPromise = getJumptoDef(dir, file, offset, document.getText());
162173

163-
return {promise:ternPromise};
174+
return {promise: ternPromise};
164175
}
165176

166177
/**
@@ -176,74 +187,35 @@ define(function (require, exports, module) {
176187

177188
pendingTernRequests[file] = null;
178189

179-
if( $deferredJump ) {
190+
if ($deferredJump) {
180191
$deferredJump.resolveWith(null, [response]);
181192
}
182193
}
183-
194+
184195
/**
185-
* Request hints from Tern.
196+
* Add a pending request waiting for the tern-worker to complete.
186197
*
187-
* Note that successive calls to getScope may return the same objects, so
188-
* clients that wish to modify those objects (e.g., by annotating them based
189-
* on some temporary context) should copy them first. See, e.g.,
190-
* Session.getHints().
191-
*
192-
* @param {Document} document - the document for which scope info is
193-
* desired
194-
* @param {number} offset - the offset into the document at which scope
195-
* info is desired
196-
* @return {jQuery.Promise} - The promise will not complete until the tern
197-
* hints have completed.
198+
* @param {string} file - the name of the file
199+
* @param {string} type - the type of request
200+
* @param {jQuery.Deferred} deferredRequest - the $.Deferred object to save
198201
*/
199-
function requestHints(session, document, offset) {
200-
var path = document.file.fullPath,
201-
split = HintUtils.splitPath(path),
202-
dir = split.dir,
203-
file = split.file;
204-
205-
var $deferredHints = $.Deferred(),
206-
hintPromise,
207-
fnTypePromise,
208-
propsPromise;
209-
210-
hintPromise = getTernHints(dir, file, offset, document.getText());
211-
var sessionType = session.getType();
212-
if (sessionType.property) {
213-
propsPromise = getTernProperties(dir, file, offset, document.getText());
202+
function addPendingRequest(file, offset, type) {
203+
var requests,
204+
key = file + "@" + offset,
205+
$deferredRequest;
206+
if (Object.prototype.hasOwnProperty.call(pendingTernRequests, key)) {
207+
requests = pendingTernRequests[key];
214208
} else {
215-
var $propsDeferred = $.Deferred();
216-
propsPromise = $propsDeferred.promise();
217-
$propsDeferred.resolveWith(null);
209+
requests = {};
210+
pendingTernRequests[key] = requests;
218211
}
219212

220-
if( sessionType.showFunctionType ) {
221-
// Show function sig
222-
fnTypePromise = getTernFunctionType(dir, file, sessionType.functionCallPos, offset, document.getText());
213+
if (Object.prototype.hasOwnProperty.call(requests, type)) {
214+
$deferredRequest = requests[type];
223215
} else {
224-
var $fnTypeDeferred = $.Deferred();
225-
fnTypePromise = $fnTypeDeferred.promise();
226-
$fnTypeDeferred.resolveWith(null);
216+
requests[type] = $deferredRequest = $.Deferred();
227217
}
228-
$.when(hintPromise, fnTypePromise, propsPromise).done(
229-
function(completions, fnType, properties){
230-
session.setTernHints(completions);
231-
session.setFnType(fnType);
232-
session.setTernProperties(properties);
233-
234-
$deferredHints.resolveWith(null);
235-
});
236-
return {promise:$deferredHints.promise()};
237-
}
238-
239-
/**
240-
* Send a message to the tern worker - if the worker is being initialized,
241-
* the message will not be posted until initialization is complete
242-
*/
243-
function postMessage(msg) {
244-
ternPromise.done(function (ternWorker){
245-
ternWorker.postMessage(msg);
246-
});
218+
return $deferredRequest.promise();
247219
}
248220

249221
/**
@@ -254,13 +226,13 @@ define(function (require, exports, module) {
254226
function getTernHints(dir, file, offset, text) {
255227
postMessage({
256228
type: HintUtils.TERN_COMPLETIONS_MSG,
257-
dir:dir,
258-
file:file,
259-
offset:offset,
260-
text:text
229+
dir: dir,
230+
file: file,
231+
offset: offset,
232+
text: text
261233
});
262234

263-
return addPendingRequest(file, offset, HintUtils.TERN_COMPLETIONS_MSG);
235+
return addPendingRequest(file, offset, HintUtils.TERN_COMPLETIONS_MSG);
264236
}
265237

266238
/**
@@ -273,10 +245,10 @@ define(function (require, exports, module) {
273245
function getTernProperties(dir, file, offset, text) {
274246
postMessage({
275247
type: HintUtils.TERN_GET_PROPERTIES_MSG,
276-
dir:dir,
277-
file:file,
248+
dir: dir,
249+
file: file,
278250
offset: offset,
279-
text:text
251+
text: text
280252
});
281253

282254
return addPendingRequest(file, offset, HintUtils.TERN_GET_PROPERTIES_MSG);
@@ -289,55 +261,86 @@ define(function (require, exports, module) {
289261
function getTernFunctionType(dir, file, pos, offset, text) {
290262
postMessage({
291263
type: HintUtils.TERN_CALLED_FUNC_TYPE_MSG,
292-
dir:dir,
293-
file:file,
294-
pos:pos,
295-
offset:offset,
296-
text:text
264+
dir: dir,
265+
file: file,
266+
pos: pos,
267+
offset: offset,
268+
text: text
297269
});
298270

299-
return addPendingRequest(file, offset, HintUtils.TERN_CALLED_FUNC_TYPE_MSG);
271+
return addPendingRequest(file, offset, HintUtils.TERN_CALLED_FUNC_TYPE_MSG);
300272
}
301273

274+
302275
/**
303-
* Add a pending request waiting for the tern-worker to complete.
276+
* Request hints from Tern.
304277
*
305-
* @param {string} file - the name of the file
306-
* @param {string} type - the type of request
307-
* @param {jQuery.Deferred} deferredRequest - the $.Deferred object to save
308-
*/
309-
function addPendingRequest(file, offset, type) {
310-
var requests,
311-
key = file+"@"+offset,
312-
$deferredRequest;
313-
if( Object.prototype.hasOwnProperty.call(pendingTernRequests, key) ) {
314-
requests = pendingTernRequests[key];
278+
* Note that successive calls to getScope may return the same objects, so
279+
* clients that wish to modify those objects (e.g., by annotating them based
280+
* on some temporary context) should copy them first. See, e.g.,
281+
* Session.getHints().
282+
*
283+
* @param {Document} document - the document for which scope info is
284+
* desired
285+
* @param {number} offset - the offset into the document at which scope
286+
* info is desired
287+
* @return {jQuery.Promise} - The promise will not complete until the tern
288+
* hints have completed.
289+
*/
290+
function requestHints(session, document, offset) {
291+
var path = document.file.fullPath,
292+
split = HintUtils.splitPath(path),
293+
dir = split.dir,
294+
file = split.file;
295+
296+
var $deferredHints = $.Deferred(),
297+
hintPromise,
298+
fnTypePromise,
299+
propsPromise;
300+
301+
hintPromise = getTernHints(dir, file, offset, document.getText());
302+
var sessionType = session.getType();
303+
if (sessionType.property) {
304+
propsPromise = getTernProperties(dir, file, offset, document.getText());
315305
} else {
316-
requests = {};
317-
pendingTernRequests[key] = requests;
306+
var $propsDeferred = $.Deferred();
307+
propsPromise = $propsDeferred.promise();
308+
$propsDeferred.resolveWith(null);
318309
}
319310

320-
if (Object.prototype.hasOwnProperty.call(requests, type)) {
321-
$deferredRequest = requests[type];
311+
if (sessionType.showFunctionType) {
312+
// Show function sig
313+
fnTypePromise = getTernFunctionType(dir, file, sessionType.functionCallPos, offset, document.getText());
322314
} else {
323-
requests[type] = $deferredRequest = $.Deferred();
315+
var $fnTypeDeferred = $.Deferred();
316+
fnTypePromise = $fnTypeDeferred.promise();
317+
$fnTypeDeferred.resolveWith(null);
324318
}
325-
return $deferredRequest.promise();
326-
}
327-
319+
$.when(hintPromise, fnTypePromise, propsPromise).done(
320+
function (completions, fnType, properties) {
321+
session.setTernHints(completions);
322+
session.setFnType(fnType);
323+
session.setTernProperties(properties);
324+
325+
$deferredHints.resolveWith(null);
326+
}
327+
);
328+
return {promise: $deferredHints.promise()};
329+
}
330+
328331
/**
329332
* Get any pending $.Deferred object waiting on the specified file and request type
330333
* @param {string} file - the file
331334
* @param {string} type - the type of request
332335
* @param {jQuery.Deferred} - the $.Deferred for the request
333-
*/
336+
*/
334337
function getPendingRequest(file, offset, type) {
335-
var key = file +"@"+offset;
336-
if( Object.prototype.hasOwnProperty.call(pendingTernRequests, key) ) {
338+
var key = file + "@" + offset;
339+
if (Object.prototype.hasOwnProperty.call(pendingTernRequests, key)) {
337340
var requests = pendingTernRequests[key];
338-
return requests[type];
339-
}
340-
}
341+
return requests[type];
342+
}
343+
}
341344

342345
/**
343346
* Handle the response from the tern web worker when
@@ -352,17 +355,17 @@ define(function (require, exports, module) {
352355
completions = response.completions,
353356
properties = response.properties,
354357
fnType = response.fnType,
355-
type = response.type,
358+
type = response.type,
356359
$deferredHints = getPendingRequest(file, offset, type);
357360

358-
if( $deferredHints ) {
359-
if( completions ) {
361+
if ($deferredHints) {
362+
if (completions) {
360363
$deferredHints.resolveWith(null, [completions]);
361-
} else if ( properties ) {
364+
} else if (properties) {
362365
$deferredHints.resolveWith(null, [properties]);
363-
} else if ( fnType ) {
366+
} else if (fnType) {
364367
$deferredHints.resolveWith(null, [fnType]);
365-
}
368+
}
366369
}
367370
}
368371

@@ -384,33 +387,33 @@ define(function (require, exports, module) {
384387

385388
function replyWith(name, txt) {
386389
postMessage({
387-
type:HintUtils.TERN_GET_FILE_MSG,
388-
file:name,
389-
text:txt
390+
type: HintUtils.TERN_GET_FILE_MSG,
391+
file: name,
392+
text: txt
390393
});
391394
}
392395

393396
var name = request.file;
394-
DocumentManager.getDocumentForPath(rootTernDir + name).done(function(document){
397+
DocumentManager.getDocumentForPath(rootTernDir + name).done(function (document) {
395398
resolvedFiles[name] = rootTernDir + name;
396399
replyWith(name, document.getText());
397400
})
398-
.fail(function(){
399-
if (projectRoot) {
400-
// Try relative to project root
401-
DocumentManager.getDocumentForPath(projectRoot + name).done(function(document) {
402-
resolvedFiles[name] = projectRoot + name;
403-
replyWith(name, document.getText());
404-
})
405-
.fail(function(){
401+
.fail(function () {
402+
if (projectRoot) {
403+
// Try relative to project root
404+
DocumentManager.getDocumentForPath(projectRoot + name).done(function (document) {
405+
resolvedFiles[name] = projectRoot + name;
406+
replyWith(name, document.getText());
407+
})
408+
.fail(function () {
409+
replyWith(name, "");
410+
});
411+
} else {
412+
// Need to send something back to tern - it will wait
413+
// until all the files have been retrieved before doing its calculations
406414
replyWith(name, "");
407-
});
408-
} else {
409-
// Need to send something back to tern - it will wait
410-
// until all the files have been retrieved before doing its calculations
411-
replyWith(name, "");
412-
}
413-
});
415+
}
416+
});
414417
}
415418

416419
/**
@@ -475,15 +478,15 @@ define(function (require, exports, module) {
475478
var response = e.data,
476479
type = response.type;
477480

478-
if( type === HintUtils.TERN_COMPLETIONS_MSG ||
479-
type === HintUtils.TERN_CALLED_FUNC_TYPE_MSG ||
480-
type === HintUtils.TERN_GET_PROPERTIES_MSG) {
481+
if (type === HintUtils.TERN_COMPLETIONS_MSG ||
482+
type === HintUtils.TERN_CALLED_FUNC_TYPE_MSG ||
483+
type === HintUtils.TERN_GET_PROPERTIES_MSG) {
481484
// handle any completions the worker calculated
482485
handleTernCompletions(response);
483-
} else if ( type === HintUtils.TERN_GET_FILE_MSG ) {
486+
} else if (type === HintUtils.TERN_GET_FILE_MSG) {
484487
// handle a request for the contents of a file
485488
handleTernGetFile(response);
486-
} else if ( type === HintUtils.TERN_JUMPTODEF_MSG ) {
489+
} else if (type === HintUtils.TERN_JUMPTODEF_MSG) {
487490
handleJumptoDef(response);
488491
} else {
489492
console.log("Worker: " + (response.log || response));

0 commit comments

Comments
 (0)