-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsubmitExercise.ts
34 lines (29 loc) · 1.07 KB
/
submitExercise.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as vscode from "vscode";
import * as actions from "../actions";
import { ActionContext } from "../actions/types";
import { BottleneckError } from "../errors";
import { Logger } from "../utilities";
export async function submitExercise(
context: vscode.ExtensionContext,
actionContext: ActionContext,
resource: vscode.Uri | undefined,
): Promise<void> {
const { dialog, workspaceManager } = actionContext;
Logger.info("Submitting exercise");
const exercise = resource
? workspaceManager.getExerciseByPath(resource)
: workspaceManager.activeExercise;
if (!exercise) {
dialog.errorNotification("Currently open editor is not part of a TMC exercise.");
return;
}
const result = await actions.submitExercise(context, actionContext, exercise);
if (result.err) {
if (result.val instanceof BottleneckError) {
Logger.warn("Submission was cancelled:", result.val);
return;
}
dialog.errorNotification("Exercise submission failed.", result.val);
return;
}
}