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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/ExecutionContextSelector.js

Issue 2471243002: DevTools: Consolidate completion code into JavaScriptAutocomplete.js (Closed)
Patch Set: merge Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 * @implements {WebInspector.TargetManager.Observer} 5 * @implements {WebInspector.TargetManager.Observer}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 WebInspector.ExecutionContextSelector = class { 8 WebInspector.ExecutionContextSelector = class {
9 /** 9 /**
10 * @param {!WebInspector.TargetManager} targetManager 10 * @param {!WebInspector.TargetManager} targetManager
(...skipping 11 matching lines...) Expand all
22 WebInspector.RuntimeModel, WebInspector.RuntimeModel.Events.ExecutionCon textDestroyed, 22 WebInspector.RuntimeModel, WebInspector.RuntimeModel.Events.ExecutionCon textDestroyed,
23 this._onExecutionContextDestroyed, this); 23 this._onExecutionContextDestroyed, this);
24 targetManager.addModelListener( 24 targetManager.addModelListener(
25 WebInspector.RuntimeModel, WebInspector.RuntimeModel.Events.ExecutionCon textOrderChanged, 25 WebInspector.RuntimeModel, WebInspector.RuntimeModel.Events.ExecutionCon textOrderChanged,
26 this._onExecutionContextOrderChanged, this); 26 this._onExecutionContextOrderChanged, this);
27 this._targetManager = targetManager; 27 this._targetManager = targetManager;
28 this._context = context; 28 this._context = context;
29 } 29 }
30 30
31 /** 31 /**
32 * @param {!Element} proxyElement
33 * @param {!Range} wordRange
34 * @param {boolean} force
35 * @param {function(!Array.<string>, number=)} completionsReadyCallback
36 */
37 static completionsForTextPromptInCurrentContext(proxyElement, wordRange, force , completionsReadyCallback) {
38 var expressionRange = wordRange.cloneRange();
39 expressionRange.collapse(true);
40 expressionRange.setStartBefore(proxyElement);
41 WebInspector.ExecutionContextSelector
42 .completionsForTextInCurrentContext(expressionRange.toString(), wordRang e.toString(), force)
43 .then(completionsReadyCallback);
44 }
45
46 /**
47 * @param {string} text
48 * @param {string} completionsPrefix
49 * @param {boolean=} force
50 * @return {!Promise<!Array<string>>}
51 */
52 static completionsForTextInCurrentContext(text, completionsPrefix, force) {
53 var executionContext = WebInspector.context.flavor(WebInspector.ExecutionCon text);
54 if (!executionContext)
55 return Promise.resolve([]);
56 var index;
57 var stopChars = new Set(' =:({;,!+-*/&|^<>`'.split(''));
58 for (index = text.length - 1; index >= 0; index--) {
59 // Pass less stop characters to rangeOfWord so the range will be a more co mplete expression.
60 if (stopChars.has(text.charAt(index)))
61 break;
62 }
63 var clippedExpression = text.substring(index + 1);
64 var bracketCount = 0;
65
66 index = clippedExpression.length - 1;
67 while (index >= 0) {
68 var character = clippedExpression.charAt(index);
69 if (character === ']')
70 bracketCount++;
71 // Allow an open bracket at the end for property completion.
72 if (character === '[' && index < clippedExpression.length - 1) {
73 bracketCount--;
74 if (bracketCount < 0)
75 break;
76 }
77 index--;
78 }
79 clippedExpression = clippedExpression.substring(index + 1);
80
81 return executionContext.completionsForExpression(clippedExpression, completi onsPrefix, force);
82 }
83
84 /**
85 * @override 32 * @override
86 * @param {!WebInspector.Target} target 33 * @param {!WebInspector.Target} target
87 */ 34 */
88 targetAdded(target) { 35 targetAdded(target) {
89 // Defer selecting default target since we need all clients to get their 36 // Defer selecting default target since we need all clients to get their
90 // targetAdded notifications first. 37 // targetAdded notifications first.
91 setImmediate(deferred.bind(this)); 38 setImmediate(deferred.bind(this));
92 39
93 /** 40 /**
94 * @this {WebInspector.ExecutionContextSelector} 41 * @this {WebInspector.ExecutionContextSelector}
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 newContext = executionContexts[0]; 198 newContext = executionContexts[0];
252 break; 199 break;
253 } 200 }
254 } 201 }
255 } 202 }
256 this._ignoreContextChanged = true; 203 this._ignoreContextChanged = true;
257 this._context.setFlavor(WebInspector.ExecutionContext, newContext); 204 this._context.setFlavor(WebInspector.ExecutionContext, newContext);
258 this._ignoreContextChanged = false; 205 this._ignoreContextChanged = false;
259 } 206 }
260 }; 207 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698