|
21 | 21 | import com.intellij.openapi.roots.ModuleRootManager;
|
22 | 22 | import com.intellij.openapi.util.Disposer;
|
23 | 23 | import com.intellij.openapi.util.SystemInfo;
|
| 24 | +import com.intellij.openapi.vfs.LocalFileSystem; |
24 | 25 | import com.intellij.openapi.vfs.VirtualFile;
|
25 | 26 | import com.intellij.psi.PsiDocumentManager;
|
26 | 27 | import com.intellij.psi.PsiElement;
|
|
55 | 56 | import java.awt.*;
|
56 | 57 | import java.awt.image.BufferedImage;
|
57 | 58 | import java.io.ByteArrayInputStream;
|
| 59 | +import java.io.File; |
58 | 60 | import java.io.IOException;
|
| 61 | +import java.net.MalformedURLException; |
| 62 | +import java.net.URL; |
59 | 63 | import java.util.List;
|
60 | 64 | import java.util.*;
|
61 | 65 | import java.util.concurrent.CompletableFuture;
|
@@ -418,6 +422,37 @@ private void onVmServiceReceived(String streamId, Event event) {
|
418 | 422 | }
|
419 | 423 | break;
|
420 | 424 | }
|
| 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 | + } |
421 | 456 | default:
|
422 | 457 | }
|
423 | 458 | }
|
|
0 commit comments