Skip to content

Commit 2246a3a

Browse files
author
Mostafa Eweda
committed
Fix asyncReplace argument + cleanup to a single version of retrieve...Identifier
1 parent 84d26b3 commit 2246a3a

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

plugins-client/ext.codecomplete/complete_util.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var ID_REGEX = /[a-zA-Z_0-9\$]/;
55
function retrievePreceedingIdentifier(text, pos, regex) {
66
regex = regex || ID_REGEX;
77
var buf = [];
8-
for (var i = pos-1; i >= 0; i--) {
8+
for(var i = pos-1; i >= 0; i--) {
99
if(regex.test(text[i]))
1010
buf.push(text[i]);
1111
else
@@ -14,6 +14,18 @@ function retrievePreceedingIdentifier(text, pos, regex) {
1414
return buf.reverse().join("");
1515
}
1616

17+
function retrieveFollowingIdentifier(text, pos, regex) {
18+
regex = regex || ID_REGEX;
19+
var buf = [];
20+
for (var i = pos; i < text.length; i++) {
21+
if (regex.test(text[i]))
22+
buf.push(text[i]);
23+
else
24+
break;
25+
}
26+
return buf;
27+
}
28+
1729
function prefixBinarySearch(items, prefix) {
1830
var startIndex = 0;
1931
var stopIndex = items.length - 1;
@@ -61,6 +73,7 @@ function fetchText(staticPrefix, path) {
6173
}
6274

6375
exports.retrievePreceedingIdentifier = retrievePreceedingIdentifier;
76+
exports.retrieveFollowingIdentifier = retrieveFollowingIdentifier;
6477
exports.findCompletions = findCompletions;
6578
exports.fetchText = fetchText;
6679

plugins-client/ext.language/complete.js

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var editors = require("ext/editors/editors");
1313
var code = require("ext/code/code");
1414
var dom = require("ace/lib/dom");
1515
var keyhandler = require("ext/language/keyhandler");
16+
var completeUtil = require("ext/codecomplete/complete_util");
1617

1718
var lang = require("ace/lib/lang");
1819
var language;
@@ -78,30 +79,6 @@ function isPopupVisible() {
7879
return barCompleterCont.$ext.style.display !== "none";
7980
}
8081

81-
function retrievePreceedingIdentifier(text, pos, regex) {
82-
regex = regex || ID_REGEX;
83-
var buf = [];
84-
for(var i = pos-1; i >= 0; i--) {
85-
if(regex.test(text[i]))
86-
buf.push(text[i]);
87-
else
88-
break;
89-
}
90-
return buf.reverse().join("");
91-
}
92-
93-
function retrieveFollowingIdentifier(text, pos, regex) {
94-
regex = regex || ID_REGEX;
95-
var buf = [];
96-
for (var i = pos; i < text.length; i++) {
97-
if (regex.test(text[i]))
98-
buf.push(text[i]);
99-
else
100-
break;
101-
}
102-
return buf;
103-
}
104-
10582
function isJavaScript() {
10683
return editors.currentEditor.amlEditor.syntax === "javascript";
10784
}
@@ -119,7 +96,7 @@ function isHtml() {
11996
function replaceText(editor, match) {
12097
// Replace text asynchronously in case Concorde didn't update the editor yet
12198
setTimeout(function() {
122-
asyncReplaceText(editor, prefix, match);
99+
asyncReplaceText(editor, match);
123100
}, CONCORDE_DELAY);
124101
}
125102

@@ -128,7 +105,7 @@ function asyncReplaceText(editor, match) {
128105
var pos = editor.getCursorPosition();
129106
var line = editor.getSession().getLine(pos.row);
130107
var doc = editor.getSession().getDocument();
131-
var prefix = retrievePreceedingIdentifier(line, pos.column, match.idRegex);
108+
var prefix = completeUtil.retrievePreceedingIdentifier(line, pos.column, match.idRegex);
132109

133110
if (match.replaceText === "require(^^)" && isJavaScript()) {
134111
newText = "require(\"^^\")";
@@ -148,11 +125,11 @@ function asyncReplaceText(editor, match) {
148125
var prefixWhitespace = line.substring(0, i);
149126

150127
// Remove HTML duplicate '<' completions
151-
var preId = retrievePreceedingIdentifier(line, pos.column, match.idRegex);
128+
var preId = completeUtil.retrievePreceedingIdentifier(line, pos.column, match.idRegex);
152129
if (isHtml() && line[pos.column-preId.length-1] === '<' && newText[0] === '<')
153130
newText = newText.substring(1);
154131

155-
var postfix = retrieveFollowingIdentifier(line, pos.column, match.idRegex) || "";
132+
var postfix = completeUtil.retrieveFollowingIdentifier(line, pos.column, match.idRegex) || "";
156133

157134
// Pad the text to be inserted
158135
var paddedLines = newText.split("\n").join("\n" + prefixWhitespace);
@@ -321,7 +298,7 @@ module.exports = {
321298
docHead = match.name + " : " + _self.$guidToLongString(match.type) + "</div>";
322299
}
323300
}
324-
var prefix = retrievePreceedingIdentifier(line, pos.column, match.idRegex);
301+
var prefix = completeUtil.retrievePreceedingIdentifier(line, pos.column, match.idRegex);
325302
var trim = match.meta ? " maintrim" : "";
326303
if (!isInferAvailable || match.icon) {
327304
html += '<span class="main' + trim + '"><u>' + prefix + "</u>" + match.name.substring(prefix.length) + '</span>';
@@ -550,7 +527,7 @@ module.exports = {
550527
// Remove out-of-date matches
551528
for (var i = 0; i < matches.length; i++) {
552529
idRegex = idRegex || matches[i].idRegex;
553-
identifier = retrievePreceedingIdentifier(line, pos.column, matches[i].idRegex);
530+
identifier = completeUtil.retrievePreceedingIdentifier(line, pos.column, matches[i].idRegex);
554531
if(matches[i].name.indexOf(identifier) !== 0) {
555532
matches.splice(i, 1);
556533
i--;
@@ -562,7 +539,7 @@ module.exports = {
562539
replaceText(editor, matches[0]);
563540
}
564541
else if (matches.length > 0) {
565-
identifier = retrievePreceedingIdentifier(line, pos.column, idRegex);
542+
identifier = completeUtil.retrievePreceedingIdentifier(line, pos.column, idRegex);
566543
this.showCompletionBox(matches, identifier);
567544
}
568545
else {

0 commit comments

Comments
 (0)