diff --git a/flutter-idea/src/io/flutter/inspector/InspectorService.java b/flutter-idea/src/io/flutter/inspector/InspectorService.java index 7020360bac..cb83e47485 100644 --- a/flutter-idea/src/io/flutter/inspector/InspectorService.java +++ b/flutter-idea/src/io/flutter/inspector/InspectorService.java @@ -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; @@ -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; @@ -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; @@ -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 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);