Bug 1217198 - Better autocompletion for template literals; r=Honza.

Add a new template literal state to findCompletionBeginning so we can
better handle the autocompletion for them.

Differential Revision: https://phabricator.services.mozilla.com/D4853
This commit is contained in:
Nicolas Chevobbe
2018-09-05 11:37:33 +00:00
parent 12a455fad4
commit 334b7e5e5b
2 changed files with 29 additions and 3 deletions

View File

@@ -19,9 +19,10 @@ const MAX_AUTOCOMPLETE_ATTEMPTS = exports.MAX_AUTOCOMPLETE_ATTEMPTS = 100000;
// Prevent iterating over too many properties during autocomplete suggestions.
const MAX_AUTOCOMPLETIONS = exports.MAX_AUTOCOMPLETIONS = 1500;
const STATE_NORMAL = 0;
const STATE_QUOTE = 2;
const STATE_DQUOTE = 3;
const STATE_NORMAL = Symbol("STATE_NORMAL");
const STATE_QUOTE = Symbol("STATE_QUOTE");
const STATE_DQUOTE = Symbol("STATE_DQUOTE");
const STATE_TEMPLATE_LITERAL = Symbol("STATE_TEMPLATE_LITERAL");
const OPEN_BODY = "{[(".split("");
const CLOSE_BODY = "}])".split("");
@@ -73,6 +74,8 @@ function findCompletionBeginning(str) {
state = STATE_DQUOTE;
} else if (c == "'") {
state = STATE_QUOTE;
} else if (c == "`") {
state = STATE_TEMPLATE_LITERAL;
} else if (c == ";") {
start = i + 1;
} else if (c == " ") {
@@ -137,6 +140,15 @@ function findCompletionBeginning(str) {
}
break;
// Template literal state > ` <
case STATE_TEMPLATE_LITERAL:
if (c == "\\") {
i++;
} else if (c == "`") {
state = STATE_NORMAL;
}
break;
// Single quote state > ' <
case STATE_QUOTE:
if (c == "\\") {