-
Notifications
You must be signed in to change notification settings - Fork 330
Register VM service with DTD #8436
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import com.google.common.base.Stopwatch; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import com.intellij.execution.ExecutionException; | ||
import com.intellij.execution.configurations.GeneralCommandLine; | ||
import com.intellij.execution.process.ProcessAdapter; | ||
|
@@ -27,13 +28,17 @@ | |
import com.intellij.openapi.util.text.StringUtil; | ||
import com.intellij.util.EventDispatcher; | ||
import com.intellij.util.concurrency.AppExecutorUtil; | ||
import com.jetbrains.lang.dart.ide.toolingDaemon.DartToolingDaemonService; | ||
import de.roderick.weberknecht.WebSocketException; | ||
import io.flutter.FlutterMessages; | ||
import io.flutter.FlutterUtils; | ||
import io.flutter.ObservatoryConnector; | ||
import io.flutter.bazel.Workspace; | ||
import io.flutter.bazel.WorkspaceCache; | ||
import io.flutter.dart.DtdUtils; | ||
import io.flutter.dart.FlutterDartAnalysisServer; | ||
import io.flutter.logging.FlutterConsoleLogManager; | ||
import io.flutter.logging.PluginLogger; | ||
import io.flutter.run.FlutterDebugProcess; | ||
import io.flutter.run.FlutterDevice; | ||
import io.flutter.run.FlutterLaunchMode; | ||
|
@@ -677,10 +682,13 @@ public void dispose() { | |
* Listens for events while running or debugging an app. | ||
*/ | ||
class FlutterAppDaemonEventListener implements DaemonEvent.Listener { | ||
private static final @NotNull Logger LOG = Logger.getInstance(FlutterAppDaemonEventListener.class); | ||
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterAppDaemonEventListener.class); | ||
|
||
private final @NotNull FlutterApp app; | ||
private final @NotNull ProgressHelper progress; | ||
private String appVmServiceUri; | ||
private final DtdUtils dtdUtils = new DtdUtils(); | ||
helin24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
FlutterAppDaemonEventListener(@NotNull FlutterApp app, @NotNull Project project) { | ||
this.app = app; | ||
|
@@ -738,6 +746,12 @@ public void onAppStarting(DaemonEvent.AppStarting event) { | |
@Override | ||
public void onAppDebugPort(@NotNull DaemonEvent.AppDebugPort debugInfo) { | ||
app.setWsUrl(debugInfo.wsUri); | ||
this.appVmServiceUri = debugInfo.wsUri; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we get any sort of identifier that we can use as a map key that we can look up when we get the app stopped event for this particular app? While the MCP server today only supports one connected app, we do want to have it support multiple in the future, so ideally the IDE plugins wouldn't be assuming just one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IJ can register multiple apps to DTD. There's an app name that's a unique identifier, or the VM service URI is unique too. This is an example of the params we send with two apps running at the same time:
The |
||
|
||
final JsonObject params = new JsonObject(); | ||
params.addProperty("uri", debugInfo.wsUri); | ||
params.addProperty("name", debugInfo.appId); | ||
sendDtdRequest("ConnectedApp.registerVmService", params); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how we want to test this (And I'd love to get your thoughts), but in anticipation, maybe we should introduce some constants somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for now I can add these methods as constants. Maybe a separate file that links to DTD documentation would be helpful. I haven't thought much about testing; I suppose one part would be testing |
||
|
||
// Print the conneciton info to the console. | ||
final ConsoleView console = app.getConsole(); | ||
|
@@ -804,7 +818,36 @@ public void onAppStopped(@NotNull DaemonEvent.AppStopped stopped) { | |
if (stopped.error != null && app.getConsole() != null) { | ||
app.getConsole().print("Finished with error: " + stopped.error + "\n", ConsoleViewContentType.ERROR_OUTPUT); | ||
} | ||
|
||
final JsonObject params = new JsonObject(); | ||
params.addProperty("uri", appVmServiceUri); | ||
sendDtdRequest("ConnectedApp.unregisterVmService", params); | ||
|
||
progress.cancel(); | ||
app.getProcessHandler().destroyProcess(); | ||
} | ||
|
||
private void sendDtdRequest(@NotNull String requestName, @NotNull JsonObject params) { | ||
try { | ||
final DartToolingDaemonService dtdService = dtdUtils.readyDtdService(app.getProject()).get(); | ||
if (dtdService == null) { | ||
return; | ||
} | ||
// This removes secret from params when we print out after receiving response. | ||
helin24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
JsonObject initialParams = params.deepCopy(); | ||
dtdService.sendRequest(requestName, params, true, object -> { | ||
final JsonObject result = object.getAsJsonObject("result"); | ||
final JsonPrimitive type = result != null ? result.getAsJsonPrimitive("type") : null; | ||
if (type != null && "Success".equals(type.getAsString())) { | ||
LOG.info("Successful request " + requestName + " to DTD with params: " + initialParams); | ||
} else { | ||
LOG.warn("Failed request " + requestName + "to DTD with params: " + initialParams); | ||
LOG.warn("Result: " + result); | ||
} | ||
}); | ||
} | ||
catch (InterruptedException | java.util.concurrent.ExecutionException | WebSocketException e) { | ||
LOG.error("Exception while sending DTD request", e); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.