Splitting the 'OpenInIDE' API to 'resolvePath' and 'open' APIs

Summary: Detect if resolved path is properly computed and accordingly display a success or error notification within InAppErrorReporter.

Reviewed By: arpitratan

Differential Revision: D23425001

fbshipit-source-id: 4ca903a8b9e83dc0e11bb823537f56678dd85b76
This commit is contained in:
Dominik Wielgórski
2020-09-04 08:32:11 -07:00
committed by Facebook GitHub Bot
parent 374648975c
commit 5b4403b400
2 changed files with 53 additions and 10 deletions

View File

@@ -23,7 +23,9 @@ import com.facebook.flipper.core.FlipperResponder;
import com.facebook.flipper.plugins.common.MainThreadFlipperReceiver;
import com.facebook.flipper.plugins.inspector.descriptors.ApplicationDescriptor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
public class InspectorFlipperPlugin implements FlipperPlugin {
@@ -36,6 +38,7 @@ public class InspectorFlipperPlugin implements FlipperPlugin {
private FlipperConnection mConnection;
private @Nullable List<ExtensionCommand> mExtensionCommands;
private boolean mShowLithoAccessibilitySettings;
private Map<String, String> resolvedPaths = new HashMap<>();
public enum IDE {
DIFFUSION("Diffusion"),
@@ -123,6 +126,7 @@ public class InspectorFlipperPlugin implements FlipperPlugin {
connection.receive("onRequestAXFocus", mOnRequestAXFocus);
connection.receive(
"shouldShowLithoAccessibilitySettings", mShouldShowLithoAccessibilitySettings);
connection.receive("setResolvedPath", mSetResolvedPath);
if (mExtensionCommands != null) {
for (ExtensionCommand extensionCommand : mExtensionCommands) {
@@ -463,16 +467,40 @@ public class InspectorFlipperPlugin implements FlipperPlugin {
return mConnection != null;
}
public void openInIDE(
String fileName, String className, String dirRoot, String repo, int lineNumber, IDE ide) {
final FlipperReceiver mSetResolvedPath =
new MainThreadFlipperReceiver() {
@Override
public void onReceiveOnMainThread(
final FlipperObject params, final FlipperResponder responder) throws Exception {
resolvedPaths.put(params.getString("className"), params.getString("resolvedPath"));
}
};
public String getResolvedPath(String className) {
return resolvedPaths.get(className);
}
public void resolvePath(String fileName, String className, String dirRoot) {
if (mConnection == null || resolvedPaths.get(className) != null) {
return;
}
mConnection.send(
"resolvePath",
new FlipperObject.Builder()
.put("fileName", fileName)
.put("className", className)
.put("dirRoot", dirRoot)
.build());
}
public void openInIDE(String resolvedPath, String repo, int lineNumber, IDE ide) {
if (mConnection == null) return;
mConnection.send(
"openInIDE",
new FlipperObject.Builder()
.put("fileName", fileName)
.put("className", className)
.put("dirRoot", dirRoot)
.put("resolvedPath", resolvedPath)
.put("repo", repo)
.put("lineNumber", lineNumber)
.put("ide", ide)

View File

@@ -65,9 +65,13 @@ type ClassFileParams = {
fileName: string;
className: string;
dirRoot: string;
};
type OpenFileParams = {
resolvedPath: string;
ide: IDEType;
repo: string;
lineNumber: number;
ide: IDEType;
};
export default class LayoutPlugin extends FlipperPlugin<
@@ -220,7 +224,11 @@ export default class LayoutPlugin extends FlipperPlugin<
}
});
this.client.subscribe('openInIDE', (params: ClassFileParams) => {
this.client.subscribe('resolvePath', (params: ClassFileParams) => {
this.resolvePath(params);
});
this.client.subscribe('openInIDE', (params: OpenFileParams) => {
this.openInIDE(params);
});
@@ -256,18 +264,25 @@ export default class LayoutPlugin extends FlipperPlugin<
});
}
openInIDE = async (params: ClassFileParams) => {
resolvePath = async (params: ClassFileParams) => {
const paths = await IDEFileResolver.resolveFullPathsFromMyles(
params.fileName,
params.dirRoot,
);
const selectedPath = IDEFileResolver.getBestPath(paths, params.className);
const resolvedPath = IDEFileResolver.getBestPath(paths, params.className);
this.client.send('setResolvedPath', {
className: params.className,
resolvedPath: resolvedPath,
});
};
openInIDE = async (params: OpenFileParams) => {
let ide: IDEType = Number(IDEType[params.ide]);
if (Number.isNaN(ide)) {
ide = IDEType.AS; // default value
}
IDEFileResolver.openInIDE(
selectedPath,
params.resolvedPath,
ide,
params.repo,
params.lineNumber,