Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to changes in the lsp server. #322

Merged
merged 10 commits into from
Jan 31, 2024
Prev Previous commit
Next Next commit
Icons and other improvements on TLAPS.
Signed-off-by: Karolis Petrauskas <k.petrauskas@gmail.com>
  • Loading branch information
kape1395 committed Jan 26, 2024
commit ff06f3e2df9f8f4cb6da9e07c4c14be0ef5b6c18
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 @@ -8,16 +8,19 @@
// Also show WebviewView to show a custom content in a sidebar.
//
// TODO: Auto re-read proof state for the visible range:
// - 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 @@
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 @@
'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 @@
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 @@
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 @@
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,8 +50,9 @@
} 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) {
content += '<ul>';
obl.results.forEach(r => {
Expand Down
Loading