use of org.dartlang.vm.service.VmService in project flutter-intellij by flutter.
the class FlutterConsoleLogManager method processLoggingEvent.
@VisibleForTesting
public void processLoggingEvent(@NotNull Event event) {
final LogRecord logRecord = event.getLogRecord();
if (logRecord == null)
return;
final VmService service = app.getVmService();
if (service == null) {
return;
}
final IsolateRef isolateRef = event.getIsolate();
final InstanceRef message = logRecord.getMessage();
@NotNull final InstanceRef loggerName = logRecord.getLoggerName();
final String name = loggerName.getValueAsString().isEmpty() ? "log" : loggerName.getValueAsString();
final String prefix = "[" + name + "] ";
final String messageStr = getFullStringValue(service, isolateRef.getId(), message);
console.print(prefix, SUBTLE_CONTENT_TYPE);
console.print(messageStr + "\n", NORMAL_CONTENT_TYPE);
@NotNull final InstanceRef error = logRecord.getError();
@NotNull final InstanceRef stackTrace = logRecord.getStackTrace();
if (!error.isNull()) {
final String padding = StringUtil.repeat(" ", prefix.length());
if (error.getKind() == InstanceKind.String) {
String string = getFullStringValue(service, isolateRef.getId(), error);
// Handle json in the error payload.
boolean isJson = false;
try {
final JsonElement json = JsonUtils.parseString(string);
isJson = true;
string = new GsonBuilder().setPrettyPrinting().create().toJson(json);
string = string.replaceAll("\n", "\n" + padding);
} catch (JsonSyntaxException ignored) {
}
console.print(padding + string + "\n", isJson ? ConsoleViewContentType.NORMAL_OUTPUT : ERROR_CONTENT_TYPE);
} else {
final CountDownLatch latch = new CountDownLatch(1);
service.invoke(isolateRef.getId(), error.getId(), "toString", Collections.emptyList(), true, new VmServiceConsumers.InvokeConsumerWrapper() {
@Override
public void received(InstanceRef response) {
console.print(padding + stringValueFromStringRef(response) + "\n", ERROR_CONTENT_TYPE);
latch.countDown();
}
@Override
public void noGoodResult() {
console.print(padding + error.getClassRef().getName() + " " + error.getId() + "\n", ERROR_CONTENT_TYPE);
latch.countDown();
}
});
try {
latch.await();
} catch (InterruptedException ignored) {
}
}
}
if (!stackTrace.isNull()) {
final String padding = StringUtil.repeat(" ", prefix.length());
final String out = stackTrace.getValueAsString() == null ? "" : stackTrace.getValueAsString().trim();
console.print(padding + out.replaceAll("\n", "\n" + padding) + "\n", ERROR_CONTENT_TYPE);
}
}
use of org.dartlang.vm.service.VmService in project flutter-intellij by flutter.
the class FlutterTestRunner method run.
protected RunContentDescriptor run(@NotNull TestLaunchState launcher, @NotNull ExecutionEnvironment env) throws ExecutionException {
final ExecutionResult executionResult = launcher.execute(env.getExecutor(), this);
final ObservatoryConnector connector = new Connector(executionResult.getProcessHandler());
ApplicationManager.getApplication().executeOnPooledThread(() -> {
// Poll, waiting for "flutter run" to give us a websocket.
// This is adapted from DartVmServiceDebugProcess::scheduleConnect.
String url = connector.getWebSocketUrl();
while (url == null) {
if (launcher.isTerminated()) {
return;
}
TimeoutUtil.sleep(100);
url = connector.getWebSocketUrl();
}
if (launcher.isTerminated()) {
return;
}
final VmService vmService;
try {
vmService = VmService.connect(url);
} catch (IOException | RuntimeException e) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Failed to connect to the VM service at: " + url + "\n" + e.toString() + "\n", ProcessOutputTypes.STDERR);
}
return;
}
// Listen for debug 'PauseStart' events for isolates after the initial connect and resume those isolates.
vmService.streamListen(VmService.DEBUG_STREAM_ID, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
vmService.addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void received(String streamId, Event event) {
if (EventKind.PauseStart.equals(event.getKind())) {
resumePausedAtStartIsolate(launcher, vmService, event.getIsolate());
}
}
});
// Resume any isolates paused at the initial connect.
vmService.getVM(new VMConsumer() {
@Override
public void received(VM response) {
final ElementList<IsolateRef> isolates = response.getIsolates();
for (IsolateRef isolateRef : isolates) {
resumePausedAtStartIsolate(launcher, vmService, isolateRef);
}
}
@Override
public void onError(RPCError error) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Error connecting to VM: " + error.getCode() + " " + error.getMessage() + "\n", ProcessOutputTypes.STDERR);
}
}
});
});
return new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse());
}
use of org.dartlang.vm.service.VmService in project flutter-intellij by flutter.
the class DartVmServiceDebugProcess method connect.
private void connect(@NotNull final String url) throws IOException {
final VmService vmService = VmService.connect(url);
final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
vmService.addVmServiceListener(vmServiceListener);
myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
myVmServiceWrapper.handleDebuggerConnected();
myVmConnected = true;
}
use of org.dartlang.vm.service.VmService in project intellij-plugins by JetBrains.
the class DartVmServiceDebugProcess method connect.
private void connect(@NotNull final String url) throws IOException {
final VmService vmService = VmService.connect(url);
final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
vmService.addVmServiceListener(vmServiceListener);
myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
myVmServiceWrapper.handleDebuggerConnected();
myVmConnected = true;
}
use of org.dartlang.vm.service.VmService in project flutter-intellij by flutter.
the class DartVmServiceDebugProcessZ method onConnectSucceeded.
private void onConnectSucceeded(VmService vmService, VmOpenSourceLocationListener vmOpenSourceLocationListener) {
final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
final DartVmServiceBreakpointHandler breakpointHandler = (DartVmServiceBreakpointHandler) myBreakpointHandlers[0];
myVmOpenSourceLocationListener = vmOpenSourceLocationListener;
myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, breakpointHandler);
final ScriptProvider provider = (isolateId, scriptId) -> myVmServiceWrapper.getScriptSync(isolateId, scriptId);
mapper.onConnect(provider, myConnector.getRemoteBaseUrl());
// We disable the remote debug flag so that handleDebuggerConnected() does not echo the stdout and
// stderr streams (this would duplicate what we get over daemon logging).
remoteDebug = false;
final FlutterLaunchMode launchMode = FlutterLaunchMode.getMode(executionEnvironment);
if (launchMode.supportsDebugConnection()) {
myVmServiceWrapper.handleDebuggerConnected();
}
// We re-enable the remote debug flag so that the service wrapper will call our guessRemoteProjectRoot()
// method with the list of loaded libraries for the isolate.
remoteDebug = true;
vmService.addVmServiceListener(vmServiceListener);
myVmOpenSourceLocationListener.addListener(this::onOpenSourceLocationRequest);
myVmConnected = true;
getSession().rebuildViews();
onVmConnected(vmService);
}
Aggregations