Skip to content

Commit ba7b436

Browse files
authored
[CQ] limit internal XDebugSessionImpl dependence; remove dead code (#8206)
🤫 Limits `XDebugSessionImpl` dependence (silencing two internal API access inspections); adding a note explaining our usage 🧹 Removes `VmServiceWrapper` dead code --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](#8098)). </details>
1 parent 6cee9cd commit ba7b436

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

src/io/flutter/vmService/DartVmServiceDebugProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ public void received(Isolate isolate) {
514514
else if (eventKind == EventKind.Resume) {
515515
// Currently true if we got here via 'flutter attach'
516516
OpenApiUtils.safeInvokeLater(() -> {
517-
myVmServiceWrapper.attachIsolate(isolateRef, isolate);
517+
myVmServiceWrapper.attachIsolate(isolateRef);
518518
});
519519
}
520520
}

src/io/flutter/vmService/VmServiceWrapper.java

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.intellij.xdebugger.impl.XDebugSessionImpl;
2525
import com.jetbrains.lang.dart.DartFileType;
2626
import io.flutter.bazel.WorkspaceCache;
27-
import io.flutter.run.daemon.FlutterApp;
2827
import io.flutter.sdk.FlutterSdk;
2928
import io.flutter.sdk.FlutterSdkVersion;
3029
import io.flutter.utils.OpenApiUtils;
@@ -33,13 +32,56 @@
3332
import io.flutter.vmService.frame.DartVmServiceStackFrame;
3433
import io.flutter.vmService.frame.DartVmServiceValue;
3534
import org.dartlang.vm.service.VmService;
36-
import org.dartlang.vm.service.consumer.*;
37-
import org.dartlang.vm.service.element.*;
35+
import org.dartlang.vm.service.consumer.AddBreakpointWithScriptUriConsumer;
36+
import org.dartlang.vm.service.consumer.EvaluateConsumer;
37+
import org.dartlang.vm.service.consumer.EvaluateInFrameConsumer;
38+
import org.dartlang.vm.service.consumer.GetIsolateConsumer;
39+
import org.dartlang.vm.service.consumer.GetObjectConsumer;
40+
import org.dartlang.vm.service.consumer.GetStackConsumer;
41+
import org.dartlang.vm.service.consumer.InvokeConsumer;
42+
import org.dartlang.vm.service.consumer.PauseConsumer;
43+
import org.dartlang.vm.service.consumer.RemoveBreakpointConsumer;
44+
import org.dartlang.vm.service.consumer.SetExceptionPauseModeConsumer;
45+
import org.dartlang.vm.service.consumer.SetIsolatePauseModeConsumer;
46+
import org.dartlang.vm.service.consumer.SuccessConsumer;
47+
import org.dartlang.vm.service.consumer.UriListConsumer;
48+
import org.dartlang.vm.service.consumer.VMConsumer;
49+
import org.dartlang.vm.service.consumer.VersionConsumer;
50+
import org.dartlang.vm.service.element.Breakpoint;
51+
import org.dartlang.vm.service.element.ElementList;
52+
import org.dartlang.vm.service.element.ErrorRef;
53+
import org.dartlang.vm.service.element.Event;
54+
import org.dartlang.vm.service.element.EventKind;
55+
import org.dartlang.vm.service.element.ExceptionPauseMode;
56+
import org.dartlang.vm.service.element.Frame;
57+
import org.dartlang.vm.service.element.FrameKind;
58+
import org.dartlang.vm.service.element.InstanceRef;
59+
import org.dartlang.vm.service.element.Isolate;
60+
import org.dartlang.vm.service.element.IsolateRef;
61+
import org.dartlang.vm.service.element.LibraryRef;
62+
import org.dartlang.vm.service.element.Obj;
63+
import org.dartlang.vm.service.element.RPCError;
64+
import org.dartlang.vm.service.element.Script;
65+
import org.dartlang.vm.service.element.ScriptRef;
66+
import org.dartlang.vm.service.element.Sentinel;
3867
import org.dartlang.vm.service.element.Stack;
68+
import org.dartlang.vm.service.element.StepOption;
69+
import org.dartlang.vm.service.element.Success;
70+
import org.dartlang.vm.service.element.UnresolvedSourceLocation;
71+
import org.dartlang.vm.service.element.UriList;
72+
import org.dartlang.vm.service.element.VM;
3973
import org.jetbrains.annotations.NotNull;
4074
import org.jetbrains.annotations.Nullable;
4175

42-
import java.util.*;
76+
import java.util.ArrayList;
77+
import java.util.Collection;
78+
import java.util.Collections;
79+
import java.util.HashMap;
80+
import java.util.HashSet;
81+
import java.util.List;
82+
import java.util.Map;
83+
import java.util.Objects;
84+
import java.util.Set;
4385
import java.util.concurrent.CompletableFuture;
4486
import java.util.concurrent.atomic.AtomicInteger;
4587
import java.util.regex.Matcher;
@@ -93,15 +135,6 @@ private void addRequest(@NotNull Runnable runnable) {
93135
}
94136
}
95137

