Merge pull request #4 from dloverin/more-tern

More tern
This commit is contained in:
Erik Tierney committed 2013-03-29 12:02:07 -07:00
commit 8a6d29fbc4
3 files changed
+27 -4

No files matched your search

@@ -74,7 +74,7 @@ define(function (require, exports, module) {
*/
function initTernEnv() {
var path = module.uri.substring(0, module.uri.lastIndexOf("/") + 1) + "tern/defs/";
var files = ["ecma5.json"];//, "browser.json", "plugin/requirejs/requirejs.json", "jquery.json"];
var files = ["ecma5.json", "browser.json"];//, "plugin/requirejs/requirejs.json", "jquery.json"];
var dirEntry = new NativeFileSystem.DirectoryEntry(path),
reader = dirEntry.createReader();
@@ -173,14 +173,14 @@ define(function (require, exports, module) {
query = "";
if (token) {
if (token.string !== ".") {
if (token.string !== "." && token.string !== "(" && token.string !== ',') {
query = token.string.substring(0, token.string.length - (token.end - cursor.ch));
query = query.trim();
}
}
return query;
};
/**
* Find the context of a property lookup. For example, for a lookup
* foo(bar, baz(quux)).prop, foo is the context.
@@ -129,6 +129,27 @@ define(function (require, exports, module) {
}
}
/*
* Comparator for sorting tokens by name
*
* @param {Object} a - a token
* @param {Object} b - another token
* @return {number} - comparator value that indicates whether the name
* of token a is lexicographically lower than the name of token b
*/
function compareByName(a, b) {
var aLowerCase = a.value.toLowerCase();
var bLowerCase = b.value.toLowerCase();
if (aLowerCase === bLowerCase) {
return 0;
} else if (aLowerCase < bLowerCase) {
return -1;
} else {
return 1;
}
}
/*
* Returns a formatted list of hints with the query substring
* highlighted.
@@ -141,6 +162,8 @@ define(function (require, exports, module) {
*/
function formatHints(hints, query) {
if (query.length > QUERY_PREFIX_LENGTH) {
// raise the hints that match on prefix to the top of the list.
hints.sort(function (hint1, hint2) {
var index1 = hint1.value.toLowerCase().indexOf(query.toLowerCase()),
index2 = hint2.value.toLowerCase().indexOf(query.toLowerCase());
@@ -151,7 +174,7 @@ define(function (require, exports, module) {
return 1;
}
return 0;
return compareByName(hint1, hint2);
});
}