mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
Migrate object_ui/ to import cross-module
Bug: 1006759 Change-Id: Ic6a53e6183e3621771c019c4c9692c072f812736 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2019123 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
This commit is contained in:
committed by
Commit Bot
parent
2cfa33d87f
commit
64a94d8105
@@ -2,16 +2,22 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import * as Common from '../common/common.js';
|
||||
import * as Formatter from '../formatter/formatter.js';
|
||||
import * as SDK from '../sdk/sdk.js';
|
||||
import * as TextUtils from '../text_utils/text_utils.js';
|
||||
import * as UI from '../ui/ui.js';
|
||||
|
||||
export class JavaScriptAutocomplete {
|
||||
constructor() {
|
||||
/** @type {!Map<string, {date: number, value: !Promise<?Object>}>} */
|
||||
this._expressionCache = new Map();
|
||||
self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.CommandEvaluated, this._clearCache, this);
|
||||
UI.context.addFlavorChangeListener(SDK.ExecutionContext, this._clearCache, this);
|
||||
self.UI.context.addFlavorChangeListener(SDK.RuntimeModel.ExecutionContext, this._clearCache, this);
|
||||
self.SDK.targetManager.addModelListener(
|
||||
SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerResumed, this._clearCache, this);
|
||||
SDK.DebuggerModel.DebuggerModel, SDK.DebuggerModel.Events.DebuggerResumed, this._clearCache, this);
|
||||
self.SDK.targetManager.addModelListener(
|
||||
SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._clearCache, this);
|
||||
SDK.DebuggerModel.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._clearCache, this);
|
||||
}
|
||||
|
||||
_clearCache() {
|
||||
@@ -37,11 +43,11 @@ export class JavaScriptAutocomplete {
|
||||
* @return {!Promise<?{args: !Array<!Array<string>>, argumentIndex: number}|undefined>}
|
||||
*/
|
||||
async argumentsHint(fullText) {
|
||||
const functionCall = await Formatter.formatterWorkerPool().findLastFunctionCall(fullText);
|
||||
const functionCall = await Formatter.FormatterWorkerPool.formatterWorkerPool().findLastFunctionCall(fullText);
|
||||
if (!functionCall) {
|
||||
return null;
|
||||
}
|
||||
const executionContext = UI.context.flavor(SDK.ExecutionContext);
|
||||
const executionContext = self.UI.context.flavor(SDK.RuntimeModel.ExecutionContext);
|
||||
if (!executionContext) {
|
||||
return null;
|
||||
}
|
||||
@@ -85,15 +91,15 @@ export class JavaScriptAutocomplete {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!SDK.RemoteObject} functionObject
|
||||
* @param {function():!Promise<?SDK.RemoteObject>} receiverObjGetter
|
||||
* @param {!SDK.RemoteObject.RemoteObject} functionObject
|
||||
* @param {function():!Promise<?SDK.RemoteObject.RemoteObject>} receiverObjGetter
|
||||
* @param {string=} parsedFunctionName
|
||||
* @return {!Promise<!Array<!Array<string>>>}
|
||||
*/
|
||||
async _argumentsForFunction(functionObject, receiverObjGetter, parsedFunctionName) {
|
||||
const description = functionObject.description;
|
||||
if (!description.endsWith('{ [native code] }')) {
|
||||
return [await Formatter.formatterWorkerPool().argumentsList(description)];
|
||||
return [await Formatter.FormatterWorkerPool.formatterWorkerPool().argumentsList(description)];
|
||||
}
|
||||
|
||||
// Check if this is a bound function.
|
||||
@@ -106,7 +112,7 @@ export class JavaScriptAutocomplete {
|
||||
if (thisProperty && targetProperty && argsProperty) {
|
||||
const originalSignatures =
|
||||
await this._argumentsForFunction(targetProperty.value, () => Promise.resolve(thisProperty.value));
|
||||
const boundArgsLength = SDK.RemoteObject.arrayLength(argsProperty.value);
|
||||
const boundArgsLength = SDK.RemoteObject.RemoteObject.arrayLength(argsProperty.value);
|
||||
const clippedArgs = [];
|
||||
for (const signature of originalSignatures) {
|
||||
const restIndex = signature.slice(0, boundArgsLength).findIndex(arg => arg.startsWith('...'));
|
||||
@@ -119,7 +125,7 @@ export class JavaScriptAutocomplete {
|
||||
return clippedArgs;
|
||||
}
|
||||
}
|
||||
const javaScriptMetadata = await self.runtime.extension(Common.JavaScriptMetadata).instance();
|
||||
const javaScriptMetadata = await self.runtime.extension(Common.JavaScriptMetaData.JavaScriptMetaData).instance();
|
||||
|
||||
const name = /^function ([^(]*)\(/.exec(description)[1] || parsedFunctionName;
|
||||
if (!name) {
|
||||
@@ -190,12 +196,13 @@ export class JavaScriptAutocomplete {
|
||||
*/
|
||||
async _mapCompletions(text, query) {
|
||||
const mapMatch = text.match(/\.\s*(get|set|delete)\s*\(\s*$/);
|
||||
const executionContext = UI.context.flavor(SDK.ExecutionContext);
|
||||
const executionContext = self.UI.context.flavor(SDK.RuntimeModel.ExecutionContext);
|
||||
if (!executionContext || !mapMatch) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const expression = await Formatter.formatterWorkerPool().findLastExpression(text.substring(0, mapMatch.index));
|
||||
const expression =
|
||||
await Formatter.FormatterWorkerPool.formatterWorkerPool().findLastExpression(text.substring(0, mapMatch.index));
|
||||
if (!expression) {
|
||||
return [];
|
||||
}
|
||||
@@ -285,7 +292,7 @@ export class JavaScriptAutocomplete {
|
||||
const suggestions =
|
||||
caseSensitivePrefix.concat(caseInsensitivePrefix, caseSensitiveAnywhere, caseInsensitiveAnywhere);
|
||||
if (suggestions.length) {
|
||||
suggestions[0].subtitle = Common.UIString('Keys');
|
||||
suggestions[0].subtitle = Common.UIString.UIString('Keys');
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
@@ -298,13 +305,14 @@ export class JavaScriptAutocomplete {
|
||||
* @return {!Promise<!UI.SuggestBox.Suggestions>}
|
||||
*/
|
||||
async _completionsForExpression(fullText, query, force) {
|
||||
const executionContext = UI.context.flavor(SDK.ExecutionContext);
|
||||
const executionContext = self.UI.context.flavor(SDK.RuntimeModel.ExecutionContext);
|
||||
if (!executionContext) {
|
||||
return [];
|
||||
}
|
||||
let expression;
|
||||
if (fullText.endsWith('.') || fullText.endsWith('[')) {
|
||||
expression = await Formatter.formatterWorkerPool().findLastExpression(fullText.substring(0, fullText.length - 1));
|
||||
expression = await Formatter.FormatterWorkerPool.formatterWorkerPool().findLastExpression(
|
||||
fullText.substring(0, fullText.length - 1));
|
||||
}
|
||||
if (!expression) {
|
||||
if (fullText.endsWith('.')) {
|
||||
@@ -380,8 +388,9 @@ export class JavaScriptAutocomplete {
|
||||
}
|
||||
let completions = [];
|
||||
if (object.type === 'object' || object.type === 'function') {
|
||||
completions =
|
||||
await object.callFunctionJSON(getCompletions, [SDK.RemoteObject.toCallArgument(object.subtype)]) || [];
|
||||
completions = await object.callFunctionJSON(
|
||||
getCompletions, [SDK.RemoteObject.RemoteObject.toCallArgument(object.subtype)]) ||
|
||||
[];
|
||||
} else if (
|
||||
object.type === 'string' || object.type === 'number' || object.type === 'boolean' ||
|
||||
object.type === 'bigint') {
|
||||
@@ -408,7 +417,7 @@ export class JavaScriptAutocomplete {
|
||||
if (completions.length) {
|
||||
completions[0].items = completions[0].items.concat(globalNames);
|
||||
} else {
|
||||
completions.push({items: globalNames.sort(), title: Common.UIString('Lexical scope variables')});
|
||||
completions.push({items: globalNames.sort(), title: Common.UIString.UIString('Lexical scope variables')});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,7 +666,7 @@ export class JavaScriptAutocomplete {
|
||||
* @return {!Promise<boolean>}
|
||||
*/
|
||||
static async isExpressionComplete(expression) {
|
||||
const currentExecutionContext = UI.context.flavor(SDK.ExecutionContext);
|
||||
const currentExecutionContext = self.UI.context.flavor(SDK.RuntimeModel.ExecutionContext);
|
||||
if (!currentExecutionContext) {
|
||||
return true;
|
||||
}
|
||||
@@ -674,15 +683,15 @@ export class JavaScriptAutocomplete {
|
||||
|
||||
export class JavaScriptAutocompleteConfig {
|
||||
/**
|
||||
* @param {!UI.TextEditor} editor
|
||||
* @param {!UI.TextEditor.TextEditor} editor
|
||||
*/
|
||||
constructor(editor) {
|
||||
this._editor = editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!UI.TextEditor} editor
|
||||
* @return {!UI.AutocompleteConfig}
|
||||
* @param {!UI.TextEditor.TextEditor} editor
|
||||
* @return {!UI.SuggestBox.AutocompleteConfig}
|
||||
*/
|
||||
static createConfigForEditor(editor) {
|
||||
const autocomplete = new JavaScriptAutocompleteConfig(editor);
|
||||
@@ -696,12 +705,12 @@ export class JavaScriptAutocompleteConfig {
|
||||
/**
|
||||
* @param {number} lineNumber
|
||||
* @param {number} columnNumber
|
||||
* @return {?TextUtils.TextRange}
|
||||
* @return {?TextUtils.TextRange.TextRange}
|
||||
*/
|
||||
_substituteRange(lineNumber, columnNumber) {
|
||||
const token = this._editor.tokenAtTextPosition(lineNumber, columnNumber);
|
||||
if (token && token.type === 'js-string') {
|
||||
return new TextUtils.TextRange(lineNumber, token.startColumn, lineNumber, columnNumber);
|
||||
return new TextUtils.TextRange.TextRange(lineNumber, token.startColumn, lineNumber, columnNumber);
|
||||
}
|
||||
|
||||
const lineText = this._editor.line(lineNumber);
|
||||
@@ -711,18 +720,19 @@ export class JavaScriptAutocompleteConfig {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new TextUtils.TextRange(lineNumber, index + 1, lineNumber, columnNumber);
|
||||
return new TextUtils.TextRange.TextRange(lineNumber, index + 1, lineNumber, columnNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!TextUtils.TextRange} queryRange
|
||||
* @param {!TextUtils.TextRange} substituteRange
|
||||
* @param {!TextUtils.TextRange.TextRange} queryRange
|
||||
* @param {!TextUtils.TextRange.TextRange} substituteRange
|
||||
* @param {boolean=} force
|
||||
* @return {!Promise<!UI.SuggestBox.Suggestions>}
|
||||
*/
|
||||
async _suggestionsCallback(queryRange, substituteRange, force) {
|
||||
const query = this._editor.text(queryRange);
|
||||
const before = this._editor.text(new TextUtils.TextRange(0, 0, queryRange.startLine, queryRange.startColumn));
|
||||
const before =
|
||||
this._editor.text(new TextUtils.TextRange.TextRange(0, 0, queryRange.startLine, queryRange.startColumn));
|
||||
const token = this._editor.tokenAtTextPosition(substituteRange.startLine, substituteRange.startColumn);
|
||||
if (token) {
|
||||
const excludedTokens = new Set(['js-comment', 'js-string-2', 'js-def']);
|
||||
@@ -753,7 +763,7 @@ export class JavaScriptAutocompleteConfig {
|
||||
* @return {!Promise<?Element>}
|
||||
*/
|
||||
async _tooltipCallback(lineNumber, columnNumber) {
|
||||
const before = this._editor.text(new TextUtils.TextRange(0, 0, lineNumber, columnNumber));
|
||||
const before = this._editor.text(new TextUtils.TextRange.TextRange(0, 0, lineNumber, columnNumber));
|
||||
const result = await ObjectUI.javaScriptAutocomplete.argumentsHint(before);
|
||||
if (!result) {
|
||||
return null;
|
||||
@@ -764,7 +774,7 @@ export class JavaScriptAutocompleteConfig {
|
||||
const argumentsElement = createElement('span');
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (i === argumentIndex || (i < argumentIndex && args[i].startsWith('...'))) {
|
||||
argumentsElement.appendChild(UI.html`<b>${args[i]}</b>`);
|
||||
argumentsElement.appendChild(UI.Fragment.html`<b>${args[i]}</b>`);
|
||||
} else {
|
||||
argumentsElement.createTextChild(args[i]);
|
||||
}
|
||||
@@ -772,7 +782,7 @@ export class JavaScriptAutocompleteConfig {
|
||||
argumentsElement.createTextChild(', ');
|
||||
}
|
||||
}
|
||||
tooltip.appendChild(UI.html`<div class='source-code'>\u0192(${argumentsElement})</div>`);
|
||||
tooltip.appendChild(UI.Fragment.html`<div class='source-code'>\u0192(${argumentsElement})</div>`);
|
||||
}
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user