Commit 122462a5 authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Fix keywords being duplicated by autocomplete cache

Change-Id: I922866e17652a3f202207a5e690e97d2da26065f
Reviewed-on: https://chromium-review.googlesource.com/879065Reviewed-by: default avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533191}
parent e1703185
...@@ -155,4 +155,10 @@ Found: "\"double-qouted\""], displayed as "\"double-qouted\"" ...@@ -155,4 +155,10 @@ Found: "\"double-qouted\""], displayed as "\"double-qouted\""
Checking 'complicatedObject["notDangerous();' Checking 'complicatedObject["notDangerous();'
Found: "notDangerous();"], displayed as "notDangerous();" Found: "notDangerous();"], displayed as "notDangerous();"
Checking 'queryOb'
Found: queryObjects
Checking 'fun'
Found: function
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
var consoleEditor; var consoleEditor;
/**
* @param {string} text
* @param {!Array<string>} expected
* @param {boolean=} force
*/
function testCompletions(text, expected, force) { function testCompletions(text, expected, force) {
var cursorPosition = text.indexOf('|'); var cursorPosition = text.indexOf('|');
...@@ -41,8 +46,11 @@ ...@@ -41,8 +46,11 @@
consoleEditor._autocompleteController.autocomplete(force); consoleEditor._autocompleteController.autocomplete(force);
return TestRunner.addSnifferPromise(consoleEditor._autocompleteController, '_onSuggestionsShownForTest').then(checkExpected); return TestRunner.addSnifferPromise(consoleEditor._autocompleteController, '_onSuggestionsShownForTest').then(checkExpected);
/**
* @param {!Array<{text: string, title: string}>} suggestions
*/
function checkExpected(suggestions) { function checkExpected(suggestions) {
var completions = new Map(suggestions.map(suggestion => [suggestion.text, suggestion])); var completions = new Map(suggestions.map(suggestion => [suggestion, suggestion.text])).inverse();
var message = 'Checking \'' + text.replace('\n', '\\n').replace('\r', '\\r') + '\''; var message = 'Checking \'' + text.replace('\n', '\\n').replace('\r', '\\r') + '\'';
if (force) if (force)
...@@ -52,10 +60,12 @@ ...@@ -52,10 +60,12 @@
for (var i = 0; i < expected.length; i++) { for (var i = 0; i < expected.length; i++) {
if (completions.has(expected[i])) { if (completions.has(expected[i])) {
if (completions.get(expected[i]).title) for (var completion of completions.get(expected[i])) {
TestRunner.addResult('Found: ' + expected[i] + ', displayed as ' + completions.get(expected[i]).title); if (completion.title)
else TestRunner.addResult('Found: ' + expected[i] + ', displayed as ' + completion.title);
TestRunner.addResult('Found: ' + expected[i]); else
TestRunner.addResult('Found: ' + expected[i]);
}
} else { } else {
TestRunner.addResult('Not Found: ' + expected[i]); TestRunner.addResult('Not Found: ' + expected[i]);
} }
...@@ -122,6 +132,8 @@ ...@@ -122,6 +132,8 @@
() => testCompletions('complicatedObject[\'\\\'sing', ['\'\\\'single-qouted\\\'\']']), () => testCompletions('complicatedObject[\'\\\'sing', ['\'\\\'single-qouted\\\'\']']),
() => testCompletions('complicatedObject["\'single-qou', ['"\'single-qouted\'"]']), () => testCompletions('complicatedObject["\'single-qou', ['"\'single-qouted\'"]']),
() => testCompletions('complicatedObject["\\"double-qouted\\"', ['"\\"double-qouted\\""]']), () => testCompletions('complicatedObject["\\"double-qouted\\"', ['"\\"double-qouted\\""]']),
() => testCompletions('complicatedObject["notDangerous();', ['"notDangerous();"]']) () => testCompletions('complicatedObject["notDangerous();', ['"notDangerous();"]']),
() => testCompletions('queryOb', ["queryObjects"]),
() => testCompletions('fun', ['function'])
]).then(TestRunner.completeTest); ]).then(TestRunner.completeTest);
})(); })();
...@@ -211,7 +211,8 @@ ObjectUI.JavaScriptAutocomplete = class { ...@@ -211,7 +211,8 @@ ObjectUI.JavaScriptAutocomplete = class {
this._expressionCache.set(expressionString, cache); this._expressionCache.set(expressionString, cache);
completionGroups = await cache.value; completionGroups = await cache.value;
} }
return this._receivedPropertyNames(completionGroups, dotNotation, bracketNotation, expressionString, query); return this._receivedPropertyNames(
completionGroups.slice(0), dotNotation, bracketNotation, expressionString, query);
/** /**
* @this {ObjectUI.JavaScriptAutocomplete} * @this {ObjectUI.JavaScriptAutocomplete}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment