Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/object_ui/JavaScriptAutocomplete.js

Issue 2712513002: DevTools: extract ObjectUI module from Components (Closed)
Patch Set: fix build.gn Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 Components.JavaScriptAutocomplete = {}; 5 ObjectUI.JavaScriptAutocomplete = {};
6 6
7 /** @typedef {{title:(string|undefined), items:Array<string>}} */ 7 /** @typedef {{title:(string|undefined), items:Array<string>}} */
8 Components.JavaScriptAutocomplete.CompletionGroup; 8 ObjectUI.JavaScriptAutocomplete.CompletionGroup;
9 9
10 /** 10 /**
11 * @param {string} text 11 * @param {string} text
12 * @param {string} query 12 * @param {string} query
13 * @param {boolean=} force 13 * @param {boolean=} force
14 * @return {!Promise<!UI.SuggestBox.Suggestions>} 14 * @return {!Promise<!UI.SuggestBox.Suggestions>}
15 */ 15 */
16 Components.JavaScriptAutocomplete.completionsForTextInCurrentContext = function( text, query, force) { 16 ObjectUI.JavaScriptAutocomplete.completionsForTextInCurrentContext = function(te xt, query, force) {
17 var clippedExpression = Components.JavaScriptAutocomplete._clipExpression(text , true); 17 var clippedExpression = ObjectUI.JavaScriptAutocomplete._clipExpression(text, true);
18 var mapCompletionsPromise = Components.JavaScriptAutocomplete._mapCompletions( text, query); 18 var mapCompletionsPromise = ObjectUI.JavaScriptAutocomplete._mapCompletions(te xt, query);
19 return Components.JavaScriptAutocomplete.completionsForExpression(clippedExpre ssion, query, force) 19 return ObjectUI.JavaScriptAutocomplete.completionsForExpression(clippedExpress ion, query, force)
20 .then(completions => mapCompletionsPromise.then(mapCompletions => mapCompl etions.concat(completions))); 20 .then(completions => mapCompletionsPromise.then(mapCompletions => mapCompl etions.concat(completions)));
21 }; 21 };
22 22
23 /** 23 /**
24 * @param {string} text 24 * @param {string} text
25 * @param {boolean=} allowEndingBracket 25 * @param {boolean=} allowEndingBracket
26 * @return {string} 26 * @return {string}
27 */ 27 */
28 Components.JavaScriptAutocomplete._clipExpression = function(text, allowEndingBr acket) { 28 ObjectUI.JavaScriptAutocomplete._clipExpression = function(text, allowEndingBrac ket) {
29 var index; 29 var index;
30 var stopChars = new Set('=:({;,!+-*/&|^<>`'.split('')); 30 var stopChars = new Set('=:({;,!+-*/&|^<>`'.split(''));
31 var whiteSpaceChars = new Set(' \r\n\t'.split('')); 31 var whiteSpaceChars = new Set(' \r\n\t'.split(''));
32 var continueChars = new Set('[. \r\n\t'.split('')); 32 var continueChars = new Set('[. \r\n\t'.split(''));
33 33
34 for (index = text.length - 1; index >= 0; index--) { 34 for (index = text.length - 1; index >= 0; index--) {
35 if (stopChars.has(text.charAt(index))) 35 if (stopChars.has(text.charAt(index)))
36 break; 36 break;
37 if (whiteSpaceChars.has(text.charAt(index)) && !continueChars.has(text.charA t(index - 1))) 37 if (whiteSpaceChars.has(text.charAt(index)) && !continueChars.has(text.charA t(index - 1)))
38 break; 38 break;
(...skipping 15 matching lines...) Expand all
54 index--; 54 index--;
55 } 55 }
56 return clippedExpression.substring(index + 1).trim(); 56 return clippedExpression.substring(index + 1).trim();
57 }; 57 };
58 58
59 /** 59 /**
60 * @param {string} text 60 * @param {string} text
61 * @param {string} query 61 * @param {string} query
62 * @return {!Promise<!UI.SuggestBox.Suggestions>} 62 * @return {!Promise<!UI.SuggestBox.Suggestions>}
63 */ 63 */
64 Components.JavaScriptAutocomplete._mapCompletions = function(text, query) { 64 ObjectUI.JavaScriptAutocomplete._mapCompletions = function(text, query) {
65 var mapMatch = text.match(/\.\s*(get|set|delete)\s*\(\s*$/); 65 var mapMatch = text.match(/\.\s*(get|set|delete)\s*\(\s*$/);
66 var executionContext = UI.context.flavor(SDK.ExecutionContext); 66 var executionContext = UI.context.flavor(SDK.ExecutionContext);
67 if (!executionContext || !mapMatch) 67 if (!executionContext || !mapMatch)
68 return Promise.resolve([]); 68 return Promise.resolve([]);
69 69
70 var clippedExpression = Components.JavaScriptAutocomplete._clipExpression(text .substring(0, mapMatch.index)); 70 var clippedExpression = ObjectUI.JavaScriptAutocomplete._clipExpression(text.s ubstring(0, mapMatch.index));
71 var fulfill; 71 var fulfill;
72 var promise = new Promise(x => fulfill = x); 72 var promise = new Promise(x => fulfill = x);
73 executionContext.evaluate(clippedExpression, 'completion', true, true, false, false, false, evaluated); 73 executionContext.evaluate(clippedExpression, 'completion', true, true, false, false, false, evaluated);
74 return promise; 74 return promise;
75 75
76 /** 76 /**
77 * @param {?SDK.RemoteObject} result 77 * @param {?SDK.RemoteObject} result
78 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails 78 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
79 */ 79 */
80 function evaluated(result, exceptionDetails) { 80 function evaluated(result, exceptionDetails) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 fulfill(suggestions); 154 fulfill(suggestions);
155 } 155 }
156 }; 156 };
157 157
158 /** 158 /**
159 * @param {string} expressionString 159 * @param {string} expressionString
160 * @param {string} query 160 * @param {string} query
161 * @param {boolean=} force 161 * @param {boolean=} force
162 * @return {!Promise<!UI.SuggestBox.Suggestions>} 162 * @return {!Promise<!UI.SuggestBox.Suggestions>}
163 */ 163 */
164 Components.JavaScriptAutocomplete.completionsForExpression = function(expression String, query, force) { 164 ObjectUI.JavaScriptAutocomplete.completionsForExpression = function(expressionSt ring, query, force) {
165 var executionContext = UI.context.flavor(SDK.ExecutionContext); 165 var executionContext = UI.context.flavor(SDK.ExecutionContext);
166 if (!executionContext) 166 if (!executionContext)
167 return Promise.resolve([]); 167 return Promise.resolve([]);
168 168
169 var lastIndex = expressionString.length - 1; 169 var lastIndex = expressionString.length - 1;
170 170
171 var dotNotation = (expressionString[lastIndex] === '.'); 171 var dotNotation = (expressionString[lastIndex] === '.');
172 var bracketNotation = (expressionString.length > 1 && expressionString[lastInd ex] === '['); 172 var bracketNotation = (expressionString.length > 1 && expressionString[lastInd ex] === '[');
173 173
174 if (dotNotation || bracketNotation) 174 if (dotNotation || bracketNotation)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 '(' + getCompletions + ')("' + result.type + '")', 'completion', fal se, true, true, false, false, 286 '(' + getCompletions + ')("' + result.type + '")', 'completion', fal se, true, true, false, false,
287 receivedPropertyNamesFromEval); 287 receivedPropertyNamesFromEval);
288 } 288 }
289 } 289 }
290 290
291 extractTarget(result).then(completionsForObject); 291 extractTarget(result).then(completionsForObject);
292 } 292 }
293 293
294 /** 294 /**
295 * @param {!SDK.DebuggerModel.CallFrame} callFrame 295 * @param {!SDK.DebuggerModel.CallFrame} callFrame
296 * @param {function(!Array<!Components.JavaScriptAutocomplete.CompletionGroup> )} callback 296 * @param {function(!Array<!ObjectUI.JavaScriptAutocomplete.CompletionGroup>)} callback
297 */ 297 */
298 function variableNamesInScopes(callFrame, callback) { 298 function variableNamesInScopes(callFrame, callback) {
299 var result = [{items: ['this']}]; 299 var result = [{items: ['this']}];
300 300
301 /** 301 /**
302 * @param {string} name 302 * @param {string} name
303 * @param {?Array<!SDK.RemoteObjectProperty>} properties 303 * @param {?Array<!SDK.RemoteObjectProperty>} properties
304 */ 304 */
305 function propertiesCollected(name, properties) { 305 function propertiesCollected(name, properties) {
306 var group = {title: name, items: []}; 306 var group = {title: name, items: []};
(...skipping 29 matching lines...) Expand all
336 336
337 /** 337 /**
338 * @param {?Object} object 338 * @param {?Object} object
339 */ 339 */
340 function receivedPropertyNames(object) { 340 function receivedPropertyNames(object) {
341 executionContext.target().runtimeAgent().releaseObjectGroup('completion'); 341 executionContext.target().runtimeAgent().releaseObjectGroup('completion');
342 if (!object) { 342 if (!object) {
343 fulfill([]); 343 fulfill([]);
344 return; 344 return;
345 } 345 }
346 var propertyGroups = /** @type {!Array<!Components.JavaScriptAutocomplete.Co mpletionGroup>} */ (object); 346 var propertyGroups = /** @type {!Array<!ObjectUI.JavaScriptAutocomplete.Comp letionGroup>} */ (object);
347 var includeCommandLineAPI = (!dotNotation && !bracketNotation); 347 var includeCommandLineAPI = (!dotNotation && !bracketNotation);
348 if (includeCommandLineAPI) { 348 if (includeCommandLineAPI) {
349 const commandLineAPI = [ 349 const commandLineAPI = [
350 'dir', 350 'dir',
351 'dirxml', 351 'dirxml',
352 'keys', 352 'keys',
353 'values', 353 'values',
354 'profile', 354 'profile',
355 'profileEnd', 355 'profileEnd',
356 'monitorEvents', 356 'monitorEvents',
357 'unmonitorEvents', 357 'unmonitorEvents',
358 'inspect', 358 'inspect',
359 'copy', 359 'copy',
360 'clear', 360 'clear',
361 'getEventListeners', 361 'getEventListeners',
362 'debug', 362 'debug',
363 'undebug', 363 'undebug',
364 'monitor', 364 'monitor',
365 'unmonitor', 365 'unmonitor',
366 'table', 366 'table',
367 '$', 367 '$',
368 '$$', 368 '$$',
369 '$x' 369 '$x'
370 ]; 370 ];
371 propertyGroups.push({items: commandLineAPI}); 371 propertyGroups.push({items: commandLineAPI});
372 } 372 }
373 fulfill(Components.JavaScriptAutocomplete._completionsForQuery( 373 fulfill(ObjectUI.JavaScriptAutocomplete._completionsForQuery(
374 dotNotation, bracketNotation, expressionString, query, propertyGroups)); 374 dotNotation, bracketNotation, expressionString, query, propertyGroups));
375 } 375 }
376 }; 376 };
377 377
378 /** 378 /**
379 * @param {boolean} dotNotation 379 * @param {boolean} dotNotation
380 * @param {boolean} bracketNotation 380 * @param {boolean} bracketNotation
381 * @param {string} expressionString 381 * @param {string} expressionString
382 * @param {string} query 382 * @param {string} query
383 * @param {!Array<!Components.JavaScriptAutocomplete.CompletionGroup>} propert yGroups 383 * @param {!Array<!ObjectUI.JavaScriptAutocomplete.CompletionGroup>} propertyG roups
384 * @return {!UI.SuggestBox.Suggestions} 384 * @return {!UI.SuggestBox.Suggestions}
385 */ 385 */
386 Components.JavaScriptAutocomplete._completionsForQuery = function( 386 ObjectUI.JavaScriptAutocomplete._completionsForQuery = function(
387 dotNotation, bracketNotation, expressionString, query, propertyGroups) { 387 dotNotation, bracketNotation, expressionString, query, propertyGroups) {
388 if (bracketNotation) { 388 if (bracketNotation) {
389 if (query.length && query[0] === '\'') 389 if (query.length && query[0] === '\'')
390 var quoteUsed = '\''; 390 var quoteUsed = '\'';
391 else 391 else
392 var quoteUsed = '"'; 392 var quoteUsed = '"';
393 } 393 }
394 394
395 if (!expressionString) { 395 if (!expressionString) {
396 const keywords = [ 396 const keywords = [
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 function itemComparator(naturalOrder, a, b) { 460 function itemComparator(naturalOrder, a, b) {
461 var aStartsWithUnderscore = a.startsWith('_'); 461 var aStartsWithUnderscore = a.startsWith('_');
462 var bStartsWithUnderscore = b.startsWith('_'); 462 var bStartsWithUnderscore = b.startsWith('_');
463 if (aStartsWithUnderscore && !bStartsWithUnderscore) 463 if (aStartsWithUnderscore && !bStartsWithUnderscore)
464 return 1; 464 return 1;
465 if (bStartsWithUnderscore && !aStartsWithUnderscore) 465 if (bStartsWithUnderscore && !aStartsWithUnderscore)
466 return -1; 466 return -1;
467 return naturalOrder ? String.naturalOrderComparator(a, b) : a.localeCompare( b); 467 return naturalOrder ? String.naturalOrderComparator(a, b) : a.localeCompare( b);
468 } 468 }
469 }; 469 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698