Implement retained target sessions, runtime sizing and Component navigation
This commit is contained in:
@@ -27,31 +27,85 @@ public final class IntellijHost implements AutoCloseable {
|
||||
docs,
|
||||
(request, output) -> scope.own(builds.start(request, output)),
|
||||
runtimes,
|
||||
location -> {
|
||||
var result = new CompletableFuture<Void>();
|
||||
ApplicationManager.getApplication()
|
||||
.invokeLater(
|
||||
() ->
|
||||
WriteIntentReadAction.run(
|
||||
() -> {
|
||||
try {
|
||||
if (project.isDisposed())
|
||||
throw new IllegalStateException("Project disposed");
|
||||
var file =
|
||||
LocalFileSystem.getInstance()
|
||||
.refreshAndFindFileByNioFile(
|
||||
Path.of(location.document()));
|
||||
if (file == null)
|
||||
throw new IllegalArgumentException(
|
||||
"Navigation file unavailable");
|
||||
new OpenFileDescriptor(project, file, location.offset())
|
||||
.navigate(true);
|
||||
result.complete(null);
|
||||
} catch (Throwable e) {
|
||||
result.completeExceptionally(e);
|
||||
}
|
||||
}));
|
||||
return result;
|
||||
new HostServices.Navigation() {
|
||||
public CompletionStage<java.util.List<HostServices.Location>> componentSources(
|
||||
String type) {
|
||||
if (!type.matches("[A-Za-z_$][A-Za-z0-9_$]*(\\.[A-Za-z_$][A-Za-z0-9_$]*)*"))
|
||||
return CompletableFuture.failedFuture(
|
||||
new IllegalArgumentException("Invalid type"));
|
||||
return CompletableFuture.supplyAsync(
|
||||
() ->
|
||||
com.intellij.openapi.application.ReadAction.compute(
|
||||
() -> {
|
||||
var result = new java.util.ArrayList<HostServices.Location>();
|
||||
String path = type.replace('.', '/');
|
||||
for (var owner :
|
||||
com.intellij.openapi.project.ProjectManager.getInstance()
|
||||
.getOpenProjects()) {
|
||||
var roots =
|
||||
com.intellij.openapi.roots.ProjectRootManager.getInstance(owner)
|
||||
.getContentSourceRoots();
|
||||
boolean declared =
|
||||
java.util.Arrays.stream(roots)
|
||||
.anyMatch(
|
||||
r -> r.findFileByRelativePath(path + ".java") != null);
|
||||
if (declared)
|
||||
for (var root : roots) {
|
||||
var file = root.findFileByRelativePath(path + ".fxml");
|
||||
if (file != null && file.isInLocalFileSystem())
|
||||
result.add(
|
||||
new HostServices.Location(
|
||||
Path.of(file.getPath()).toUri(), 0));
|
||||
}
|
||||
}
|
||||
return java.util.List.copyOf(result);
|
||||
}));
|
||||
}
|
||||
|
||||
public CompletionStage<Void> open(HostServices.Location location) {
|
||||
var result = new CompletableFuture<Void>();
|
||||
ApplicationManager.getApplication()
|
||||
.invokeLater(
|
||||
() ->
|
||||
WriteIntentReadAction.run(
|
||||
() -> {
|
||||
try {
|
||||
if (project.isDisposed())
|
||||
throw new IllegalStateException("Project disposed");
|
||||
var file =
|
||||
LocalFileSystem.getInstance()
|
||||
.refreshAndFindFileByNioFile(
|
||||
Path.of(location.document()));
|
||||
if (file == null)
|
||||
throw new IllegalArgumentException(
|
||||
"Navigation file unavailable");
|
||||
Project owner = project;
|
||||
for (var candidate :
|
||||
com.intellij.openapi.project.ProjectManager.getInstance()
|
||||
.getOpenProjects())
|
||||
if (!candidate.isDisposed()
|
||||
&& com.intellij.openapi.roots.ProjectFileIndex
|
||||
.getInstance(candidate)
|
||||
.isInSourceContent(file)) {
|
||||
owner = candidate;
|
||||
break;
|
||||
}
|
||||
if ("fxml".equalsIgnoreCase(file.getExtension())) {
|
||||
var manager =
|
||||
com.intellij.openapi.fileEditor.FileEditorManager
|
||||
.getInstance(owner);
|
||||
manager.openFile(file, true);
|
||||
manager.setSelectedEditor(file, "neitzel-fx-designer");
|
||||
} else
|
||||
new OpenFileDescriptor(owner, file, location.offset())
|
||||
.navigate(true);
|
||||
result.complete(null);
|
||||
} catch (Throwable e) {
|
||||
result.completeExceptionally(e);
|
||||
}
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
},
|
||||
diagnostics,
|
||||
scope);
|
||||
|
||||
Reference in New Issue
Block a user