Created openInIDE API inside Layout Plugin
Summary: Created a communication between Layout Plugin and Flipper Desktop. The API allows users to open given file in a selected IDE. The openInIDE function returns true if the connection with Flipper is established, otherwise returns false. Reviewed By: adityasharat Differential Revision: D22625829 fbshipit-source-id: feaf186c107d62b1a75dfc6bbe2c1d66ffd7fd78
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3e4d92aad0
commit
cf6df492ee
@@ -37,6 +37,12 @@ public class InspectorFlipperPlugin implements FlipperPlugin {
|
||||
private @Nullable List<ExtensionCommand> mExtensionCommands;
|
||||
private boolean mShowLithoAccessibilitySettings;
|
||||
|
||||
public enum IDE {
|
||||
diffusion,
|
||||
AS,
|
||||
VSCode
|
||||
}
|
||||
|
||||
/** An interface for extensions to the Inspector Flipper plugin */
|
||||
public interface ExtensionCommand {
|
||||
/** The command to respond to */
|
||||
@@ -419,6 +425,23 @@ public class InspectorFlipperPlugin implements FlipperPlugin {
|
||||
}
|
||||
};
|
||||
|
||||
public boolean openInIDE(
|
||||
String fileName, String className, String dirRoot, String repo, int lineNumber, IDE ide) {
|
||||
if (mConnection == null) return false;
|
||||
|
||||
mConnection.send(
|
||||
"openInIDE",
|
||||
new FlipperObject.Builder()
|
||||
.put("fileName", fileName)
|
||||
.put("className", className)
|
||||
.put("dirRoot", dirRoot)
|
||||
.put("repo", repo)
|
||||
.put("lineNumber", lineNumber)
|
||||
.put("ide", ide)
|
||||
.build());
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setHighlighted(
|
||||
final String id, final boolean highlighted, final boolean isAlignmentMode) throws Exception {
|
||||
final Object obj = mObjectTracker.get(id);
|
||||
|
||||
@@ -31,6 +31,12 @@ import ProxyArchiveClient from './ProxyArchiveClient';
|
||||
import React from 'react';
|
||||
import {VisualizerPortal} from 'flipper';
|
||||
import {getFlipperMediaCDN} from 'flipper';
|
||||
import {
|
||||
resolveFullPathsFromMyles,
|
||||
getBestPath,
|
||||
IDE,
|
||||
openInIDE,
|
||||
} from '../../app/src/fb-stubs/FileResolver';
|
||||
|
||||
type State = {
|
||||
init: boolean;
|
||||
@@ -57,6 +63,15 @@ export type PersistedState = {
|
||||
type ClientGetNodesCalls = 'getNodes' | 'getAXNodes';
|
||||
type ClientMethodCalls = 'getRoot' | 'getAXRoot' | ClientGetNodesCalls;
|
||||
|
||||
type ClassFileParams = {
|
||||
fileName: string;
|
||||
className: string;
|
||||
dirRoot: string;
|
||||
repo: string;
|
||||
lineNumber: number;
|
||||
ide: IDE;
|
||||
};
|
||||
|
||||
export default class LayoutPlugin extends FlipperPlugin<
|
||||
State,
|
||||
any,
|
||||
@@ -205,6 +220,10 @@ export default class LayoutPlugin extends FlipperPlugin<
|
||||
}
|
||||
});
|
||||
|
||||
this.client.subscribe('openInIDE', (params: ClassFileParams) => {
|
||||
this.openInIDE(params);
|
||||
});
|
||||
|
||||
if (this.props.isArchivedDevice) {
|
||||
this.getDevice()
|
||||
.then((d) => {
|
||||
@@ -229,6 +248,19 @@ export default class LayoutPlugin extends FlipperPlugin<
|
||||
});
|
||||
}
|
||||
|
||||
openInIDE = async (params: ClassFileParams) => {
|
||||
const paths = await resolveFullPathsFromMyles(
|
||||
params.fileName,
|
||||
params.dirRoot,
|
||||
);
|
||||
const selectedPath = getBestPath(paths, params.className);
|
||||
let ide: IDE = Number(IDE[params.ide]);
|
||||
if (Number.isNaN(ide)) {
|
||||
ide = IDE.AS; // default value
|
||||
}
|
||||
openInIDE(selectedPath, ide, params.repo, params.lineNumber);
|
||||
};
|
||||
|
||||
onToggleTargetMode = () => {
|
||||
const inTargetMode = !this.state.inTargetMode;
|
||||
this.setState({inTargetMode});
|
||||
|
||||
Reference in New Issue
Block a user