Skip to content

Commit

Permalink
Icons and other improvements on TLAPS.
Browse files Browse the repository at this point in the history
Signed-off-by: Karolis Petrauskas <k.petrauskas@gmail.com>
  • Loading branch information
kape1395 committed Jan 26, 2024
1 parent 7f4b577 commit ff06f3e
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 21 deletions.
3 changes: 3 additions & 0 deletions resources/images/icons-material/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Icons for the TLAPS proof steps:
- These icons are downloaded from <https://fonts.google.com/icons>.
- The files with the suffix `-color` are manually edited to add the fill color.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/model/tlaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface TlapsProofObligationState {

export interface TlapsProofStepDetails {
kind: string;
status: string;
location: Location;
obligations: TlapsProofObligationState[];
}
95 changes: 74 additions & 21 deletions src/tlaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
// - Visible range: https://stackoverflow.com/questions/40339229/vscode-extension-api-how-to-get-only-visible-lines-of-editor

Check warning on line 11 in src/tlaps.ts

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

This line has a length of 126. Maximum allowed is 120

Check warning on line 11 in src/tlaps.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

This line has a length of 126. Maximum allowed is 120

Check warning on line 11 in src/tlaps.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This line has a length of 126. Maximum allowed is 120

Check warning on line 11 in src/tlaps.ts

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

This line has a length of 126. Maximum allowed is 120

Check warning on line 11 in src/tlaps.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

This line has a length of 126. Maximum allowed is 120

Check warning on line 11 in src/tlaps.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This line has a length of 126. Maximum allowed is 120
// - Cursor change event: https://stackoverflow.com/questions/44782075/vscode-extension-ondidchangecursorposition
//
// TODO: Try getting the expanded proof obligations from the parser instead of the prover.
//
// TODO: Icons: https://code.visualstudio.com/api/references/icons-in-labels
// - testing-passed-icon
// - testing-failed-icon
// - settings-sync-view-icon $(sync~spin)
// - testing-run-icon
//
// TODO: Links to the proof steps: DocumentLinkProvider<T>
//
// TODO: Links from the side pane: TextEditor.revealRange(range: Range, revealType?: TextEditorRevealType): void
//
import * as vscode from 'vscode';
import {
DocumentUri,
Expand All @@ -28,11 +31,11 @@ import {
VersionedTextDocumentIdentifier
} from 'vscode-languageclient/node';
import { TlapsProofObligationView } from './webview/tlapsCurrentProofObligationView';
import { TlapsProofObligationState, TlapsProofStepDetails } from './model/tlaps';
import { TlapsProofStepDetails } from './model/tlaps';

interface ProofStateMarker {
interface ProofStepMarker {
status: string;
range: vscode.Range;
state: string;
hover: string;
}

Expand All @@ -50,6 +53,23 @@ export class TlapsClient {
'progress',
];
private proofStateDecorationTypes = new Map<string, vscode.TextEditorDecorationType>();
private iconsAdhoc = new Map<string, string>(Object.entries({
proved: 'icons-adhoc/tlaps-proof-state-proved.svg',
failed: 'icons-adhoc/tlaps-proof-state-failed.svg',
omitted: 'icons-adhoc/tlaps-proof-state-omitted.svg',
missing: 'icons-adhoc/tlaps-proof-state-missing.svg',
pending: 'icons-adhoc/tlaps-proof-state-pending.svg',
progress: 'icons-adhoc/tlaps-proof-state-progress.svg',
}));
private iconsMaterial = new Map<string, string>(Object.entries({
proved: 'icons-material/check_circle_FILL0_wght400_GRAD0_opsz24-color.svg',
failed: 'icons-material/close_FILL0_wght400_GRAD0_opsz24-color.svg',
omitted: 'icons-material/editor_choice_FILL0_wght400_GRAD0_opsz24-color.svg',
missing: 'icons-material/check_box_outline_blank_FILL0_wght400_GRAD0_opsz24-color.svg',
pending: 'icons-material/help_FILL0_wght400_GRAD0_opsz24-color.svg',
progress: 'icons-material/more_horiz_FILL0_wght400_GRAD0_opsz24-color.svg',
}));
private icons = this.iconsMaterial;

constructor(
private context: vscode.ExtensionContext,
Expand Down Expand Up @@ -94,17 +114,26 @@ export class TlapsClient {
this.proofStateNames.forEach(name => {
const color = { 'id': 'tlaplus.tlaps.proofState.' + name };
const bgColor = name === 'failed' ? { backgroundColor: color } : undefined;
const decType = vscode.window.createTextEditorDecorationType({
const decTypeFirst = vscode.window.createTextEditorDecorationType({
overviewRulerColor: color,
overviewRulerLane: vscode.OverviewRulerLane.Right,
light: bgColor,
dark: bgColor,
isWholeLine: this.configWholeLine,
rangeBehavior: vscode.DecorationRangeBehavior.ClosedOpen,
gutterIconPath: this.context.asAbsolutePath(`resources/images/${this.icons.get(name)}`),
gutterIconSize: '100%',
});
const decTypeNext = vscode.window.createTextEditorDecorationType({
overviewRulerColor: color,
overviewRulerLane: vscode.OverviewRulerLane.Right,
light: bgColor,
dark: bgColor,
isWholeLine: this.configWholeLine,
rangeBehavior: vscode.DecorationRangeBehavior.ClosedOpen,
gutterIconPath: this.context.asAbsolutePath(`resources/images/tlaps-proof-state-${name}.svg`),
gutterIconSize: '85%'
});
this.proofStateDecorationTypes.set(name, decType);
this.proofStateDecorationTypes.set(name + '.first', decTypeFirst);
this.proofStateDecorationTypes.set(name + '.next', decTypeNext);
});
}

Expand Down Expand Up @@ -156,8 +185,8 @@ export class TlapsClient {
true,
);
this.context.subscriptions.push(this.client.onNotification(
'tlaplus/tlaps/proofStates',
this.proofStateNotifHandler.bind(this)
'tlaplus/tlaps/proofStepMarkers',
this.proofStepMarkersNotifHandler.bind(this)
));
this.context.subscriptions.push(this.client.onNotification(
'tlaplus/tlaps/currentProofStep',
Expand All @@ -177,20 +206,44 @@ export class TlapsClient {
return client.stop();
}

private proofStateNotifHandler(uri: DocumentUri, markers: ProofStateMarker[]) {
private proofStepMarkersNotifHandler(uri: DocumentUri, markers: ProofStepMarker[]) {
vscode.window.visibleTextEditors.forEach(editor => {
if (editor.document.uri.toString() === uri) {
const decorations = new Map(this.proofStateNames.map(name => [name, [] as vscode.DecorationOptions[]]));
const decorations = new Map<string, vscode.DecorationOptions[]>();
this.proofStateDecorationTypes.forEach((_, decTypeName) => {
decorations.set(decTypeName, [] as vscode.DecorationOptions[]);
});
markers.forEach(marker => {
decorations.get(marker.state)?.push(
{
range: marker.range,
hoverMessage: marker.hover,
}
);
if (marker.range.isSingleLine) {
decorations.get(marker.status + '.first')?.push(
{
range: marker.range,
hoverMessage: marker.hover,
}
);
} else {
const start = marker.range.start;
const midA = new vscode.Position(start.line, 1024);
const midB = new vscode.Position(start.line + 1, 0);
const end = marker.range.end;
const rangeFirst = new vscode.Range(start, midA);
const rangeNext = new vscode.Range(midB, end);
decorations.get(marker.status + '.first')?.push(
{
range: rangeFirst,
hoverMessage: marker.hover,
}
);
decorations.get(marker.status + '.next')?.push(
{
range: rangeNext,
hoverMessage: marker.hover,
}
);
}
});
this.proofStateDecorationTypes.forEach((decoratorType, proofStateName) => {
const decs = decorations.get(proofStateName);
this.proofStateDecorationTypes.forEach((decoratorType, decTypeName) => {
const decs = decorations.get(decTypeName);
editor.setDecorations(decoratorType, decs ? decs : []);
});
}
Expand Down
1 change: 1 addition & 0 deletions src/webview/tlapsCurrentProofObligationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class TlapsProofObligationView implements vscode.WebviewViewProvider {
} else {
content += `<p>Lines: ${loc.range.start.line + 1}-${loc.range.end.line + 1}</p>`;
}
content += `<p>Status: ${this.tlapsProofStepDetails.kind} / ${this.tlapsProofStepDetails.status}</p>`;
this.tlapsProofStepDetails.obligations.forEach(obl => {
content += `<div> Obligation on ${obl.range.start.line + 1}:${obl.range.start.character + 1}--${obl.range.end.line + 1}:${obl.range.end.character + 1}`;

Check warning on line 55 in src/webview/tlapsCurrentProofObligationView.ts

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

This line has a length of 168. Maximum allowed is 120

Check warning on line 55 in src/webview/tlapsCurrentProofObligationView.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

This line has a length of 168. Maximum allowed is 120

Check warning on line 55 in src/webview/tlapsCurrentProofObligationView.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This line has a length of 168. Maximum allowed is 120

Check warning on line 55 in src/webview/tlapsCurrentProofObligationView.ts

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

This line has a length of 168. Maximum allowed is 120

Check warning on line 55 in src/webview/tlapsCurrentProofObligationView.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

This line has a length of 168. Maximum allowed is 120

Check warning on line 55 in src/webview/tlapsCurrentProofObligationView.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This line has a length of 168. Maximum allowed is 120
if (obl.results) {
Expand Down

0 comments on commit ff06f3e

Please sign in to comment.