Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft code for responding to DTD navigate to code request #7677

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion flutter-idea/src/io/flutter/inspector/InspectorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package io.flutter.inspector;

import com.google.api.client.json.Json;
import com.google.common.base.Joiner;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand All @@ -29,14 +30,17 @@
import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
import com.intellij.xdebugger.impl.XSourcePositionImpl;
import com.jetbrains.lang.dart.ide.toolingDaemon.DartToolingDaemonService;
import com.jetbrains.lang.dart.psi.DartCallExpression;
import com.jetbrains.lang.dart.psi.DartExpression;
import com.jetbrains.lang.dart.psi.DartReferenceExpression;
import io.flutter.bazel.Workspace;
import io.flutter.bazel.WorkspaceCache;
import io.flutter.dart.DtdUtils;
import io.flutter.pub.PubRoot;
import io.flutter.run.FlutterDebugProcess;
import io.flutter.run.daemon.FlutterApp;
import io.flutter.sdk.FlutterSdk;
import io.flutter.utils.JsonUtils;
import io.flutter.utils.StreamSubscription;
import io.flutter.utils.VmServiceListenerAdapter;
Expand All @@ -61,6 +65,7 @@
import java.util.List;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -251,7 +256,41 @@ private InspectorService(@NotNull FlutterApp app,

clients = new HashSet<>();

vmService.addVmServiceListener(new VmServiceListenerAdapter() {
// This code hasn't been tested yet, as it requires the Dart plugin to be updated to this PR: https://github.com/JetBrains/intellij-plugins/pull/920.
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(app.getProject());
if (sdk != null && sdk.getVersion().canUseDtd()) {
Thread t1 = new Thread(() -> {
CompletableFuture<DartToolingDaemonService> future = new DtdUtils().readyDtdService(app.getProject());
future.thenApply((dtdService) -> {
JsonObject capabilities = new JsonObject();
JsonArray capabilitiesList = new JsonArray();
capabilitiesList.add("file");
capabilities.add("supportedSchemes", capabilitiesList);

dtdService.registerServiceMethod("Editor", "navigateToCode", capabilities, new DartToolingDaemonRequestHandler() {
public DartToolingDaemonResponse handleRequest(JsonObject request) {
// Extract request params
// Then replicate ToolEvent actions below

// This is a code pointer for where DevTools is currently using `ToolEvent` for the performance panel's rebuild stats:
// https://github.com/flutter/devtools/blob/master/packages/devtools_app/lib/src/screens/performance/panes/rebuild_stats/rebuild_stats.dart#L215
// It would make sense to send a DTD `Editor.navigateToCode` request here (once this IJ change has landed).

// DevTools also sends a `ToolEvent` when a location is clicked in the inspector panel, but this is through flutter/flutter:
// https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/widget_inspector.dart#L1607
// It would also make sense to make a DTD `Editor.navigateToCode` where this is used (I am not sure where DevTools invokes
// this code).

// I'm not sure if we should remove `ToolEvent` entirely. We should probably keep while there are cases when DTD isn't
// started: internal users, is DTD is started all the time in Dart?
}
});
});
});
t1.start();
}

vmService.addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void received(String streamId, Event event) {
onVmServiceReceived(streamId, event);
Expand Down
Loading