Skip to content

Commit a554fc6

Browse files
Show the message notes and the counterexample in the hover
The editor diagnostic, and so the hover and the Problems view, now carries the headline, then the verifier's message notes, then its counterexample, each on its own line. The hints stay in the LiquidJava view. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 69b6860 commit a554fc6

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎server/src/main/java/LJDiagnosticsHandler.java‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public static List<PublishDiagnosticsParams> getDiagnostics(List<LJDiagnostic> d
7272
d -> PathUtils.toFileUri(d.getFile()),
7373
Collectors.mapping(d -> {
7474
Range range = getRangeFromPosition(d.getPosition());
75-
String message = String.format("%s: %s", d.getTitle(), d.getMessage());
76-
return new Diagnostic(range, message, severity, SOURCE);
75+
return new Diagnostic(range, getHoverMessage(d), severity, SOURCE);
7776
}, Collectors.toList())
7877
));
7978

@@ -83,6 +82,22 @@ public static List<PublishDiagnosticsParams> getDiagnostics(List<LJDiagnostic> d
8382
.toList();
8483
}
8584

85+
/**
86+
* The message the editor shows for a diagnostic: the headline, then the notes that explain it and the
87+
* counterexample, each on its own line. The hints are left to the LiquidJava view
88+
* @param diagnostic the diagnostic
89+
* @return the message
90+
*/
91+
static String getHoverMessage(LJDiagnostic diagnostic) {
92+
List<String> lines = new ArrayList<>();
93+
lines.add(String.format("%s: %s", diagnostic.getTitle(), diagnostic.getMessage()));
94+
lines.addAll(diagnostic.getMessageNotes());
95+
String counterexample = diagnostic.getCounterexampleStr();
96+
if (counterexample != null && !counterexample.isBlank())
97+
lines.add(counterexample);
98+
return String.join("\n", lines);
99+
}
100+
86101
/**
87102
* Generates empty diagnostics for the given URI
88103
* @param uri the uri used for the verification
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
3+
import java.util.List;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import liquidjava.diagnostics.LJDiagnostic;
8+
import liquidjava.diagnostics.hints.Hint;
9+
10+
class LJDiagnosticsHandlerTest {
11+
12+
@Test
13+
void hoverShowsTheHeadlineThenTheNotesThenTheCounterexampleButNoHints() {
14+
LJDiagnostic diagnostic = new LJDiagnostic("Refinement Error", "expected timeout >= 0 but could not prove it",
15+
null, "", null) {
16+
@Override
17+
public List<String> getMessageNotes() {
18+
return List.of("where Positive(x) means x > 0");
19+
}
20+
};
21+
diagnostic.setCounterexampleStr("Counterexample: timeout == -1");
22+
diagnostic.addHint(Hint.general("Add a refinement"));
23+
24+
assertEquals("""
25+
Refinement Error: expected timeout >= 0 but could not prove it
26+
where Positive(x) means x > 0
27+
Counterexample: timeout == -1""", LJDiagnosticsHandler.getHoverMessage(diagnostic));
28+
}
29+
}

0 commit comments

Comments
 (0)