Add source highlighting and revision-checked diagnostic fixes in both hosts
This commit is contained in:
@@ -25,7 +25,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
private final Path file;
|
||||
private final KitView kit;
|
||||
private final Label status = new Label("Opening document");
|
||||
private final TextArea source = new TextArea(), output = new TextArea();
|
||||
private final DiagnosticTextArea source = new DiagnosticTextArea();
|
||||
private final TextArea output = new TextArea();
|
||||
private final ComboBox<DesignerWorkflow.Example> examples = new ComboBox<>();
|
||||
private final SplitPane design;
|
||||
private final ContentPanelController content;
|
||||
@@ -124,6 +125,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
private DiagnosticsPane diagnosticsPane;
|
||||
private final String diagnosticsOwner = java.util.UUID.randomUUID().toString();
|
||||
private long diagnosticsRevision = -1;
|
||||
private long diagnosticGeneration;
|
||||
private SplitPane sourceSplit;
|
||||
private Integer pendingSourceOffset;
|
||||
private String pendingReferenceValidation;
|
||||
@@ -727,6 +729,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
host.diagnostics().clear(diagnosticsOwner);
|
||||
if (diagnosticsPane != null) diagnosticsPane.show(java.util.List.of(), message);
|
||||
diagnosticsRevision = -1;
|
||||
diagnosticGeneration++;
|
||||
source.diagnostics("", java.util.List.of());
|
||||
validatedSource = null;
|
||||
validatingSource = null;
|
||||
validationPreview = false;
|
||||
@@ -743,8 +747,34 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
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);
|
||||
var captured = draft;
|
||||
long generation = ++diagnosticGeneration;
|
||||
java.util.function.Consumer<HostServices.QuickFix> apply =
|
||||
fix -> fx(() -> applyDiagnosticFix(captured, generation, diagnostics, fix));
|
||||
diagnosticsPane.show(diagnostics, label, apply);
|
||||
source.diagnostics(captured.text(), diagnostics);
|
||||
host.diagnostics().replace(diagnosticsOwner, captured, label, diagnostics, apply);
|
||||
}
|
||||
|
||||
private void applyDiagnosticFix(
|
||||
DocumentSnapshot captured,
|
||||
long generation,
|
||||
java.util.List<HostServices.Diagnostic> diagnostics,
|
||||
HostServices.QuickFix fix) {
|
||||
if (closed || generation != diagnosticGeneration) return;
|
||||
withDraft(
|
||||
() -> {
|
||||
if (generation != diagnosticGeneration
|
||||
|| draft.revision() != captured.revision()
|
||||
|| !draft.text().equals(captured.text())
|
||||
|| !draft.writable()
|
||||
|| diagnostics.stream().noneMatch(d -> d.fixes().contains(fix))) {
|
||||
status.setText("Diagnostic changed; validate again before applying a fix");
|
||||
return;
|
||||
}
|
||||
pendingReferenceValidation = apply(draft.text(), fix.edits());
|
||||
submit(fix.edits(), fix.label());
|
||||
});
|
||||
}
|
||||
|
||||
private void validationUnavailable(Throwable error) {
|
||||
@@ -1378,6 +1408,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
public void close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
diagnosticGeneration++;
|
||||
source.diagnostics("", java.util.List.of());
|
||||
host.diagnostics().clear(diagnosticsOwner);
|
||||
try {
|
||||
changes.close();
|
||||
|
||||
Reference in New Issue
Block a user