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:
2026-11-13 16:52:50 +01:00
parent 910a8b0e85
commit 8a4f456e38
17 changed files with 883 additions and 17 deletions
@@ -0,0 +1,83 @@
package de.neitzel.fxdesigner.kit;
import static org.junit.jupiter.api.Assertions.*;
import de.neitzel.fxdesigner.contracts.DocumentSnapshot;
import de.neitzel.fxdesigner.protocol.BindingMetadata.Problem;
import java.net.URI;
import java.util.List;
import org.junit.jupiter.api.Test;
class FxmlDiagnosticsTest {
private DocumentSnapshot source(String xml) {
return new DocumentSnapshot(URI.create("file:/View.fxml"), 3, xml, true, true);
}
private static final String XML =
"<?import de.neitzel.fx.view.*?><VBox xmlns:fx='http://javafx.com/fxml/1'>\n"
+ "<fx:define><BindingList><!-- untouched --><DirectBinding control='field'"
+ " property='text' path='missing' direction='view'/><Repeat pane='rows'"
+ " collection='items' component='app.Row'/></BindingList></fx:define>\n"
+ "<Label fx:id='field'/><VBox fx:id='rows'/><Table fx:id='table' collection='items'"
+ " row='app.Row'><columns><Column header='N'"
+ " attribute='name'/></columns></Table></VBox>";
@Test
void locatesBindingsRepeatAndTableWithoutProjectionIdentities() {
var d = source(XML);
var result =
FxmlDiagnostics.target(
d,
List.of(
new Problem("field", "text", "ERROR", "bad path"),
new Problem("rows", "children", "WARNING", "unknown"),
new Problem("table", "columns", "ERROR", "bad column")));
assertEquals(
List.of(XML.indexOf("<DirectBinding"), XML.indexOf("<Repeat"), XML.indexOf("<Table")),
result.stream().map(p -> p.location().orElseThrow().offset()).toList());
assertTrue(
result.stream().allMatch(p -> p.location().orElseThrow().document().equals(d.document())));
}
@Test
void ambiguousTargetsIdentifyEveryDeclarationAndDeduplicateEvidence() {
String xml =
XML.replace(
"<!-- untouched -->",
"<ComputedBinding control='field' property='text' method='#value'/>");
var p = new Problem("field", "text", "ERROR", "duplicate");
var result = FxmlDiagnostics.target(source(xml), List.of(p, p));
assertEquals(2, result.size());
assertEquals(
xml.indexOf("<ComputedBinding"), result.getFirst().location().orElseThrow().offset());
}
@Test
void unknownOriginsFallBackToRootAndNestedTargetsAreLocated() {
String xml =
XML.replace(
"control='field' property='text' path='missing' direction='view'/>",
"path='missing'"
+ " direction='view'><control>field</control><property>text</property></DirectBinding>");
var result =
FxmlDiagnostics.target(
source(xml),
List.of(
new Problem("field", "text", "ERROR", "bad"),
new Problem("", "", "WARNING", "context unavailable")));
assertEquals(
xml.indexOf("<DirectBinding"), result.getFirst().location().orElseThrow().offset());
assertEquals(xml.indexOf("<VBox"), result.getLast().location().orElseThrow().offset());
}
@Test
void structuralErrorsAndMalformedXmlRemainNavigable() {
assertFalse(
FxmlDiagnostics.local(source(XML.replace("direction='view'", "direction='wrong'")))
.isEmpty());
var malformed = FxmlDiagnostics.local(source("<VBox>\n<Label>\n</VBox>"));
assertEquals(1, malformed.size());
assertTrue(malformed.getFirst().location().orElseThrow().offset() > 0);
assertTrue(FxmlDiagnostics.local(source(XML)).isEmpty());
}
}
@@ -691,6 +691,75 @@ public final class ProjectionHostChecks {
});
}
@SuppressWarnings("unchecked")
private static java.util.List<de.neitzel.fxdesigner.host.HostServices.Diagnostic> diagnostics(
DesignerPane pane) throws Exception {
return fx(
() ->
java.util.List.copyOf(
((ListView<de.neitzel.fxdesigner.host.HostServices.Diagnostic>)
pane.lookup("#diagnostics-list"))
.getItems()));
}
private static void diagnosticsEdits(DesignerPane pane, DocumentSession document, String full)
throws Exception {
String invalid = full.replace("path=\"rank\"", "path=\"diagnosticMissing\"");
set(document, invalid);
await(() -> fx(() -> source(pane).getText().equals(invalid)));
bindingTab(pane, "Problems");
click(pane, "Validate View");
await(
() -> diagnostics(pane).stream().anyMatch(d -> d.message().contains("diagnosticMissing")));
var problem =
diagnostics(pane).stream()
.filter(d -> d.message().contains("diagnosticMissing"))
.findFirst()
.orElseThrow();
int offset = problem.location().orElseThrow().offset();
check(
invalid.substring(offset).startsWith("<DirectBinding"),
"Diagnostic did not locate authoritative binding declaration");
fx(
() -> {
((ListView<de.neitzel.fxdesigner.host.HostServices.Diagnostic>)
pane.lookup("#diagnostics-list"))
.getSelectionModel()
.select(problem);
return null;
});
click(pane, "Go to FXML");
await(() -> fx(() -> source(pane).getCaretPosition() == offset));
check(documentText(document).equals(invalid), "Diagnostic navigation mutated source");
set(document, full);
await(() -> fx(() -> source(pane).getText().equals(full)));
await(
() -> diagnostics(pane).stream().noneMatch(d -> d.message().contains("diagnosticMissing")));
repeatHistory(pane, document, invalid, full);
bindingTab(pane, "Problems");
click(pane, "Validate View");
await(
() ->
fx(
() ->
((Label) pane.lookup("#diagnostics-state"))
.getText()
.startsWith("Current successful build")));
check(
diagnostics(pane).stream()
.noneMatch(d -> d.severity() == de.neitzel.fxdesigner.host.HostServices.Severity.ERROR),
"Corrected source retained error diagnostics");
set(document, "<VBox>\n<Label>\n</VBox>");
await(() -> diagnostics(pane).stream().anyMatch(d -> d.operation().equals("FXML")));
set(document, full);
await(() -> fx(() -> source(pane).getText().equals(full)));
await(() -> diagnostics(pane).isEmpty());
click(pane, "Split");
System.out.println(
"PASS shared diagnostics: authoritative binding location, source navigation, stale"
+ " withdrawal, correction, exact undo/redo and malformed FXML recovery");
}
private static void structureEdits(DesignerPane pane, DocumentSession document, String full)
throws Exception {
String base =
@@ -1708,6 +1777,7 @@ public final class ProjectionHostChecks {
tableDiscovery(pane, document, full);
tableEdits(pane, document, full);
structureEdits(pane, document, full);
diagnosticsEdits(pane, document, full);
document
.save(document.snapshot().toCompletableFuture().get().revision())
.toCompletableFuture()