Skip to content

Commit

Permalink
case insensitive matches, middle matching, and use tern rawCompletion…
Browse files Browse the repository at this point in the history
…s request
  • Loading branch information
dloverin committed Mar 25, 2013
1 parent cb4e0c6 commit f4bcdfc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
[submodule "src/thirdparty/mustache"]
path = src/thirdparty/mustache
url = https://github.com/janl/mustache.js.git
[submodule "src/extensions/default/JavaScriptCodeHints/tern"]
path = src/extensions/default/JavaScriptCodeHints/tern
url = https://github.com/eztierney/tern
[submodule "src/extensions/default/JavaScriptCodeHints/acorn"]
path = src/extensions/default/JavaScriptCodeHints/acorn
url = https://github.com/eztierney/acorn
[submodule "src/extensions/default/JavaScriptCodeHints/tern"]
path = src/extensions/default/JavaScriptCodeHints/tern
url = http://github.com/dloverin/tern.git
2 changes: 1 addition & 1 deletion src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ define(function (require, exports, module) {
return request;
}

var request = buildRequest(dir, file, "completions", offset);
var request = buildRequest(dir, file, "rawCompletions", offset);
var ternHints = [];
ternServer.request(request, function(error, data) {
//if (error) return displayError(error);
Expand Down
1 change: 1 addition & 0 deletions src/extensions/default/JavaScriptCodeHints/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ define(function (require, exports, module) {
var ternHints = ScopeManager.getTernHints("dir", "file", offset, this.editor.document.getText());
if( ternHints && ternHints.length > 0 ) {
hints = ternHints;
hints.sort(compareByName);
}
else{
hints = copyHints(this.properties);
Expand Down
32 changes: 28 additions & 4 deletions src/extensions/default/JavaScriptCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ define(function (require, exports, module) {
cachedScope = null, // the inner-most scope returned by the query worker
cachedLine = null; // the line number for the cached scope

var MAX_DISPLAYED_HINTS = 100;
var MAX_DISPLAYED_HINTS = 100,
QUERY_PREFIX_LENGTH = 1; // Any query of this size or less is matched as a prefix of a hint.

/**
* Creates a hint response object. Filters the hint list using the query
Expand Down Expand Up @@ -102,7 +103,11 @@ define(function (require, exports, module) {
if (trimmedQuery !== query) {
return filterArrayPrefix(tokens, function (token) {
if (token.literal && token.kind === "string") {
return (token.value.indexOf(trimmedQuery) === 0);
if (query.length > (QUERY_PREFIX_LENGTH + 1)) {
return (token.value.toLowerCase().indexOf(trimmedQuery.toLowerCase()) !== -1);
} else {
return (token.value.toLowerCase().indexOf(trimmedQuery.toLowerCase()) === 0);
}
} else {
return false;
}
Expand All @@ -112,7 +117,11 @@ define(function (require, exports, module) {
if (token.literal && token.kind === "string") {
return false;
} else {
return (token.value.indexOf(query) === 0);
if (query.length > QUERY_PREFIX_LENGTH) {
return (token.value.toLowerCase().indexOf(query.toLowerCase()) !== -1);
} else {
return (token.value.toLowerCase().indexOf(query.toLowerCase()) === 0);
}
}
}, limit);
} else {
Expand All @@ -131,9 +140,24 @@ define(function (require, exports, module) {
* objects
*/
function formatHints(hints, query) {
if (query.length > QUERY_PREFIX_LENGTH) {
hints.sort(function (hint1, hint2) {
var index1 = hint1.value.toLowerCase().indexOf(query.toLowerCase()),
index2 = hint2.value.toLowerCase().indexOf(query.toLowerCase());

if (index1 === 0 && index2 !== 0) {
return -1;
} else if (index1 !== 0 && index2 === 0) {
return 1;
}

return 0;
});
}

return hints.map(function (token) {
var hint = token.value,
index = hint.indexOf(query),
index = hint.toLowerCase().indexOf(query.toLowerCase()),
$hintObj = $("<span>").addClass("brackets-js-hints"),
delimiter = "";

Expand Down

0 comments on commit f4bcdfc

Please sign in to comment.