mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
cleanup jslint warnings
This commit is contained in:
1 parent
3eee0bef6f
commit
d96d73d895
6 files changed
+208
-203
No files matched your search
@@ -94,7 +94,7 @@ define(function (require, exports, module) {
|
||||
function splitPath(path) {
|
||||
var index = path.lastIndexOf("/"),
|
||||
dir = path.substring(0, index),
|
||||
file = path.substring(index+1, path.length);
|
||||
file = path.substring(index + 1, path.length);
|
||||
|
||||
return {dir: dir, file: file };
|
||||
}
|
||||
|
||||
@@ -124,6 +124,17 @@ define(function (require, exports, module) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the tern worker - if the worker is being initialized,
|
||||
* the message will not be posted until initialization is complete
|
||||
*/
|
||||
function postMessage(msg) {
|
||||
ternPromise.done(function (ternWorker) {
|
||||
ternWorker.postMessage(msg);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Promise for the definition from TernJS, for the file & offset passed in.
|
||||
* @return {jQuery.Promise} - a promise that will resolve to definition when
|
||||
@@ -132,10 +143,10 @@ define(function (require, exports, module) {
|
||||
function getJumptoDef(dir, file, offset, text) {
|
||||
postMessage({
|
||||
type: HintUtils.TERN_JUMPTODEF_MSG,
|
||||
dir:dir,
|
||||
file:file,
|
||||
offset:offset,
|
||||
text:text
|
||||
dir: dir,
|
||||
file: file,
|
||||
offset: offset,
|
||||
text: text
|
||||
});
|
||||
|
||||
var $deferredJump = $.Deferred();
|
||||
@@ -160,7 +171,7 @@ define(function (require, exports, module) {
|
||||
|
||||
var ternPromise = getJumptoDef(dir, file, offset, document.getText());
|
||||
|
||||
return {promise:ternPromise};
|
||||
return {promise: ternPromise};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,10 +187,90 @@ define(function (require, exports, module) {
|
||||
|
||||
pendingTernRequests[file] = null;
|
||||
|
||||
if( $deferredJump ) {
|
||||
if ($deferredJump) {
|
||||
$deferredJump.resolveWith(null, [response]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pending request waiting for the tern-worker to complete.
|
||||
*
|
||||
* @param {string} file - the name of the file
|
||||
* @param {string} type - the type of request
|
||||
* @param {jQuery.Deferred} deferredRequest - the $.Deferred object to save
|
||||
*/
|
||||
function addPendingRequest(file, offset, type) {
|
||||
var requests,
|
||||
key = file + "@" + offset,
|
||||
$deferredRequest;
|
||||
if (Object.prototype.hasOwnProperty.call(pendingTernRequests, key)) {
|
||||
requests = pendingTernRequests[key];
|
||||
} else {
|
||||
requests = {};
|
||||
pendingTernRequests[key] = requests;
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(requests, type)) {
|
||||
$deferredRequest = requests[type];
|
||||
} else {
|
||||
requests[type] = $deferredRequest = $.Deferred();
|
||||
}
|
||||
return $deferredRequest.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for the completions from TernJS, for the file & offset passed in.
|
||||
* @return {jQuery.Promise} - a promise that will resolve to an array of completions when
|
||||
* it is done
|
||||
*/
|
||||
function getTernHints(dir, file, offset, text) {
|
||||
postMessage({
|
||||
type: HintUtils.TERN_COMPLETIONS_MSG,
|
||||
dir: dir,
|
||||
file: file,
|
||||
offset: offset,
|
||||
text: text
|
||||
});
|
||||
|
||||
return addPendingRequest(file, offset, HintUtils.TERN_COMPLETIONS_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for all of the known properties from TernJS, for the directory and file.
|
||||
* The properties will be used as guesses in tern.
|
||||
*
|
||||
* @return {jQuery.Promise} - a promise that will resolve to an array of properties when
|
||||
* it is done
|
||||
*/
|
||||
function getTernProperties(dir, file, offset, text) {
|
||||
postMessage({
|
||||
type: HintUtils.TERN_GET_PROPERTIES_MSG,
|
||||
dir: dir,
|
||||
file: file,
|
||||
offset: offset,
|
||||
text: text
|
||||
});
|
||||
|
||||
return addPendingRequest(file, offset, HintUtils.TERN_GET_PROPERTIES_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for the function type from TernJS.
|
||||
* @return {jQuery.Promise} - a promise that will resolve to the function type of the function being called.
|
||||
*/
|
||||
function getTernFunctionType(dir, file, pos, offset, text) {
|
||||
postMessage({
|
||||
type: HintUtils.TERN_CALLED_FUNC_TYPE_MSG,
|
||||
dir: dir,
|
||||
file: file,
|
||||
pos: pos,
|
||||
offset: offset,
|
||||
text: text
|
||||
});
|
||||
|
||||
return addPendingRequest(file, offset, HintUtils.TERN_CALLED_FUNC_TYPE_MSG);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Request hints from Tern.
|
||||
@@ -217,127 +308,39 @@ define(function (require, exports, module) {
|
||||
$propsDeferred.resolveWith(null);
|
||||
}
|
||||
|
||||
if( sessionType.showFunctionType ) {
|
||||
if (sessionType.showFunctionType) {
|
||||
// Show function sig
|
||||
fnTypePromise = getTernFunctionType(dir, file, sessionType.functionCallPos, offset, document.getText());
|
||||
fnTypePromise = getTernFunctionType(dir, file, sessionType.functionCallPos, offset, document.getText());
|
||||
} else {
|
||||
var $fnTypeDeferred = $.Deferred();
|
||||
fnTypePromise = $fnTypeDeferred.promise();
|
||||
$fnTypeDeferred.resolveWith(null);
|
||||
}
|
||||
$.when(hintPromise, fnTypePromise, propsPromise).done(
|
||||
function(completions, fnType, properties){
|
||||
function (completions, fnType, properties) {
|
||||
session.setTernHints(completions);
|
||||
session.setFnType(fnType);
|
||||
session.setTernProperties(properties);
|
||||
|
||||
$deferredHints.resolveWith(null);
|
||||
});
|
||||
return {promise:$deferredHints.promise()};
|
||||
}
|
||||
);
|
||||
return {promise: $deferredHints.promise()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the tern worker - if the worker is being initialized,
|
||||
* the message will not be posted until initialization is complete
|
||||
*/
|
||||
function postMessage(msg) {
|
||||
ternPromise.done(function (ternWorker){
|
||||
ternWorker.postMessage(msg);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for the completions from TernJS, for the file & offset passed in.
|
||||
* @return {jQuery.Promise} - a promise that will resolve to an array of completions when
|
||||
* it is done
|
||||
*/
|
||||
function getTernHints(dir, file, offset, text) {
|
||||
postMessage({
|
||||
type: HintUtils.TERN_COMPLETIONS_MSG,
|
||||
dir:dir,
|
||||
file:file,
|
||||
offset:offset,
|
||||
text:text
|
||||
});
|
||||
|
||||
return addPendingRequest(file, offset, HintUtils.TERN_COMPLETIONS_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for all of the known properties from TernJS, for the directory and file.
|
||||
* The properties will be used as guesses in tern.
|
||||
*
|
||||
* @return {jQuery.Promise} - a promise that will resolve to an array of properties when
|
||||
* it is done
|
||||
*/
|
||||
function getTernProperties(dir, file, offset, text) {
|
||||
postMessage({
|
||||
type: HintUtils.TERN_GET_PROPERTIES_MSG,
|
||||
dir:dir,
|
||||
file:file,
|
||||
offset: offset,
|
||||
text:text
|
||||
});
|
||||
|
||||
return addPendingRequest(file, offset, HintUtils.TERN_GET_PROPERTIES_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for the function type from TernJS.
|
||||
* @return {jQuery.Promise} - a promise that will resolve to the function type of the function being called.
|
||||
*/
|
||||
function getTernFunctionType(dir, file, pos, offset, text) {
|
||||
postMessage({
|
||||
type: HintUtils.TERN_CALLED_FUNC_TYPE_MSG,
|
||||
dir:dir,
|
||||
file:file,
|
||||
pos:pos,
|
||||
offset:offset,
|
||||
text:text
|
||||
});
|
||||
|
||||
return addPendingRequest(file, offset, HintUtils.TERN_CALLED_FUNC_TYPE_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pending request waiting for the tern-worker to complete.
|
||||
*
|
||||
* @param {string} file - the name of the file
|
||||
* @param {string} type - the type of request
|
||||
* @param {jQuery.Deferred} deferredRequest - the $.Deferred object to save
|
||||
*/
|
||||
function addPendingRequest(file, offset, type) {
|
||||
var requests,
|
||||
key = file+"@"+offset,
|
||||
$deferredRequest;
|
||||
if( Object.prototype.hasOwnProperty.call(pendingTernRequests, key) ) {
|
||||
requests = pendingTernRequests[key];
|
||||
} else {
|
||||
requests = {};
|
||||
pendingTernRequests[key] = requests;
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(requests, type)) {
|
||||
$deferredRequest = requests[type];
|
||||
} else {
|
||||
requests[type] = $deferredRequest = $.Deferred();
|
||||
}
|
||||
return $deferredRequest.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any pending $.Deferred object waiting on the specified file and request type
|
||||
* @param {string} file - the file
|
||||
* @param {string} type - the type of request
|
||||
* @param {jQuery.Deferred} - the $.Deferred for the request
|
||||
*/
|
||||
*/
|
||||
function getPendingRequest(file, offset, type) {
|
||||
var key = file +"@"+offset;
|
||||
if( Object.prototype.hasOwnProperty.call(pendingTernRequests, key) ) {
|
||||
var key = file + "@" + offset;
|
||||
if (Object.prototype.hasOwnProperty.call(pendingTernRequests, key)) {
|
||||
var requests = pendingTernRequests[key];
|
||||
return requests[type];
|
||||
}
|
||||
}
|
||||
return requests[type];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the response from the tern web worker when
|
||||
@@ -352,17 +355,17 @@ define(function (require, exports, module) {
|
||||
completions = response.completions,
|
||||
properties = response.properties,
|
||||
fnType = response.fnType,
|
||||
type = response.type,
|
||||
type = response.type,
|
||||
$deferredHints = getPendingRequest(file, offset, type);
|
||||
|
||||
if( $deferredHints ) {
|
||||
if( completions ) {
|
||||
if ($deferredHints) {
|
||||
if (completions) {
|
||||
$deferredHints.resolveWith(null, [completions]);
|
||||
} else if ( properties ) {
|
||||
} else if (properties) {
|
||||
$deferredHints.resolveWith(null, [properties]);
|
||||
} else if ( fnType ) {
|
||||
} else if (fnType) {
|
||||
$deferredHints.resolveWith(null, [fnType]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,33 +387,33 @@ define(function (require, exports, module) {
|
||||
|
||||
function replyWith(name, txt) {
|
||||
postMessage({
|
||||
type:HintUtils.TERN_GET_FILE_MSG,
|
||||
file:name,
|
||||
text:txt
|
||||
type: HintUtils.TERN_GET_FILE_MSG,
|
||||
file: name,
|
||||
text: txt
|
||||
});
|
||||
}
|
||||
|
||||
var name = request.file;
|
||||
DocumentManager.getDocumentForPath(rootTernDir + name).done(function(document){
|
||||
DocumentManager.getDocumentForPath(rootTernDir + name).done(function (document) {
|
||||
resolvedFiles[name] = rootTernDir + name;
|
||||
replyWith(name, document.getText());
|
||||
})
|
||||
.fail(function(){
|
||||
if (projectRoot) {
|
||||
// Try relative to project root
|
||||
DocumentManager.getDocumentForPath(projectRoot + name).done(function(document) {
|
||||
resolvedFiles[name] = projectRoot + name;
|
||||
replyWith(name, document.getText());
|
||||
})
|
||||
.fail(function(){
|
||||
.fail(function () {
|
||||
if (projectRoot) {
|
||||
// Try relative to project root
|
||||
DocumentManager.getDocumentForPath(projectRoot + name).done(function (document) {
|
||||
resolvedFiles[name] = projectRoot + name;
|
||||
replyWith(name, document.getText());
|
||||
})
|
||||
.fail(function () {
|
||||
replyWith(name, "");
|
||||
});
|
||||
} else {
|
||||
// Need to send something back to tern - it will wait
|
||||
// until all the files have been retrieved before doing its calculations
|
||||
replyWith(name, "");
|
||||
});
|
||||
} else {
|
||||
// Need to send something back to tern - it will wait
|
||||
// until all the files have been retrieved before doing its calculations
|
||||
replyWith(name, "");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -475,15 +478,15 @@ define(function (require, exports, module) {
|
||||
var response = e.data,
|
||||
type = response.type;
|
||||
|
||||
if( type === HintUtils.TERN_COMPLETIONS_MSG ||
|
||||
type === HintUtils.TERN_CALLED_FUNC_TYPE_MSG ||
|
||||
type === HintUtils.TERN_GET_PROPERTIES_MSG) {
|
||||
if (type === HintUtils.TERN_COMPLETIONS_MSG ||
|
||||
type === HintUtils.TERN_CALLED_FUNC_TYPE_MSG ||
|
||||
type === HintUtils.TERN_GET_PROPERTIES_MSG) {
|
||||
// handle any completions the worker calculated
|
||||
handleTernCompletions(response);
|
||||
} else if ( type === HintUtils.TERN_GET_FILE_MSG ) {
|
||||
} else if (type === HintUtils.TERN_GET_FILE_MSG) {
|
||||
// handle a request for the contents of a file
|
||||
handleTernGetFile(response);
|
||||
} else if ( type === HintUtils.TERN_JUMPTODEF_MSG ) {
|
||||
} else if (type === HintUtils.TERN_JUMPTODEF_MSG) {
|
||||
handleJumptoDef(response);
|
||||
} else {
|
||||
console.log("Worker: " + (response.log || response));
|
||||
|
||||
@@ -268,10 +268,10 @@ define(function (require, exports, module) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( found ) {
|
||||
functionCallPos = {line:line, ch:col};
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
functionCallPos = {line: line, ch: col};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (token.string === ".") {
|
||||
propertyLookup = true;
|
||||
@@ -287,14 +287,14 @@ define(function (require, exports, module) {
|
||||
context = this.getContext(cursor);
|
||||
}
|
||||
}
|
||||
if( propertyLookup ) { showFunctionType = false; }
|
||||
}
|
||||
if (propertyLookup) { showFunctionType = false; }
|
||||
}
|
||||
|
||||
return {
|
||||
property: propertyLookup,
|
||||
inFunctionCall: inFunctionCall,
|
||||
showFunctionType: showFunctionType,
|
||||
functionCallPos: functionCallPos,
|
||||
showFunctionType: showFunctionType,
|
||||
functionCallPos: functionCallPos,
|
||||
context: context
|
||||
};
|
||||
};
|
||||
@@ -314,7 +314,10 @@ define(function (require, exports, module) {
|
||||
query = "";
|
||||
}
|
||||
|
||||
var MAX_DISPLAYED_HINTS = 500;
|
||||
var MAX_DISPLAYED_HINTS = 500,
|
||||
type = this.getType(),
|
||||
builtins = this.builtins,
|
||||
hints;
|
||||
|
||||
/**
|
||||
* Is the origin one of the builtin files.
|
||||
@@ -346,7 +349,7 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
if (!type.property && !type.showFunctionType && hint.origin &&
|
||||
isBuiltin(hint.origin)) {
|
||||
isBuiltin(hint.origin)) {
|
||||
searchResult.builtin = 1;
|
||||
} else {
|
||||
searchResult.builtin = 0;
|
||||
@@ -359,10 +362,6 @@ define(function (require, exports, module) {
|
||||
return matchResults;
|
||||
}
|
||||
|
||||
var type = this.getType(),
|
||||
builtins = this.builtins,
|
||||
hints;
|
||||
|
||||
if (type.property) {
|
||||
hints = this.ternHints || [];
|
||||
hints = filterWithQueryAndMatcher(hints, matcher);
|
||||
@@ -373,8 +372,8 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
StringMatch.multiFieldSort(hints, { matchGoodness: 0, value: 1 });
|
||||
} else if ( type.showFunctionType ) {
|
||||
hints = this.getFunctionTypeHint();
|
||||
} else if (type.showFunctionType) {
|
||||
hints = this.getFunctionTypeHint();
|
||||
} else { // identifiers, literals, and keywords
|
||||
hints = this.ternHints || [];
|
||||
hints = hints.concat(HintUtils.LITERALS);
|
||||
@@ -396,18 +395,18 @@ define(function (require, exports, module) {
|
||||
this.ternProperties = newProperties;
|
||||
};
|
||||
Session.prototype.setFnType = function (newFnType) {
|
||||
this.fnType = newFnType;
|
||||
this.fnType = newFnType;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the function type hint. This will format the hint so
|
||||
* that it has the called variable name instead of just "fn()".
|
||||
*/
|
||||
Session.prototype.getFunctionTypeHint = function() {
|
||||
Session.prototype.getFunctionTypeHint = function () {
|
||||
var fnHint = this.fnType,
|
||||
hints = [];
|
||||
|
||||
if (fnHint && (fnHint.substring(0,3) === "fn(")) {
|
||||
if (fnHint && (fnHint.substring(0, 3) === "fn(")) {
|
||||
var sessionType = this.getType(),
|
||||
cursor = sessionType.functionCallPos,
|
||||
token = cursor ? this.getToken(cursor) : undefined,
|
||||
@@ -418,8 +417,8 @@ define(function (require, exports, module) {
|
||||
fnHint = varName + fnHint.substr(2);
|
||||
}
|
||||
}
|
||||
hints[0] = {value:fnHint, positions:[]};
|
||||
}
|
||||
hints[0] = {value: fnHint, positions: []};
|
||||
}
|
||||
return hints;
|
||||
};
|
||||
|
||||
|
||||
@@ -404,7 +404,7 @@ define(function (require, exports, module) {
|
||||
var resolvedPath = ScopeManager.getResolvedPath(jumpResp.resultFile);
|
||||
if (resolvedPath) {
|
||||
CommandManager.execute(Commands.FILE_OPEN, {fullPath: resolvedPath})
|
||||
.done(function() {
|
||||
.done(function () {
|
||||
session.editor.setCursorPos(jumpResp.start);
|
||||
session.editor.setSelection(jumpResp.start, jumpResp.end);
|
||||
session.editor.centerOnCursor();
|
||||
|
||||
@@ -31,13 +31,13 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
var HintUtils;
|
||||
var Tern;
|
||||
require(["./HintUtils"], function(hintUtils) {
|
||||
require(["./HintUtils"], function (hintUtils) {
|
||||
HintUtils = hintUtils;
|
||||
var ternRequire = require.config({baseUrl: "./thirdparty"});
|
||||
ternRequire(["tern/lib/tern", "tern/plugin/requirejs"], function(tern, requirejs) {
|
||||
ternRequire(["tern/lib/tern", "tern/plugin/requirejs"], function (tern, requirejs) {
|
||||
Tern = tern;
|
||||
} );
|
||||
} );
|
||||
});
|
||||
});
|
||||
|
||||
var ternServer = null;
|
||||
|
||||
@@ -65,7 +65,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
*/
|
||||
function handleGetFile(file, text) {
|
||||
var next = fileCallBacks[file];
|
||||
if( next ) {
|
||||
if (next) {
|
||||
next(null, text);
|
||||
}
|
||||
delete fileCallBacks[file];
|
||||
@@ -76,21 +76,21 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
*/
|
||||
function initTernServer(env, dir, files) {
|
||||
var ternOptions = {
|
||||
defs:env,
|
||||
async:true,
|
||||
defs: env,
|
||||
async: true,
|
||||
getFile: getFile,
|
||||
plugins: {requirejs: {}}
|
||||
};
|
||||
ternServer = new Tern.Server(ternOptions);
|
||||
|
||||
files.forEach(function (file){
|
||||
ternServer.addFile(file);
|
||||
files.forEach(function (file) {
|
||||
ternServer.addFile(file);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function buildRequest(dir, file, query, offset, text){
|
||||
query = {type:query};
|
||||
function buildRequest(dir, file, query, offset, text) {
|
||||
query = {type: query};
|
||||
query.start = offset;
|
||||
query.end = offset;
|
||||
query.file = file;
|
||||
@@ -101,11 +101,20 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
query.origins = true;
|
||||
query.expandWordForward = true;
|
||||
|
||||
var request = {query:query, files:[], offset:offset};
|
||||
request.files.push({type:"full", name:file, text:text});
|
||||
var request = {query: query, files: [], offset: offset};
|
||||
request.files.push({type: "full", name: file, text: text});
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a log message back from the worker to the main thread
|
||||
*
|
||||
* @param {string} msg - the log message
|
||||
*/
|
||||
function _log(msg) {
|
||||
self.postMessage({log: msg });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get definition location
|
||||
@@ -118,7 +127,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
var request = buildRequest(dir, file, "definition", offset, text);
|
||||
request.query.lineCharPositions = true;
|
||||
ternServer.request(request, function(error, data) {
|
||||
ternServer.request(request, function (error, data) {
|
||||
if (error) {
|
||||
_log("Error returned from Tern 'definition' request: " + error);
|
||||
self.postMessage({type: HintUtils.TERN_JUMPTODEF_MSG});
|
||||
@@ -146,16 +155,17 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
*/
|
||||
function getTernHints(dir, file, offset, text) {
|
||||
|
||||
var request = buildRequest(dir, file, "completions", offset, text);
|
||||
var request = buildRequest(dir, file, "completions", offset, text),
|
||||
i;
|
||||
//_log("request " + dir + " " + file + " " + offset /*+ " " + text */);
|
||||
ternServer.request(request, function(error, data) {
|
||||
ternServer.request(request, function (error, data) {
|
||||
if (error) {
|
||||
_log("Error returned from Tern 'completions' request: " + error);
|
||||
return;
|
||||
}
|
||||
var completions = [];
|
||||
//_log("found " + completions.length + " for " + file + "@" + offset);
|
||||
for (var i = 0; i < data.completions.length; ++i) {
|
||||
for (i = 0; i < data.completions.length; ++i) {
|
||||
var completion = data.completions[i];
|
||||
completions.push({value: completion.name, type: completion.type, depth: completion.depth,
|
||||
guess: completion.guess, origin: completion.origin});
|
||||
@@ -180,16 +190,17 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
*/
|
||||
function handleGetProperties(dir, file, offset, text) {
|
||||
|
||||
var request = buildRequest(dir, file, "properties", undefined, text);
|
||||
var request = buildRequest(dir, file, "properties", undefined, text),
|
||||
i;
|
||||
//_log("request " + request.type + dir + " " + file);
|
||||
ternServer.request(request, function(error, data) {
|
||||
ternServer.request(request, function (error, data) {
|
||||
if (error) {
|
||||
_log("Error returned from Tern 'properties' request: " + error);
|
||||
return;
|
||||
}
|
||||
//_log("completions = " + data.completions.length);
|
||||
var properties = [];
|
||||
for (var i = 0; i < data.completions.length; ++i) {
|
||||
for (i = 0; i < data.completions.length; ++i) {
|
||||
var property = data.completions[i];
|
||||
properties.push({value: property, guess: true});
|
||||
}
|
||||
@@ -200,7 +211,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
file: file,
|
||||
offset: offset,
|
||||
properties: properties
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -218,12 +229,12 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
request.preferFunction = true;
|
||||
|
||||
//_log("request " + dir + " " + file + " " + offset /*+ " " + text */);
|
||||
ternServer.request(request, function(error, data) {
|
||||
ternServer.request(request, function (error, data) {
|
||||
if (error) {
|
||||
_log("Error returned from Tern 'type' request: " + error);
|
||||
return;
|
||||
}
|
||||
var fnType = data.type;
|
||||
var fnType = data.type;
|
||||
|
||||
// Post a message back to the main thread with the completions
|
||||
self.postMessage({type: HintUtils.TERN_CALLED_FUNC_TYPE_MSG,
|
||||
@@ -235,15 +246,6 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a log message back from the worker to the main thread
|
||||
*
|
||||
* @param {string} msg - the log message
|
||||
*/
|
||||
function _log(msg) {
|
||||
self.postMessage({log: msg });
|
||||
}
|
||||
|
||||
self.addEventListener("message", function (e) {
|
||||
var dir, file, text, offset,
|
||||
request = e.data,
|
||||
@@ -252,34 +254,34 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
if (type === HintUtils.TERN_INIT_MSG) {
|
||||
|
||||
dir = request.dir;
|
||||
var env = request.env,
|
||||
var env = request.env,
|
||||
files = request.files;
|
||||
initTernServer(env, dir, files);
|
||||
|
||||
} else if( type === HintUtils.TERN_COMPLETIONS_MSG) {
|
||||
} else if (type === HintUtils.TERN_COMPLETIONS_MSG) {
|
||||
dir = request.dir;
|
||||
file = request.file;
|
||||
text = request.text;
|
||||
offset = request.offset;
|
||||
getTernHints(dir, file, offset, text);
|
||||
} else if ( type === HintUtils.TERN_GET_PROPERTIES_MSG) {
|
||||
file = request.file,
|
||||
} else if (type === HintUtils.TERN_GET_PROPERTIES_MSG) {
|
||||
file = request.file;
|
||||
dir = request.dir;
|
||||
text = request.text;
|
||||
offset = request.offset;
|
||||
handleGetProperties(dir, file, offset, text);
|
||||
} else if ( type === HintUtils.TERN_GET_FILE_MSG ) {
|
||||
file = request.file,
|
||||
} else if (type === HintUtils.TERN_GET_FILE_MSG) {
|
||||
file = request.file;
|
||||
text = request.text;
|
||||
handleGetFile(file, text);
|
||||
} else if ( type === HintUtils.TERN_CALLED_FUNC_TYPE_MSG ) {
|
||||
} else if (type === HintUtils.TERN_CALLED_FUNC_TYPE_MSG) {
|
||||
dir = request.dir;
|
||||
file = request.file;
|
||||
text = request.text;
|
||||
offset = request.offset;
|
||||
var pos = request.pos;
|
||||
handleFunctionType(dir, file, pos, offset, text);
|
||||
} else if ( type === HintUtils.TERN_JUMPTODEF_MSG ) {
|
||||
handleFunctionType(dir, file, pos, offset, text);
|
||||
} else if (type === HintUtils.TERN_JUMPTODEF_MSG) {
|
||||
file = request.file;
|
||||
dir = request.dir;
|
||||
text = request.text;
|
||||
|
||||
@@ -234,7 +234,8 @@ define(function (require, exports, module) {
|
||||
* @return {number} the index of the hint corresponding to the hintSelection
|
||||
*/
|
||||
function findHint(hintList, hintSelection) {
|
||||
for (var i = 0, l = hintList.length; i < l; ++i) {
|
||||
var i, l;
|
||||
for (i = 0, l = hintList.length; i < l; ++i) {
|
||||
var current = hintList[i].data("token");
|
||||
if (hintSelection === current.value) {
|
||||
return i;
|
||||
@@ -321,7 +322,7 @@ define(function (require, exports, module) {
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
hintsPresent(hintObj, ["alert", "console", "confirm", "navigator", "window", "frames"]);
|
||||
});
|
||||
*/
|
||||
*/
|
||||
it("should NOT list implicitly defined globals from missing JSLint annotations", function () {
|
||||
testEditor.setCursorPos({ line: 6, ch: 0 });
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
@@ -375,7 +376,7 @@ define(function (require, exports, module) {
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
hintsPresent(hintObj, ["use strict"]);
|
||||
});
|
||||
*/
|
||||
*/
|
||||
it("should NOT list string literals from other files", function () {
|
||||
testEditor.setCursorPos({ line: 6, ch: 0 });
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
|
||||
Reference in new issue
Block a user