Add source highlighting and revision-checked diagnostic fixes in both hosts

This commit is contained in:
2026-11-13 18:19:39 +01:00
parent 8a4f456e38
commit 9bc4569407
18 changed files with 1033 additions and 14 deletions
@@ -91,13 +91,46 @@ public record HostServices(
ERROR
}
/** Half-open UTF-16 range in the authoritative source. */
public record SourceRange(int start, int end) {
public SourceRange {
if (start < 0 || end < start) throw new IllegalArgumentException("Invalid diagnostic range");
}
}
public record QuickFix(
String label, List<de.neitzel.fxdesigner.contracts.EditBatch.Replacement> edits) {
public QuickFix {
if (label == null || label.isBlank()) throw new IllegalArgumentException("Missing fix label");
edits = List.copyOf(edits);
if (edits.isEmpty()) throw new IllegalArgumentException("Empty fix");
}
@Override
public String toString() {
return label;
}
}
public record Diagnostic(
String operation, Severity severity, String message, Optional<Location> location) {
String operation,
Severity severity,
String message,
Optional<Location> location,
Optional<SourceRange> range,
List<QuickFix> fixes) {
public Diagnostic(
String operation, Severity severity, String message, Optional<Location> location) {
this(operation, severity, message, location, Optional.empty(), List.of());
}
public Diagnostic {
Objects.requireNonNull(operation);
Objects.requireNonNull(severity);
Objects.requireNonNull(message);
Objects.requireNonNull(location);
Objects.requireNonNull(range);
fixes = List.copyOf(fixes);
}
}
@@ -111,6 +144,16 @@ public record HostServices(
String context,
List<Diagnostic> diagnostics) {}
/** Fix execution stays with the shared editor's revision-checked host transaction. */
default void replace(
String owner,
de.neitzel.fxdesigner.contracts.DocumentSnapshot source,
String context,
List<Diagnostic> diagnostics,
Consumer<QuickFix> apply) {
replace(owner, source, context, diagnostics);
}
/** Withdraw this editor's diagnostics without removing another editor's results. */
default void clear(String owner) {}
}