mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 09:47:56 +08:00
DevTools: Give argument hints in the console prompt
https://i.imgur.com/Y3OlPM2.png Change-Id: Ic1d9ef1d47ff93ce77bfc3ae7173689bccf0cb2c Reviewed-on: https://chromium-review.googlesource.com/1031096 Reviewed-by: Andrey Lushnikov <lushnikov@chromium.org> Commit-Queue: Joel Einbinder <einbinder@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#557030} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 66bdf19b13c9a1dffbd47121101e0b8aedde3495
This commit is contained in:
committed by
Commit Bot
parent
4566e31350
commit
2fc0fb7ea3
@@ -32,6 +32,43 @@ ObjectUI.JavaScriptAutocomplete = class {
|
||||
return mapCompletions.concat(expressionCompletions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} fullText
|
||||
* @return {!Promise<?{args: !Array<string>, argumentIndex: number}>}
|
||||
*/
|
||||
async argumentsHint(fullText) {
|
||||
const functionCall = await Formatter.formatterWorkerPool().findLastFunctionCall(fullText);
|
||||
if (!functionCall)
|
||||
return null;
|
||||
const executionContext = UI.context.flavor(SDK.ExecutionContext);
|
||||
if (!executionContext)
|
||||
return null;
|
||||
const result = await executionContext.evaluate(
|
||||
{
|
||||
expression: functionCall.baseExpression,
|
||||
objectGroup: 'argumentsHint',
|
||||
includeCommandLineAPI: true,
|
||||
silent: true,
|
||||
returnByValue: false,
|
||||
generatePreview: false,
|
||||
throwOnSideEffect: functionCall.possibleSideEffects,
|
||||
timeout: functionCall.possibleSideEffects ? 500 : undefined
|
||||
},
|
||||
/* userGesture */ false, /* awaitPromise */ false);
|
||||
if (!result || result.exceptionDetails || !result.object || result.object.type !== 'function')
|
||||
return null;
|
||||
executionContext.runtimeModel.releaseObjectGroup('argumentsHint');
|
||||
|
||||
const description = result.object.description;
|
||||
if (description.endsWith('{ [native code] }'))
|
||||
return null; // TODO(einbinder) support native function argument hints
|
||||
const args = await Formatter.formatterWorkerPool().argumentsList(description);
|
||||
|
||||
if (!args.length)
|
||||
return null;
|
||||
return {args, argumentIndex: functionCall.argumentIndex};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {string} query
|
||||
|
||||
Reference in New Issue
Block a user