mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Add remaining JSDoc annotations
This commit is contained in:
1 parent
91487e3a6a
commit
c0e75bcc7e
6 files changed
+481
-136
No files matched your search
@@ -32,6 +32,15 @@ define(function (require, exports, module) {
|
||||
SINGLE_QUOTE = "\'",
|
||||
DOUBLE_QUOTE = "\"";
|
||||
|
||||
/**
|
||||
* Create a hint token with name value that occurs at the given list of
|
||||
* positions.
|
||||
*
|
||||
* @param {String} value - name of the new hint token
|
||||
* @param {?Array<Number>} positions - optional list of positions at which
|
||||
* the token occurs
|
||||
* @return {Object} - a new hint token
|
||||
*/
|
||||
function makeToken(value, positions) {
|
||||
positions = positions || [];
|
||||
|
||||
@@ -43,6 +52,9 @@ define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Is the string key perhaps a valid JavaScript identifier?
|
||||
*
|
||||
* @param {String} key - the string to test
|
||||
* @return {Boolean} - could key be a valid identifier?
|
||||
*/
|
||||
function maybeIdentifier(key) {
|
||||
return (/[0-9a-z_.\$]/i).test(key) ||
|
||||
@@ -51,7 +63,10 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the token's class hintable?
|
||||
* Is the token's class hintable? (A very conservative test.)
|
||||
*
|
||||
* @param {Object} token - the token to test for hintability
|
||||
* @return {Boolean} - could the token be hintable?
|
||||
*/
|
||||
function hintable(token) {
|
||||
switch (token.className) {
|
||||
@@ -66,6 +81,10 @@ define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Divide a path into directory and filename parts
|
||||
*
|
||||
* @param {String} path - a URI with directories separated by /
|
||||
* @return {Object<dir: String, file: String>} - a pair of strings that
|
||||
* correspond to the directory and filename of the given path.
|
||||
*/
|
||||
function splitPath(path) {
|
||||
var index = path.lastIndexOf("/"),
|
||||
@@ -76,7 +95,11 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a JS-hints-specific event name
|
||||
* Get a JS-hints-specific event name. Used to prevent event namespace
|
||||
* pollution.
|
||||
*
|
||||
* @param {String} name - the unqualified event name
|
||||
* @return {String} - the qualified event name
|
||||
*/
|
||||
function eventName(name) {
|
||||
var EVENT_TAG = "brackets-js-hints";
|
||||
@@ -84,7 +107,15 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Annotate list of identifiers with their scope level
|
||||
* Annotate list of identifiers with their scope level.
|
||||
*
|
||||
* @param {Array<Object>} identifiers - list of identifier tokens to be
|
||||
* annotated
|
||||
* @param {Scope} scope - scope object used to determine the scope level of
|
||||
* each identifier token in the previous list.
|
||||
* @return {Array<Object>} - the input array; to each object in the array a
|
||||
* new level {Number} property has been added to indicate its scope
|
||||
* level.
|
||||
*/
|
||||
function annotateWithScope(identifiers, scope) {
|
||||
return identifiers.map(function (t) {
|
||||
@@ -101,6 +132,13 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Annotate a list of properties with their association level
|
||||
*
|
||||
* @param {Array<Object>} properties - list of property tokens
|
||||
* @param {Association} association - an object that maps property
|
||||
* names to the number of times it occurs in a particular context
|
||||
* @return {Array<Object>} - the input array; to each object in the array a
|
||||
* new level {Number} property has been added to indicate the number
|
||||
* of times the property has occurred in the association context.
|
||||
*/
|
||||
function annotateWithAssociation(properties, association) {
|
||||
return properties.map(function (t) {
|
||||
@@ -113,6 +151,11 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Annotate a list of tokens as being global variables
|
||||
*
|
||||
* @param {Array<Object>} globals - list of identifier tokens
|
||||
* @return {Array<Object>} - the input array; to each object in the array a
|
||||
* new global {Boolean} property has been added to indicate that it is
|
||||
* a global variable.
|
||||
*/
|
||||
function annotateGlobals(globals) {
|
||||
return globals.map(function (t) {
|
||||
@@ -124,15 +167,26 @@ define(function (require, exports, module) {
|
||||
/*
|
||||
* Annotate a list of tokens as literals of a particular kind;
|
||||
* if string literals, annotate with an appropriate delimiter.
|
||||
*
|
||||
* @param {Array<Object>} literals - list of hint tokens
|
||||
* @param {String} kind - the kind of literals in the list (e.g., "string")
|
||||
* @return {Array<Object>} - the input array; to each object in the array a
|
||||
* new literal {Boolean} property has been added to indicate that it
|
||||
* is a literal hint, and also a new kind {String} property to indicate
|
||||
* the literal kind. For string literals, a delimiter property is also
|
||||
* added to indicate what the default delimiter should be (viz. a
|
||||
* single or double quotation mark).
|
||||
*/
|
||||
function annotateLiterals(literals, kind) {
|
||||
return literals.map(function (t) {
|
||||
t.literal = true;
|
||||
t.kind = kind;
|
||||
if (/[\\\\]*[^\\]"/.test(t.value)) {
|
||||
t.delimeter = SINGLE_QUOTE;
|
||||
} else {
|
||||
t.delimeter = DOUBLE_QUOTE;
|
||||
if (kind === "string") {
|
||||
if (/[\\\\]*[^\\]"/.test(t.value)) {
|
||||
t.delimeter = SINGLE_QUOTE;
|
||||
} else {
|
||||
t.delimeter = DOUBLE_QUOTE;
|
||||
}
|
||||
}
|
||||
return t;
|
||||
});
|
||||
@@ -140,6 +194,11 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Annotate a list of tokens as keywords
|
||||
*
|
||||
* @param {Array<Object>} keyword - list of keyword tokens
|
||||
* @return {Array<Object>} - the input array; to each object in the array a
|
||||
* new keyword {Boolean} property has been added to indicate that the
|
||||
* hint is a keyword.
|
||||
*/
|
||||
function annotateKeywords(keywords) {
|
||||
return keywords.map(function (t) {
|
||||
@@ -149,7 +208,13 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Annotate a list of tokens as keywords
|
||||
* Annotate a list of tokens with a path name
|
||||
*
|
||||
* @param {Array<Object>} tokens - list of hint tokens
|
||||
* @param {String} dir - directory with which to annotate the hints
|
||||
* @param {String} file - file name with which to annotate the hints
|
||||
* @return {Array<Object>} - the input array; to each object in the array a
|
||||
* new path {String} property has been added, equal to dir + file.
|
||||
*/
|
||||
function annotateWithPath(tokens, dir, file) {
|
||||
var path = dir + file;
|
||||
@@ -202,6 +267,7 @@ define(function (require, exports, module) {
|
||||
return prev;
|
||||
}, {}); // builds an object from the array of tokens.
|
||||
|
||||
// Predefined sets of globals as defined by JSLint
|
||||
var JSL_GLOBALS_BROWSER = [
|
||||
JSL_GLOBALS.clearInterval,
|
||||
JSL_GLOBALS.clearTimeout,
|
||||
|
||||
@@ -52,11 +52,24 @@ define(function (require, exports, module) {
|
||||
return arr[middle];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a scope object from AST tree as a child of the given parent.
|
||||
*
|
||||
* @constructor
|
||||
* @param {AST} tree - an AST as described at
|
||||
https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
|
||||
* @param {?Scope} parent - the (optional) parent of the new Scope
|
||||
*/
|
||||
function Scope(tree, parent) {
|
||||
|
||||
/*
|
||||
* Given a member expression, try to add a target-property association
|
||||
* to the given scope.
|
||||
*
|
||||
* @param {AST} object - the lookup object
|
||||
* @param {AST} property - the property being looked up
|
||||
* @param {Scope} parent - the Scope object in which the association
|
||||
* occurs.
|
||||
*/
|
||||
function _buildAssociations(object, property, parent) {
|
||||
if (property.type === "Identifier") {
|
||||
@@ -83,7 +96,11 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Build scope information for an AST as a child scope of parent.
|
||||
* Walk a given AST and add scope information to a given parent scope,
|
||||
* including new child Scope objects.
|
||||
*
|
||||
* @param {AST} tree - the AST from which the Scope is constructed
|
||||
* @param {Scope} parent - the parent of the Scope to be constructed
|
||||
*/
|
||||
function _buildScope(tree, parent) {
|
||||
var child;
|
||||
@@ -356,6 +373,10 @@ define(function (require, exports, module) {
|
||||
* Rebuild a Scope object from an object that has all the necessary data
|
||||
* but the wrong prototype. Such objects may be created as a result of
|
||||
* e.g., JSON-marshalling and unmarshalling a scope.
|
||||
*
|
||||
* @param {Object} data - an object that contains all data of a Scope object
|
||||
* but none of the methods
|
||||
* @return {Scope} - the same object with Scope methods added
|
||||
*/
|
||||
Scope.rebuild = function (data) {
|
||||
var memberName,
|
||||
@@ -379,6 +400,8 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Add an identifier occurrence.
|
||||
*
|
||||
* @param {AST} id - an identifier AST node
|
||||
*/
|
||||
Scope.prototype.addIdOccurrence = function (id) {
|
||||
this.idOccurrences.push(id);
|
||||
@@ -386,6 +409,8 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Add an identifier declaration
|
||||
*
|
||||
* @param {AST} id - an identifier AST node
|
||||
*/
|
||||
Scope.prototype.addDeclaration = function (id) {
|
||||
this.idDeclarations[id.name] = id;
|
||||
@@ -394,6 +419,8 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Add a list of identifier declarations
|
||||
*
|
||||
* @param {Array<AST>} ids - a list of identifier AST nodes
|
||||
*/
|
||||
Scope.prototype.addAllDeclarations = function (ids) {
|
||||
var that = this;
|
||||
@@ -404,6 +431,8 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Add a property occurrence
|
||||
*
|
||||
* @param {AST} prop - a property AST node
|
||||
*/
|
||||
Scope.prototype.addProperty = function (prop) {
|
||||
this.propOccurrences.push(prop);
|
||||
@@ -411,6 +440,9 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Add an association object
|
||||
*
|
||||
* @param {AST} obj - a identifer AST node
|
||||
* @param {AST} prop - a property AST node
|
||||
*/
|
||||
Scope.prototype.addAssociation = function (obj, prop) {
|
||||
this.associations.push({object: obj, property: prop});
|
||||
@@ -418,13 +450,18 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Add a literal occurrence
|
||||
*
|
||||
* @param {AST} lit - a literal AST node
|
||||
*/
|
||||
Scope.prototype.addLiteralOccurrence = function (lit) {
|
||||
this.literals.push(lit);
|
||||
};
|
||||
|
||||
/*
|
||||
* Attach a new child scope to the current scope
|
||||
* Attach a new child scope to the current scope. Inserts the child scope
|
||||
* in range-sorted order w.r.t. the other children of the current scope.
|
||||
*
|
||||
* @param {Scope} child - the child to be added
|
||||
*/
|
||||
Scope.prototype.addChildScope = function (child) {
|
||||
var i = 0;
|
||||
@@ -438,6 +475,10 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Is the symbol declared in this scope?
|
||||
*
|
||||
* @param {String} sym - a symbol name
|
||||
* @return {Boolean} - whether a symbol with that name is declared in this
|
||||
* immediate scope
|
||||
*/
|
||||
Scope.prototype.member = function (sym) {
|
||||
return Object.prototype.hasOwnProperty.call(this.idDeclarations, sym);
|
||||
@@ -445,6 +486,10 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Is the symbol declared in this scope or a parent scope?
|
||||
*
|
||||
* @param {String} sym - a symbol name
|
||||
* @return {Boolean} - whether a symbol with that name is declared in this
|
||||
* immediate scope or a parent scope
|
||||
*/
|
||||
Scope.prototype.contains = function (sym) {
|
||||
var depth = 0,
|
||||
@@ -464,6 +509,9 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Does this scope, or its children, contain the given position?
|
||||
*
|
||||
* @param {Number} pos - the position to test for inclusion in the scope
|
||||
* @return {Boolean} - is the position included in the scope?
|
||||
*/
|
||||
Scope.prototype.containsPosition = function (pos) {
|
||||
return this.range.start <= pos && pos <= this.range.end;
|
||||
@@ -471,6 +519,9 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Does this scope, but not its children, contain the given position?
|
||||
*
|
||||
* @param {Number} pos - the position to test for inclusion in the scope
|
||||
* @return {Boolean} - is the position directly included in the scope?
|
||||
*/
|
||||
Scope.prototype.containsPositionImmediate = function (pos) {
|
||||
if (this.containsPosition(pos)) {
|
||||
@@ -490,6 +541,10 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Find the child scope of the current scope for a given position
|
||||
*
|
||||
* @param {Number} pos - the position at which to find a child scope
|
||||
* @return {?Scope} - the child scope for the given position, or null
|
||||
* if none exists
|
||||
*/
|
||||
Scope.prototype.findChild = function (pos) {
|
||||
if (this.containsPosition(pos)) {
|
||||
@@ -509,7 +564,12 @@ define(function (require, exports, module) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Traverse the scope down via children
|
||||
* Traverse the scope down via children in pre-order.
|
||||
*
|
||||
* @param {Function} add - the Scope accumulation function
|
||||
* @param {Object} init - an initial value for the accumulation function
|
||||
* @return {Object} - the result of of accumulating the current scope along
|
||||
* with all of its children
|
||||
*/
|
||||
Scope.prototype.walkDown = function (add, init) {
|
||||
var result = add(this, init);
|
||||
@@ -523,6 +583,12 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Traverse a particular list in the scope down via children
|
||||
*
|
||||
* @param {Function} addItem - the item accumulation function
|
||||
* @param {Object} init - an initial value for the accumulation function
|
||||
* @param {String} listName - the name of a Scope property
|
||||
* @return {Object} - the result of of accumulating the given property for
|
||||
* the current scope along with all of its children
|
||||
*/
|
||||
Scope.prototype.walkDownList = function (addItem, init, listName) {
|
||||
function addList(scope, init) {
|
||||
@@ -537,6 +603,11 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Traverse identifier occurrences in the scope down via children
|
||||
*
|
||||
* @param {Function} add - the identifier accumulation function
|
||||
* @param {Object} init - an initial value for the accumulation function
|
||||
* @return {Object} - the result of of accumulating identifier occurrences
|
||||
* for the current scope along with all of its children
|
||||
*/
|
||||
Scope.prototype.walkDownIdentifiers = function (add, init) {
|
||||
return this.walkDownList(add, init, "idOccurrences");
|
||||
@@ -544,6 +615,11 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Traverse property occurrences in the scope down via children
|
||||
*
|
||||
* @param {Function} add - the property accumulation function
|
||||
* @param {Object} init - an initial value for the accumulation function
|
||||
* @return {Object} - the result of of accumulating property occurrences
|
||||
* for the current scope along with all of its children
|
||||
*/
|
||||
Scope.prototype.walkDownProperties = function (add, init) {
|
||||
return this.walkDownList(add, init, "propOccurrences");
|
||||
@@ -551,6 +627,11 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Traverse associations in the scope down via children
|
||||
*
|
||||
* @param {Function} add - the association accumulation function
|
||||
* @param {Object} init - an initial value for the accumulation function
|
||||
* @return {Object} - the result of of accumulating association occurrences
|
||||
* for the current scope along with all of its children
|
||||
*/
|
||||
Scope.prototype.walkDownAssociations = function (add, init) {
|
||||
return this.walkDownList(add, init, "associations");
|
||||
@@ -558,6 +639,11 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Traverse literals in the scope down via children
|
||||
*
|
||||
* @param {Function} add - the literal accumulation function
|
||||
* @param {Object} init - an initial value for the accumulation function
|
||||
* @return {Object} - the result of of accumulating literal occurrences
|
||||
* for the current scope along with all of its children
|
||||
*/
|
||||
Scope.prototype.walkDownLiterals = function (add, init) {
|
||||
return this.walkDownList(add, init, "literals");
|
||||
@@ -565,77 +651,26 @@ define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Traverse the scope up via the parent
|
||||
*
|
||||
* @param {Function} add - the Scope accumulation function
|
||||
* @param {Object} init - an initial value for the accumulation function
|
||||
* @return {Object} - the result of of accumulating the current scope along
|
||||
* with its parents
|
||||
*/
|
||||
Scope.prototype.walkUp = function (add, init, prop) {
|
||||
var scope = this,
|
||||
result = init,
|
||||
i;
|
||||
var scope = this,
|
||||
result = init,
|
||||
combine = function (elem) {
|
||||
result = add(result, elem);
|
||||
};
|
||||
|
||||
while (scope !== null) {
|
||||
for (i = 0; i < this[prop].length; i++) {
|
||||
result = add(result, this[prop][i]);
|
||||
}
|
||||
this[prop].forEach(combine);
|
||||
scope = scope.parent;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Traverse identifier declarations in the scope up via the parent
|
||||
*/
|
||||
Scope.prototype.walkUpDeclarations = function (add, init) {
|
||||
return this.walkUp(add, init, "idDeclarations");
|
||||
};
|
||||
|
||||
/**
|
||||
* Traverse identifier occurrences in the scope up via the parent
|
||||
*/
|
||||
Scope.prototype.walkUpIdentifiers = function (add, init) {
|
||||
return this.walkUp(add, init, "idOccurrences");
|
||||
};
|
||||
|
||||
/**
|
||||
* Traverse property occurrences in the scope up via the parent
|
||||
*/
|
||||
Scope.prototype.walkUpProperties = function (add, init) {
|
||||
return this.walkUp(add, init, "propOccurrences");
|
||||
};
|
||||
|
||||
/**
|
||||
* Traverse associations in the scope up via the parent
|
||||
*/
|
||||
Scope.prototype.walkUpAssociations = function (add, init) {
|
||||
return this.walkUp(add, init, "associations");
|
||||
};
|
||||
|
||||
/**
|
||||
* Traverse literal occurrences in the scope up via the parent
|
||||
*/
|
||||
Scope.prototype.walkUpLiterals = function (add, init) {
|
||||
return this.walkUp(add, init, "literals");
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a string representations of declarations below this scope
|
||||
*/
|
||||
Scope.prototype.toStringBelow = function () {
|
||||
return "[" + this.range.start + " " + this.idDeclarations.map(function (i) {
|
||||
return i.name;
|
||||
}).join(", ") +
|
||||
" : " + (this.children.map(function (c) {
|
||||
return c.toString();
|
||||
}).join("; ")) + this.range.end + "]";
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a string representations of declarations in this scope
|
||||
*/
|
||||
Scope.prototype.toString = function () {
|
||||
return "[" + this.range.start + " " + this.idDeclarations.map(function (i) {
|
||||
return i.name;
|
||||
}).join(", ") + this.range.end + "]";
|
||||
};
|
||||
|
||||
module.exports = Scope;
|
||||
});
|
||||
@@ -52,8 +52,11 @@ define(function (require, exports, module) {
|
||||
var MAX_TEXT_LENGTH = 1000000, // about 1MB
|
||||
MAX_FILES_IN_DIR = 100;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize state for a given directory and file name
|
||||
*
|
||||
* @param {String} dir - the directory name to initialize
|
||||
* @param {String} file - the file name to initialize
|
||||
*/
|
||||
function initFileState(dir, file) {
|
||||
// initialize outerScope, etc. at dir
|
||||
@@ -95,6 +98,17 @@ define(function (require, exports, module) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file state for a given path. If just the directory is given
|
||||
* instead of the whole path, a set of file states is returned, one for
|
||||
* each (known) file in the directory.
|
||||
*
|
||||
* @param {String} dir - the directory name for which state is desired
|
||||
* @param {String} file - the file name for which state is desired
|
||||
* @return {Object} - a file state object (as documented within
|
||||
* intializeFileState above), or a set of file state objects if
|
||||
* file is omitted.
|
||||
*/
|
||||
function getFileState(dir, file) {
|
||||
initFileState(dir, file);
|
||||
|
||||
@@ -107,6 +121,13 @@ define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Request a new outer scope object from the parser worker, if necessary
|
||||
*
|
||||
* @param {String} dir - the directory name for which the outer scope is to
|
||||
* be refreshed
|
||||
* @param {String} file - the file name for which the outer scope is to be
|
||||
* refreshed
|
||||
* @param {String} text - the text of the file for which the outer scope is
|
||||
* to be refreshed
|
||||
*/
|
||||
function refreshOuterScope(dir, file, text) {
|
||||
|
||||
@@ -142,12 +163,31 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Recompute the inner scope for a given cursor position, if necessary
|
||||
* Get inner scope information for a given file and offset if a suitable
|
||||
* global scope object is availble; otherwise, return a promise for such
|
||||
* information, resolved when a suitable global scope object becomes
|
||||
* available.
|
||||
*
|
||||
* @param {String} dir - the directory name for which the inner scope is to
|
||||
* be refreshed
|
||||
* @param {String} file - the file name for which the inner scope is to be
|
||||
* refreshed
|
||||
* @param {Number} offset - offset into the text at which the inner scope
|
||||
* is to be refreshed
|
||||
* @param {Object + jQuery.Promise} - inner scope information, or a promise
|
||||
* for such information, including the local scope object and lists of
|
||||
* identifiers, properties, globals, literals and associations.
|
||||
*/
|
||||
function refreshInnerScope(dir, file, offset) {
|
||||
|
||||
/*
|
||||
* Filter a list of tokens using a given scope object
|
||||
*
|
||||
* @param {Array<Object>} tokens - a list of identifier tokens
|
||||
* @param {Scope} scope - a scope object
|
||||
* @return {Array<Object>} - the sublist of the input list that
|
||||
* contains all and only the identifier tokens in scope
|
||||
* w.r.t. to the given scope
|
||||
*/
|
||||
function filterByScope(tokens, scope) {
|
||||
return tokens.filter(function (id) {
|
||||
@@ -157,16 +197,24 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Combine a set of sets using the add operation
|
||||
* Combine a particular property from a set of sets using a given add
|
||||
* operation
|
||||
*
|
||||
* @param {Object} sets - a set of sets
|
||||
* @param {String} propName - the property to pick out from each set
|
||||
* @param {Function} add - the function that combines properties from
|
||||
* each set
|
||||
* @return {Object}- the result of combining each set's property using
|
||||
* the add function
|
||||
*/
|
||||
function merge(sets, property, add) {
|
||||
function merge(sets, propName, add) {
|
||||
var combinedSet = {},
|
||||
nextSet,
|
||||
file;
|
||||
|
||||
for (file in sets) {
|
||||
if (sets.hasOwnProperty(file)) {
|
||||
nextSet = sets[file][property];
|
||||
nextSet = sets[file][propName];
|
||||
if (nextSet) {
|
||||
add(combinedSet, nextSet);
|
||||
}
|
||||
@@ -178,7 +226,11 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Combine properties from files in the current file's directory into
|
||||
* one sorted list.
|
||||
* a single list.
|
||||
*
|
||||
* @param {String} dir - the directory name of the files for which
|
||||
* property lists should be merged
|
||||
* @param {Array<Object>} - the combined list of property tokens
|
||||
*/
|
||||
function mergeProperties(dir) {
|
||||
|
||||
@@ -209,7 +261,12 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Combine association objects from multiple files
|
||||
* Combine association set objects from all of the files in a given
|
||||
* directory
|
||||
*
|
||||
* @param {String} dir - the directory name of the files for which
|
||||
* association sets should be merged
|
||||
* @param {Object} - the combined association set object
|
||||
*/
|
||||
function mergeAssociations(dir) {
|
||||
function addAssocSets(list1, list2) {
|
||||
@@ -303,13 +360,20 @@ define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Get a new inner scope and related info, if possible. If there is no
|
||||
* outer scope for the given file, a deferred object will be returned
|
||||
* instead.
|
||||
* outer scope for the given file, a promise will be returned instead.
|
||||
* (See refreshInnerScope above.)
|
||||
*
|
||||
* Note that successive calls to getScope may return the same objects, so
|
||||
* clients that wish to modify those objects (e.g., by annotating them based
|
||||
* on some temporary context) should copy them first. See, e.g.,
|
||||
* Session.getHints().
|
||||
*
|
||||
* @param {Document} document - the document for which scope info is
|
||||
* desired
|
||||
* @param {Number} offset - the offset into the document at which scope
|
||||
* info is desired
|
||||
* @param {Object + jQuery.Promise} - the inner scope info, or a promise
|
||||
* for such info. (See refreshInnerScope above.)
|
||||
*/
|
||||
function getScopeInfo(document, offset) {
|
||||
var path = document.file.fullPath,
|
||||
@@ -323,6 +387,10 @@ define(function (require, exports, module) {
|
||||
/**
|
||||
* Is the inner scope dirty? (It is if the outer scope has changed since
|
||||
* the last inner scope request)
|
||||
*
|
||||
* @param {Document} document - the document for which the last requested
|
||||
* inner scope may or may not be dirty
|
||||
* @return {Boolean} - is the inner scope dirty?
|
||||
*/
|
||||
function isScopeDirty(document) {
|
||||
var path = document.file.fullPath,
|
||||
@@ -335,8 +403,11 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a file as dirty, which causes an outer scope request to trigger
|
||||
* a reparse request.
|
||||
* Mark a file as dirty, which may cause a later outer scope request to
|
||||
* trigger a reparse request.
|
||||
*
|
||||
* @param {String} dir - the directory name of the file to be marked dirty
|
||||
* @param {String} file - the file name of the file to be marked dirty
|
||||
*/
|
||||
function markFileDirty(dir, file) {
|
||||
var state = getFileState(dir, file);
|
||||
@@ -345,8 +416,10 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the outer scopes of the given file as well as of the other files
|
||||
* in the given directory.
|
||||
* Called each time a new editor becomes active. Refreshes the outer scopes
|
||||
* of the given file as well as of the other files in the given directory.
|
||||
*
|
||||
* @param {Document} document - the document of the editor that has changed
|
||||
*/
|
||||
function handleEditorChange(document) {
|
||||
var path = document.file.fullPath,
|
||||
@@ -383,7 +456,10 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* When a file changes, mark it as being dirty and refresh its outer scope.
|
||||
* Called each time the file associated with the active edtor changes.
|
||||
* Marks the file as being dirty and refresh its outer scope.
|
||||
*
|
||||
* @param {Document} document - the document that has changed
|
||||
*/
|
||||
function handleFileChange(document) {
|
||||
var path = document.file.fullPath,
|
||||
@@ -396,7 +472,12 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Receive an outer scope object from the parser worker
|
||||
* Receive an outer scope object from the parser worker and resolves any
|
||||
* deferred inner scope requests.
|
||||
*
|
||||
* @param {Object} response - the parser response object, which includes
|
||||
* the global scope and lists of identifiers, properties, globals,
|
||||
* literals and associations.
|
||||
*/
|
||||
function handleOuterScope(response) {
|
||||
var dir = response.dir,
|
||||
@@ -444,6 +525,7 @@ define(function (require, exports, module) {
|
||||
}
|
||||
}
|
||||
|
||||
// handle response objects, otherwise log the message
|
||||
outerScopeWorker.addEventListener("message", function (e) {
|
||||
var response = e.data,
|
||||
type = response.type;
|
||||
@@ -473,25 +555,19 @@ define(function (require, exports, module) {
|
||||
newDir = newSplit.dir,
|
||||
newFile = newSplit.file;
|
||||
|
||||
/*
|
||||
* Move property obj[olddir][oldfile] to obj[newdir][newfile]
|
||||
*/
|
||||
function moveProp(obj) {
|
||||
if (obj.hasOwnProperty(oldDir) && obj[oldDir].hasOwnProperty(oldFile)) {
|
||||
if (!obj.hasOwnProperty(newDir)) {
|
||||
obj[newDir] = {};
|
||||
}
|
||||
obj[newDir][newFile] = obj[oldDir][oldFile];
|
||||
delete obj[oldDir][oldFile];
|
||||
if (fileState.hasOwnProperty(oldDir) &&
|
||||
fileState[oldDir].hasOwnProperty(oldFile)) {
|
||||
if (!fileState.hasOwnProperty(newDir)) {
|
||||
fileState[newDir] = {};
|
||||
}
|
||||
fileState[newDir][newFile] = fileState[oldDir][oldFile];
|
||||
delete fileState[oldDir][oldFile];
|
||||
}
|
||||
|
||||
moveProp(fileState);
|
||||
});
|
||||
|
||||
|
||||
exports.handleEditorChange = handleEditorChange;
|
||||
exports.handleFileChange = handleFileChange;
|
||||
exports.getScopeInfo = getScopeInfo;
|
||||
exports.isScopeDirty = isScopeDirty;
|
||||
|
||||
});
|
||||
@@ -48,6 +48,10 @@ define(function (require, exports, module) {
|
||||
* Creates a hint response object. Filters the hint list using the query
|
||||
* string, formats the hints for display, and returns a hint response
|
||||
* object according to the CodeHintManager's API for code hint providers.
|
||||
*
|
||||
* @param {Array<Object>} hints - hints to be included in the response
|
||||
* @param {String} query - querystring with which to filter the hint list
|
||||
* @return {Object} - hint response as defined by the CodeHintManager API
|
||||
*/
|
||||
function getHintResponse(hints, query) {
|
||||
|
||||
@@ -56,13 +60,22 @@ define(function (require, exports, module) {
|
||||
formattedHints;
|
||||
|
||||
/*
|
||||
* Filter a list of tokens using a given query string
|
||||
* Filter a list of tokens using the query string in the closure.
|
||||
*
|
||||
* @param {Array<Object>} tokens - list of hints to filter
|
||||
* @param {Number} limit - maximum numberof tokens to return
|
||||
* @return {Array<Object>} - filtered list of hints
|
||||
*/
|
||||
function filterWithQuery(tokens, limit) {
|
||||
|
||||
/*
|
||||
* Filter arr using test, returning at most limit results from the
|
||||
* front of the array.
|
||||
*
|
||||
* @param {Array} arr - array to filter
|
||||
* @param {Function} test - test to determine if an element should
|
||||
* be included in the results
|
||||
* @param {Number} limit - the maximum number of elements to return
|
||||
*/
|
||||
function filterArrayPrefix(arr, test, limit) {
|
||||
var i = 0,
|
||||
@@ -107,7 +120,14 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a formatted list of hints with the query substring highlighted
|
||||
* Returns a formatted list of hints with the query substring
|
||||
* highlighted.
|
||||
*
|
||||
* @param {Array<Object>} hints - the list of hints to format
|
||||
* @param {String} query - querystring used for highlighting matched
|
||||
* poritions of each hint
|
||||
* @param {Array<jQuery.Object>} - array of hints formatted as jQuery
|
||||
* objects
|
||||
*/
|
||||
function formatHints(hints, query) {
|
||||
return hints.map(function (token) {
|
||||
@@ -197,6 +217,10 @@ define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Determine whether hints are available for a given editor context
|
||||
*
|
||||
* @param {Editor} editor - the current editor context
|
||||
* @param {String} key - charCode of the last pressed key
|
||||
* @param {Boolean} - can the provider provide hints for this session?
|
||||
*/
|
||||
JSHints.prototype.hasHints = function (editor, key) {
|
||||
if ((key === null) || HintUtils.maybeIdentifier(key)) {
|
||||
@@ -228,6 +252,10 @@ define(function (require, exports, module) {
|
||||
/**
|
||||
* Return a list of hints, possibly deferred, for the current editor
|
||||
* context
|
||||
*
|
||||
* @param {String} key - charCode of the last pressed key
|
||||
* @return {Object + jQuery.Deferred} - hint response (immediate or
|
||||
* deferred) as defined by the CodeHintManager API
|
||||
*/
|
||||
JSHints.prototype.getHints = function (key) {
|
||||
var cursor = session.getCursor(),
|
||||
@@ -293,9 +321,11 @@ define(function (require, exports, module) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Enters the code completion text into the editor
|
||||
* Inserts the hint selected by the user into the current editor.
|
||||
*
|
||||
* @param {string} hint - text to insert into current code editor
|
||||
* @param {jQuery.Object} hint - hint object to insert into current editor
|
||||
* @return {Boolean} - should a new hinting session be requested
|
||||
* immediately after insertion?
|
||||
*/
|
||||
JSHints.prototype.insertHint = function ($hintObj) {
|
||||
var hint = $hintObj.data("token"),
|
||||
@@ -348,6 +378,8 @@ define(function (require, exports, module) {
|
||||
/*
|
||||
* When the editor is changed, reset the hinting session and cached
|
||||
* information, and reject any pending deferred requests.
|
||||
*
|
||||
* @param {Editor} editor - editor context to be initialized.
|
||||
*/
|
||||
function initializeSession(editor) {
|
||||
ScopeManager.handleEditorChange(editor.document);
|
||||
@@ -360,6 +392,9 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Install editor change listeners
|
||||
*
|
||||
* @param {Editor} editor - editor context on which to listen for
|
||||
* changes
|
||||
*/
|
||||
function installEditorListeners(editor) {
|
||||
if (!editor) {
|
||||
@@ -377,6 +412,9 @@ define(function (require, exports, module) {
|
||||
|
||||
/*
|
||||
* Uninstall editor change listeners
|
||||
*
|
||||
* @param {Editor} editor - editor context on which to stop listening
|
||||
* for changes
|
||||
*/
|
||||
function uninstallEditorListeners(editor) {
|
||||
$(editor)
|
||||
@@ -387,6 +425,10 @@ define(function (require, exports, module) {
|
||||
* Handle the activeEditorChange event fired by EditorManager.
|
||||
* Uninstalls the change listener on the previous editor
|
||||
* and installs a change listener on the new editor.
|
||||
*
|
||||
* @param {Event} event - editor change event (ignored)
|
||||
* @param {Editor} current - the new current editor context
|
||||
* @param {Editor} previous - the previous editor context
|
||||
*/
|
||||
function handleActiveEditorChange(event, current, previous) {
|
||||
uninstallEditorListeners(previous);
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
* Loads a file that contains an AMD module definition using the web worker
|
||||
* importScripts global function.
|
||||
*
|
||||
* @param {String} url - The URL of the module to load
|
||||
* @param {String} url - the URL of the module to load
|
||||
* @return {Object} - the module imported from the aforementioned URL
|
||||
*/
|
||||
function require(url) {
|
||||
"use strict";
|
||||
@@ -43,6 +44,10 @@ function require(url) {
|
||||
* array of bindings, which are ignored. In the former case, the wrapper
|
||||
* function expects require, exports and module arguments; in the latter
|
||||
* case, the wrapper function expects only an exports arguments.
|
||||
*
|
||||
* @param {?Array<String>} bindings - an optional list of resources
|
||||
* required by the module
|
||||
* @param {Function} wrapper - the function that defines the module
|
||||
*/
|
||||
self.define = function (bindings, wrapper) {
|
||||
var module = { exports: exports },
|
||||
@@ -70,8 +75,14 @@ function require(url) {
|
||||
HintUtils = require("HintUtils.js"),
|
||||
esprima = require("thirdparty/esprima/esprima.js");
|
||||
|
||||
// maximum number of times a file will be reparsed before failing
|
||||
var MAX_RETRIES = 10;
|
||||
|
||||
/**
|
||||
* 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 });
|
||||
}
|
||||
@@ -79,13 +90,20 @@ function require(url) {
|
||||
/**
|
||||
* Walk the scope to find all the objects of a given type, along with a
|
||||
* list of their positions in the file.
|
||||
*
|
||||
* @param {Function} walk - the function used to walk over an implicit scope
|
||||
* @param {String} keyProp - the property of the implicit scope to walk over
|
||||
* @param {Array<Object>} - a list of hint tokens for the implicit scope,
|
||||
* including the positions at which they occur.
|
||||
*/
|
||||
function siftPositions(walk, keyProp) {
|
||||
var occurrences,
|
||||
results = [],
|
||||
key,
|
||||
token,
|
||||
comparator = function (a, b) { return a - b; };
|
||||
comparator = function (a, b) {
|
||||
return a - b;
|
||||
};
|
||||
|
||||
occurrences = walk(function (acc, token) {
|
||||
if (Object.prototype.hasOwnProperty.call(acc, token[keyProp])) {
|
||||
@@ -107,6 +125,12 @@ function require(url) {
|
||||
|
||||
/**
|
||||
* Walk the scope to compute all available association objects
|
||||
*
|
||||
* @param {Function} walk - the function used to walk over an implicit scope
|
||||
* @param {Object} - a set of association objects: each property is a
|
||||
* property name; each value is an association, which indicates the
|
||||
* number of times the property occurs w.r.t. to a particular lookup
|
||||
* context.
|
||||
*/
|
||||
function siftAssociations(walk) {
|
||||
return walk(function (acc, assoc) {
|
||||
@@ -128,31 +152,36 @@ function require(url) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for a JSLint globals annotation in the comments
|
||||
* Parse JSLint globals annotations from an array of JavaScript comments
|
||||
*
|
||||
* @param {Array<String>} comments - list of JavaScript comments
|
||||
* @return {Array<Object>} - a list of global hint objects as described by
|
||||
* JSLint annotations found in the comments.
|
||||
*/
|
||||
function extractGlobals(comments) {
|
||||
var globals = [];
|
||||
|
||||
if (comments) {
|
||||
comments.forEach(function (c) {
|
||||
if (c.type === "Block" && c.value) {
|
||||
if (c.value.indexOf("global") === 0) {
|
||||
c.value.substring(7).split(",").forEach(function (g) {
|
||||
var index = g.indexOf(":");
|
||||
comments.forEach(function (comment) {
|
||||
if (comment.type === "Block" && comment.value) {
|
||||
var val = comment.value;
|
||||
if (val.indexOf("global") === 0) {
|
||||
val.substring(7).split(",").forEach(function (global) {
|
||||
var index = global.indexOf(":");
|
||||
|
||||
if (index >= 0) {
|
||||
g = g.substring(0, index);
|
||||
global = global.substring(0, index);
|
||||
}
|
||||
globals.push(HintUtils.makeToken(g.trim()));
|
||||
globals.push(HintUtils.makeToken(global.trim()));
|
||||
});
|
||||
} else if (c.value.indexOf("jslint") === 0) {
|
||||
c.value.substring(7).split(",").forEach(function (e) {
|
||||
var index = e.indexOf(":"),
|
||||
prop = (index >= 0) ? e.substring(0, index).trim() : "",
|
||||
val = (index >= 0) ? e.substring(index + 1, e.length).trim() : "";
|
||||
} else if (val.indexOf("jslint") === 0) {
|
||||
val.substring(7).split(",").forEach(function (ann) {
|
||||
var index = ann.indexOf(":"),
|
||||
aKey = (index >= 0) ? ann.substring(0, index).trim() : "",
|
||||
aVal = (index >= 0) ? ann.substring(index + 1, ann.length).trim() : "";
|
||||
|
||||
if (val === "true" && HintUtils.JSL_GLOBAL_DEFS.hasOwnProperty(prop)) {
|
||||
globals = globals.concat(HintUtils.JSL_GLOBAL_DEFS[prop]);
|
||||
if (aVal === "true" && HintUtils.JSL_GLOBAL_DEFS.hasOwnProperty(aKey)) {
|
||||
globals = globals.concat(HintUtils.JSL_GLOBAL_DEFS[aKey]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -164,6 +193,12 @@ function require(url) {
|
||||
|
||||
/**
|
||||
* Send the scope and associated parse information back to the caller.
|
||||
* Called by the parse function below.
|
||||
*
|
||||
* @param {String} dir - the directory name of the parsed file
|
||||
* @param {String} file - the file name of the parsed file
|
||||
* @param {Number} length - the length of the parsed file
|
||||
* @param {Object} parseObj - scope and token data from the parsed file
|
||||
*/
|
||||
function respond(dir, file, length, parseObj) {
|
||||
var success = !!parseObj,
|
||||
@@ -195,7 +230,16 @@ function require(url) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use Esprima to parse a JavaScript text
|
||||
* Parse a JavaScript text with Esprima. This function is intended to be
|
||||
* called asynchronously; the respond function above is called with the
|
||||
* results of parsing.
|
||||
*
|
||||
* @param {String} dir - the directory name of the file to parse
|
||||
* @param {String} file - the file name of the file to parse
|
||||
* @param {String} text - the text of the file to parse
|
||||
* @param {Number} retries - the number of times an unparseable text should
|
||||
* be retried, after blanking whatever lines are causing the parsing
|
||||
* errors.
|
||||
*/
|
||||
function parse(dir, file, text, retries) {
|
||||
try {
|
||||
|
||||
@@ -43,9 +43,12 @@ define(function (require, exports, module) {
|
||||
/**
|
||||
* Returns an Editor suitable for use in isolation: i.e., a Document that
|
||||
* will never be set as the currentDocument or added to the working set.
|
||||
* @return {!Editor}
|
||||
*
|
||||
* @param {Document} doc - the document to be contained by the new Editor
|
||||
* @param {String} mode - the CodeMirror mode of the new Editor
|
||||
* @return {Editor} - the mock editor object
|
||||
*/
|
||||
function createMockEditor(doc, mode, visibleRange) {
|
||||
function createMockEditor(doc, mode) {
|
||||
mode = mode || "";
|
||||
|
||||
// Initialize EditorManager
|
||||
@@ -55,14 +58,23 @@ define(function (require, exports, module) {
|
||||
$("body").append($editorHolder);
|
||||
|
||||
// create Editor instance
|
||||
var editor = new Editor(doc, true, mode, $editorHolder.get(0), visibleRange);
|
||||
var editor = new Editor(doc, true, mode, $editorHolder.get(0));
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
describe("JavaScript Code Hinting", function () {
|
||||
|
||||
// Ask provider for hints at current cursor position; expect it to return some
|
||||
/*
|
||||
* Ask provider for hints at current cursor position; expect it to
|
||||
* return some
|
||||
*
|
||||
* @param {Object} provider - a CodeHintProvider object
|
||||
* @param {String} key - the charCode of a key press that triggers the
|
||||
* CodeHint provider
|
||||
* @return {Boolean} - whether the provider has hints in the context of
|
||||
* the test editor
|
||||
*/
|
||||
function expectHints(provider, key) {
|
||||
if (key === undefined) {
|
||||
key = null;
|
||||
@@ -72,7 +84,14 @@ define(function (require, exports, module) {
|
||||
return provider.getHints(null);
|
||||
}
|
||||
|
||||
// Ask provider for hints at current cursor position; expect it NOT to return any
|
||||
/*
|
||||
* Ask provider for hints at current cursor position; expect it NOT to
|
||||
* return any
|
||||
*
|
||||
* @param {Object} provider - a CodeHintProvider object
|
||||
* @param {String} key - the charCode of a key press that triggers the
|
||||
* CodeHint provider
|
||||
*/
|
||||
function expectNoHints(provider, key) {
|
||||
|
||||
if (key === undefined) {
|
||||
@@ -82,6 +101,14 @@ define(function (require, exports, module) {
|
||||
expect(provider.hasHints(testEditor, key)).toBe(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the index at which hint occurs in hintList
|
||||
*
|
||||
* @param {Array<Object>} hintList - the list of hints
|
||||
* @param {String} hint - the hint to search for
|
||||
* @return {Number} - the index into hintList at which the hint occurs,
|
||||
* or -1 if it does not
|
||||
*/
|
||||
function _indexOf(hintList, hint) {
|
||||
var index = -1,
|
||||
counter = 0;
|
||||
@@ -95,6 +122,15 @@ define(function (require, exports, module) {
|
||||
return index;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for a hint response object to resolve, then apply a callback
|
||||
* to the result
|
||||
*
|
||||
* @param {Object + jQuery.Deferred} hintObj - a hint response object,
|
||||
* possibly deferred
|
||||
* @param {Function} callback - the callback to apply to the resolved
|
||||
* hint response object
|
||||
*/
|
||||
function _waitForHints(hintObj, callback) {
|
||||
var complete = false,
|
||||
hintList = null;
|
||||
@@ -115,17 +151,34 @@ define(function (require, exports, module) {
|
||||
|
||||
runs(function () { callback(hintList); });
|
||||
}
|
||||
|
||||
|
||||
function hintsAbsent(hintObj, expectedHints) {
|
||||
|
||||
/*
|
||||
* Expect a given list of hints to be absent from a given hint
|
||||
* response object
|
||||
*
|
||||
* @param {Object + jQuery.Deferred} hintObj - a hint response object,
|
||||
* possibly deferred
|
||||
* @param {Array<String>} absentHints - a list of hints that should not
|
||||
* be present in the hint response
|
||||
*/
|
||||
function hintsAbsent(hintObj, absentHints) {
|
||||
_waitForHints(hintObj, function (hintList) {
|
||||
expect(hintList).not.toBeNull();
|
||||
expectedHints.forEach(function (expectedHint) {
|
||||
expect(_indexOf(hintList, expectedHint)).toBe(-1);
|
||||
absentHints.forEach(function (absentHint) {
|
||||
expect(_indexOf(hintList, absentHint)).toBe(-1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Expect a given list of hints to be present in a given hint
|
||||
* response object
|
||||
*
|
||||
* @param {Object + jQuery.Deferred} hintObj - a hint response object,
|
||||
* possibly deferred
|
||||
* @param {Array<String>} absentHints - a list of hints that should be
|
||||
* present in the hint response
|
||||
*/
|
||||
function hintsPresent(hintObj, expectedHints) {
|
||||
_waitForHints(hintObj, function (hintList) {
|
||||
expect(hintList).not.toBeNull();
|
||||
@@ -135,6 +188,15 @@ define(function (require, exports, module) {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Expect a given list of hints to be present in the given order in a
|
||||
* given hint response object
|
||||
*
|
||||
* @param {Object + jQuery.Deferred} hintObj - a hint response object,
|
||||
* possibly deferred
|
||||
* @param {Array<String>} absentHints - a list of hints that should be
|
||||
* present in the given order in the hint response
|
||||
*/
|
||||
function hintsPresentOrdered(hintObj, expectedHints) {
|
||||
var prevIndex = -1,
|
||||
currIndex;
|
||||
@@ -148,7 +210,16 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Expect a given list of hints to be present in a given hint
|
||||
* response object, and no more.
|
||||
*
|
||||
* @param {Object + jQuery.Deferred} hintObj - a hint response object,
|
||||
* possibly deferred
|
||||
* @param {Array<String>} absentHints - a list of hints that should be
|
||||
* present in the hint response, and no more.
|
||||
*/
|
||||
function hintsPresentExact(hintObj, expectedHints) {
|
||||
_waitForHints(hintObj, function (hintList) {
|
||||
expect(hintList).not.toBeNull();
|
||||
@@ -157,7 +228,18 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Simulation of selection of a particular hint in a hint list.
|
||||
* Presumably results in side effects in the hint provider's
|
||||
* current editor context.
|
||||
*
|
||||
* @param {Object} provider - a CodeHint provider object
|
||||
* @param {Object} hintObj - a hint response object from that provider,
|
||||
* possibly deferred
|
||||
* @param {Number} index - the index into the hint list at which a hint
|
||||
* is to be selected
|
||||
*/
|
||||
function selectHint(provider, hintObj, index) {
|
||||
var hintList = expectHints(provider);
|
||||
_waitForHints(hintObj, function (hintList) {
|
||||
@@ -166,7 +248,7 @@ define(function (require, exports, module) {
|
||||
expect(provider.insertHint(hintList[index])).toBe(false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
describe("JavaScript Code Hinting", function () {
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
Reference in new issue
Block a user