96-
@NotNull
97-
public List<IsolateRef> getExistingIsolates() {
98-
List<IsolateRef> isolateRefs = new ArrayList<>();
99-
for (IsolatesInfo.IsolateInfo isolateInfo : myIsolatesInfo.getIsolateInfos()) {
100-
isolateRefs.add(isolateInfo.getIsolateRef());
101-
}
102-
return isolateRefs;
103-
}
104-
105138
@Nullable
106139
public StepOption getLatestStep() {
107140
return myLatestStep;
@@ -145,7 +178,7 @@ public void received(final Isolate isolate) {
145178

146179
// This is the entry point for attaching a debugger to a running app.
147180
if (eventKind == EventKind.Resume) {
148-
attachIsolate(isolateRef, isolate);
181+
attachIsolate(isolateRef);
149182
return;
150183
}
151184
// if event is not PauseStart it means that PauseStart event will follow later and will be handled by listener
@@ -290,13 +323,16 @@ public void received(Success response) {
290323
}
291324
}
292325

293-
public void attachIsolate(@NotNull IsolateRef isolateRef, @NotNull Isolate isolate) {
326+
public void attachIsolate(@NotNull IsolateRef isolateRef) {
294327
boolean newIsolate = myIsolatesInfo.addIsolate(isolateRef);
295328
// Just to make sure that the main isolate is not handled twice, both from handleDebuggerConnected() and DartVmServiceListener.received(PauseStart)
296329
if (newIsolate) {
297-
XDebugSessionImpl session = (XDebugSessionImpl)myDebugProcess.getSession();
330+
var session = myDebugProcess.getSession();
298331
OpenApiUtils.safeRunReadAction(() -> {
299-
session.reset();
332+
// Only the impl class supports reset so we need to cast.
333+
// Note that `XDebugSessionImpl` is marked internal, so this may not be safe long-run.
334+
// See: https://github.com/flutter/flutter-intellij/issues/7718
335+
((XDebugSessionImpl)session).reset();
300336
session.initBreakpoints();
301337
});
302338
setIsolatePauseMode(isolateRef.getId(), myDebugProcess.getBreakOnExceptionMode(), isolateRef);
@@ -328,20 +364,6 @@ public void received(final Isolate isolate) {
328364
}
329365
}
330366

331-
private void setInitialBreakpointsAndCheckExtensions(@NotNull IsolateRef isolateRef, @NotNull Isolate isolate) {
332-
doSetBreakpointsForIsolate(myBreakpointHandler.getXBreakpoints(), isolateRef.getId(), () -> {
333-
myIsolatesInfo.setBreakpointsSet(isolateRef);
334-
});
335-
FlutterApp app = FlutterApp.fromEnv(myDebugProcess.getExecutionEnvironment());
336-
// TODO(messick) Consider replacing this test with an assert; could interfere with setExceptionPauseMode().
337-
if (app != null) {
338-
VMServiceManager service = app.getVMServiceManager();
339-
if (service != null) {
340-
service.addRegisteredExtensionRPCs(isolate);
341-
}
342-
}
343-
}
344-
345367
private void doSetInitialBreakpointsAndResume(@NotNull IsolateRef isolateRef) {
346368
doSetBreakpointsForIsolate(myBreakpointHandler.getXBreakpoints(), isolateRef.getId(), () -> {
347369
myIsolatesInfo.setBreakpointsSet(isolateRef);
@@ -471,8 +493,7 @@ private boolean isVmServiceMappingSupported(org.dartlang.vm.service.element.Vers
471493
if (WorkspaceCache.getInstance(myDebugProcess.getSession().getProject()).isBazel()) {
472494
return true;
473495
}
474-
475-
FlutterSdk sdk = FlutterSdk.getFlutterSdk(myDebugProcess.getSession().getProject());
496+
476497
return VmServiceVersion.hasMapping(version);
477498
}
478499

0 commit comments

Comments
 (0)