Publish shared FXML diagnostics and integrate IntelliJ Problems
Navigate authoritative FXML locations, withdraw stale results and preserve host Undo/Redo. Include editor ownership in native problem identity so equal diagnostics from separate owners survive independent cleanup. Qualify both hosts automatically.
This commit is contained in:
@@ -121,6 +121,11 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
private BindingEditor bindingEditor, computedEditor, repeatEditor;
|
||||
private TableEditor tableEditor;
|
||||
private ReferenceEditor referenceEditor;
|
||||
private DiagnosticsPane diagnosticsPane;
|
||||
private final String diagnosticsOwner = java.util.UUID.randomUUID().toString();
|
||||
private long diagnosticsRevision = -1;
|
||||
private SplitPane sourceSplit;
|
||||
private Integer pendingSourceOffset;
|
||||
private String pendingReferenceValidation;
|
||||
private String validatedSource, validatingSource;
|
||||
private boolean validationPreview;
|
||||
@@ -220,6 +225,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
new TableEditor(
|
||||
this::editTable, this::navigateComponent, values -> validateBindings(values, false));
|
||||
referenceEditor = new ReferenceEditor(file.toUri().toString(), this::editStructure);
|
||||
diagnosticsPane =
|
||||
new DiagnosticsPane(() -> validateBindings(null, false), this::navigateDiagnostic);
|
||||
bindingBrowser =
|
||||
new BindingBrowser(
|
||||
this::discoverBindings,
|
||||
@@ -346,6 +353,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
});
|
||||
var split = new SplitPane(source, design);
|
||||
sourceSplit = split;
|
||||
split.setDividerPositions(.3);
|
||||
var modes =
|
||||
new ToolBar(
|
||||
@@ -372,13 +380,21 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
repeatTab.setClosable(false);
|
||||
var tableTab = new Tab("Table / Columns", tableEditor);
|
||||
tableTab.setClosable(false);
|
||||
var problemsTab = new Tab("Problems", diagnosticsPane);
|
||||
problemsTab.setClosable(false);
|
||||
var structureTab = new Tab("Structure", referenceEditor);
|
||||
structureTab.setClosable(false);
|
||||
var bindings =
|
||||
new TitledPane(
|
||||
"Bindings",
|
||||
new TabPane(
|
||||
directBindingTab, computedTab, repeatTab, tableTab, structureTab, discoveryTab));
|
||||
directBindingTab,
|
||||
computedTab,
|
||||
repeatTab,
|
||||
tableTab,
|
||||
structureTab,
|
||||
problemsTab,
|
||||
discoveryTab));
|
||||
bindings.setExpanded(false);
|
||||
center.setBottom(new VBox(properties, bindings));
|
||||
output.setEditable(false);
|
||||
@@ -478,6 +494,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
.report(
|
||||
new HostServices.Diagnostic(
|
||||
"Designer", HostServices.Severity.ERROR, String.valueOf(error), Optional.empty()));
|
||||
if (draft != null && diagnosticsPane != null) validationUnavailable(error);
|
||||
status.setText("Designer: " + error.getMessage());
|
||||
log(error.toString());
|
||||
}
|
||||
@@ -518,6 +535,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
draft = value;
|
||||
publishDiagnostics("Source checked; target validation outdated", java.util.List.of());
|
||||
bindingEditor.load(value.text(), value.writable());
|
||||
computedEditor.load(value.text(), value.writable());
|
||||
repeatEditor.load(value.text(), value.writable());
|
||||
@@ -544,6 +562,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
var hit = kit.editor().getSelection().getHitItem();
|
||||
String selectedId = hit == null ? null : hit.getFxId();
|
||||
draft = value;
|
||||
publishDiagnostics("Source checked; target validation outdated", java.util.List.of());
|
||||
bindingEditor.load(value.text(), value.writable());
|
||||
computedEditor.load(value.text(), value.writable());
|
||||
repeatEditor.load(value.text(), value.writable());
|
||||
@@ -614,6 +633,11 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
report(error);
|
||||
} finally {
|
||||
loading = false;
|
||||
if (pendingSourceOffset != null) {
|
||||
int offset = pendingSourceOffset;
|
||||
pendingSourceOffset = null;
|
||||
showSource(offset);
|
||||
}
|
||||
if (value.text().equals(pendingReferenceValidation)) {
|
||||
pendingReferenceValidation = null;
|
||||
Platform.runLater(() -> validateBindings(null, false));
|
||||
@@ -700,6 +724,9 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
|
||||
private void invalidateBindings(String message) {
|
||||
bindingRequest++;
|
||||
host.diagnostics().clear(diagnosticsOwner);
|
||||
if (diagnosticsPane != null) diagnosticsPane.show(java.util.List.of(), message);
|
||||
diagnosticsRevision = -1;
|
||||
validatedSource = null;
|
||||
validatingSource = null;
|
||||
validationPreview = false;
|
||||
@@ -709,6 +736,66 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
tableEditor.invalidateDiscovery();
|
||||
}
|
||||
|
||||
private void publishDiagnostics(String context, java.util.List<HostServices.Diagnostic> target) {
|
||||
if (closed || draft == null) return;
|
||||
var all = new java.util.LinkedHashSet<>(FxmlDiagnostics.local(draft));
|
||||
all.addAll(target);
|
||||
var diagnostics = java.util.List.copyOf(all);
|
||||
diagnosticsRevision = draft.revision();
|
||||
String label = context + " · draft revision " + draft.revision();
|
||||
diagnosticsPane.show(diagnostics, label);
|
||||
host.diagnostics().replace(diagnosticsOwner, draft, label, diagnostics);
|
||||
}
|
||||
|
||||
private void validationUnavailable(Throwable error) {
|
||||
publishDiagnostics(
|
||||
"Validation unavailable; results are not a clean bill of health",
|
||||
java.util.List.of(
|
||||
new HostServices.Diagnostic(
|
||||
"Designer",
|
||||
HostServices.Severity.ERROR,
|
||||
String.valueOf(error.getMessage()),
|
||||
Optional.of(new HostServices.Location(draft.document(), 0)))));
|
||||
}
|
||||
|
||||
private void navigateDiagnostic(HostServices.Diagnostic problem) {
|
||||
long revision = diagnosticsRevision;
|
||||
withDraft(
|
||||
() -> {
|
||||
if (revision != draft.revision()) {
|
||||
publishDiagnostics(
|
||||
"Document changed; validate again before navigating", java.util.List.of());
|
||||
return;
|
||||
}
|
||||
problem
|
||||
.location()
|
||||
.ifPresent(
|
||||
location -> {
|
||||
if (location.document().equals(draft.document())) showSource(location.offset());
|
||||
else
|
||||
host.navigation()
|
||||
.openSource(location)
|
||||
.exceptionally(
|
||||
error -> {
|
||||
fx(() -> report(error));
|
||||
return null;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Select authoritative FXML source, preserving the host-owned draft and undo history. */
|
||||
public void showSource(int offset) {
|
||||
if (closed) return;
|
||||
if (draft == null) {
|
||||
pendingSourceOffset = offset;
|
||||
return;
|
||||
}
|
||||
sourceSplit.getItems().setAll(source);
|
||||
source.positionCaret(Math.min(Math.max(0, offset), source.getLength()));
|
||||
source.requestFocus();
|
||||
}
|
||||
|
||||
private void editStructure(ReferenceEditor.Intent intent) {
|
||||
withDraft(
|
||||
() -> {
|
||||
@@ -796,6 +883,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
var captured = draft;
|
||||
validatingSource = captured.text();
|
||||
validationPreview |= preview;
|
||||
publishDiagnostics("Validating target types…", java.util.List.of());
|
||||
status.setText("Validating binding types in target runtime…");
|
||||
bindingWorkflow
|
||||
.bindingDetails(
|
||||
@@ -820,12 +908,18 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
boolean resumePreview = validationPreview;
|
||||
validationPreview = false;
|
||||
if (error != null) {
|
||||
validationUnavailable(error);
|
||||
status.setText(
|
||||
"Binding validation unavailable: " + error.getMessage());
|
||||
return;
|
||||
}
|
||||
validatedSource = captured.text();
|
||||
bindingProblems = metadata.problems();
|
||||
publishDiagnostics(
|
||||
last
|
||||
? "Explicit retained build (outdated)"
|
||||
: "Current successful build",
|
||||
FxmlDiagnostics.target(captured, metadata.problems()));
|
||||
bindingEditor.metadata(
|
||||
metadata,
|
||||
values,
|
||||
@@ -888,6 +982,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
boolean resumePreview = validationPreview;
|
||||
validationPreview = false;
|
||||
if (error != null) {
|
||||
validationUnavailable(error);
|
||||
bindingBrowser.invalidate(
|
||||
"Discovery unavailable: "
|
||||
+ error.getMessage()
|
||||
@@ -896,6 +991,11 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
validatedSource = captured.text();
|
||||
bindingProblems = metadata.problems();
|
||||
publishDiagnostics(
|
||||
last
|
||||
? "Explicit retained build (outdated)"
|
||||
: "Current successful build",
|
||||
FxmlDiagnostics.target(captured, metadata.problems()));
|
||||
bindingBrowser.show(
|
||||
metadata,
|
||||
(last
|
||||
@@ -1278,6 +1378,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
public void close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
host.diagnostics().clear(diagnosticsOwner);
|
||||
try {
|
||||
changes.close();
|
||||
saves.close();
|
||||
|
||||
Reference in New Issue
Block a user