Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/show-spec'
Browse files Browse the repository at this point in the history
  • Loading branch information
mullr committed Aug 12, 2024
2 parents 789041e + c42ecc5 commit 99073b3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
},
{
"command": "auxon.specs.showVersion",
"when": "view == auxon.specs && viewItem == specVersion && !listMultiSelection && false",
"when": "view == auxon.specs && viewItem == specVersion && !listMultiSelection",
"group": "1_context@1"
},
{
Expand Down
5 changes: 4 additions & 1 deletion vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export async function activate(context: vscode.ExtensionContext) {
eventsProvider.setSelectedTimelines(selection);
});

new specs.SpecsTreeDataProvider(apiClient, specCoverageProvider, wss, context);
const specsProvider = new specs.SpecsTreeDataProvider(apiClient, specCoverageProvider, wss, context);
// Pre-load specs provided so that the deviant panel can reveal spec tree items without having the user
// explicitly load the specs panel first
const _ignored = specsProvider.getChildren();

new mutators.MutatorsTreeDataProvider(apiClient, wss, context);
new mutations.MutationsTreeDataProvider(apiClient, wss, context);
Expand Down
23 changes: 23 additions & 0 deletions vscode/src/specFileCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,26 @@ export function runConformEvalCommand(args: SpecEvalCommandArgs): Thenable<vscod

return vscode.tasks.executeTask(task);
}

export async function inspectSpecSpeqtr(specNameOrVersion: string): Promise<string | undefined> {
const conform = config.toolPath("conform");

try {
const res = await execFile(
conform,
["spec", "inspect", "--with-speqtr", "--format", "json", specNameOrVersion],
{
encoding: "utf8",
}
);
const data = JSON.parse(res.stdout);
return data.target_version.content.speqtr;
} catch (e: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
if (Object.prototype.hasOwnProperty.call(e, "stderr")) {
vscode.window.showErrorMessage(e.stderr.trim());
} else {
vscode.window.showErrorMessage(e.toString());
}
return undefined;
}
}
25 changes: 25 additions & 0 deletions vscode/src/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export class SpecsTreeDataProvider implements vscode.TreeDataProvider<SpecsTreeI
vscode.commands.registerCommand("auxon.specs.evalVersion.dryRun", (item: SpecVersionTreeItemData) =>
this.evalVersionDryRun(item)
),
vscode.commands.registerCommand("auxon.specs.showLatest", (item: NamedSpecTreeItemData) =>
this.showLatest(item)
),
vscode.commands.registerCommand("auxon.specs.showVersion", (item: SpecVersionTreeItemData) =>
this.showVersion(item)
),
vscode.commands.registerCommand("auxon.specs.delete", (item: NamedSpecTreeItemData) =>
this.deleteSpec(item)
),
Expand Down Expand Up @@ -203,6 +209,14 @@ export class SpecsTreeDataProvider implements vscode.TreeDataProvider<SpecsTreeI
this.conformEval({ spec_version: spec.specVersion, dry_run: true });
}

async showLatest(spec: NamedSpecTreeItemData) {
await this.showSpec(spec.specMetadata.name);
}

async showVersion(spec: SpecVersionTreeItemData) {
await this.showSpec(spec.specVersion);
}

async deleteSpec(spec: NamedSpecTreeItemData) {
const answer = await vscode.window.showInformationMessage(
`Really delete spec '${spec.specMetadata.name}'? This will delete all spec versions and stored results.`,
Expand Down Expand Up @@ -309,6 +323,17 @@ export class SpecsTreeDataProvider implements vscode.TreeDataProvider<SpecsTreeI
conformEval(args: specFileCommands.SpecEvalCommandArgs) {
specFileCommands.runConformEvalCommand(args);
}

async showSpec(specNameOrVersion: string) {
const speqtr = await specFileCommands.inspectSpecSpeqtr(specNameOrVersion);
if (speqtr) {
const doc = await vscode.workspace.openTextDocument({
language: "speqtr",
content: speqtr,
});
await vscode.window.showTextDocument(doc);
}
}
}

// This is the base of all the tree item data classes
Expand Down

0 comments on commit 99073b3

Please sign in to comment.