Skip to content

Commit a1f1522

Browse files
authored
Use ToolEvent for inspect elements (#6881)
Fixes #6875 Some things I'm not sure about: - I'm currently using the custom VM service stream 'ToolEvent' directly. VS Code is using the DAP forwarding of events from this stream; is this a point where it would make sense to use DAP from DDS? - This skips large portions of previous architecture to listen for changes in selections, e.g. classes like `InspectorObjectGroupManager` - is that okay?
1 parent 16749f9 commit a1f1522

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

flutter-idea/src/io/flutter/inspector/InspectorService.java

+35
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.intellij.openapi.roots.ModuleRootManager;
2222
import com.intellij.openapi.util.Disposer;
2323
import com.intellij.openapi.util.SystemInfo;
24+
import com.intellij.openapi.vfs.LocalFileSystem;
2425
import com.intellij.openapi.vfs.VirtualFile;
2526
import com.intellij.psi.PsiDocumentManager;
2627
import com.intellij.psi.PsiElement;
@@ -55,7 +56,10 @@
5556
import java.awt.*;
5657
import java.awt.image.BufferedImage;
5758
import java.io.ByteArrayInputStream;
59+
import java.io.File;
5860
import java.io.IOException;
61+
import java.net.MalformedURLException;
62+
import java.net.URL;
5963
import java.util.List;
6064
import java.util.*;
6165
import java.util.concurrent.CompletableFuture;
@@ -418,6 +422,37 @@ private void onVmServiceReceived(String streamId, Event event) {
418422
}
419423
break;
420424
}
425+
case "ToolEvent": {
426+
Optional<Event> eventOrNull = Optional.ofNullable(event);
427+
if ("navigate".equals(eventOrNull.map(Event::getExtensionKind).orElse(null))) {
428+
JsonObject json = eventOrNull.map(Event::getExtensionData).map(ExtensionData::getJson).orElse(null);
429+
if (json == null) return;
430+
431+
String fileUri = JsonUtils.getStringMember(json, "fileUri");
432+
if (fileUri == null) return;
433+
434+
String path;
435+
try {
436+
path = new URL(fileUri).getFile();
437+
}
438+
catch (MalformedURLException e) {
439+
return;
440+
}
441+
if (path == null) return;
442+
443+
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
444+
final Integer line = JsonUtils.getIntMember(json, "line");
445+
final Integer column = JsonUtils.getIntMember(json, "column");;
446+
447+
ApplicationManager.getApplication().invokeLater(() -> {
448+
if (file != null && line >= 0 && column >= 0) {
449+
XSourcePositionImpl position = XSourcePositionImpl.create(file, line - 1, column - 1);
450+
position.createNavigatable(app.getProject()).navigate(false);
451+
}
452+
});
453+
}
454+
break;
455+
}
421456
default:
422457
}
423458
}

flutter-idea/src/io/flutter/vmService/VmServiceWrapper.java

+11
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ public void received(final Isolate isolate) {
174174
});
175175
}
176176
});
177+
178+
streamListen("ToolEvent", new SuccessConsumer() {
179+
@Override
180+
public void received(Success response) {
181+
}
182+
183+
@Override
184+
public void onError(RPCError error) {
185+
LOG.error("Error listening to ToolEvent stream: " + error);
186+
}
187+
});
177188
}
178189

179190
private void streamListen(@NotNull String streamId, @NotNull SuccessConsumer consumer) {

0 commit comments

Comments
 (0)