Skip to content

Commit

Permalink
Merge pull request #730 from rage/v3.1.0
Browse files Browse the repository at this point in the history
v3.1.0
  • Loading branch information
nygrenh authored Dec 18, 2024
2 parents 4434824 + a36b028 commit 8abb947
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [3.1.0] - 2024-12-17

- Fixed downloading old submissions for C# exercises
- Fixed error messages not displaying in some cases when running tests
- Bumped TMC-langs version to 0.37.0

## [3.0.6] - 2024-11-07

- Added a warning for a large number of open exercises
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Automatic build task starts the first time that the extension is launched from V

You can also build the extension by running `npm run webpack` or `npm run webpack:watch`.

## Updating dependencies

The tmc-langs version can be updated by changing the `TMC_LANGS_RUST_VERSION` variable in `config.js`.

## Testing

The tests use a mock backend which needs to be initialised. Run `cd backend && npm run setup` to do so. The tests can be run with `npm run test`. If you get a `Connection error: TypeError`, make sure the backend is running.
Expand Down
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const path = require("path");

const TMC_LANGS_RUST_VERSION = "0.36.4";
const TMC_LANGS_RUST_VERSION = "0.37.0";

const mockTmcLocalMooc = {
__TMC_BACKEND_URL__: JSON.stringify("http://localhost:4001"),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "test-my-code",
"displayName": "TestMyCode",
"version": "3.0.6",
"version": "3.1.0",
"description": "TestMyCode extension for Visual Studio Code",
"categories": [
"Education",
Expand Down
14 changes: 13 additions & 1 deletion shared/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export type ExtensionToWebview =
| {
type: "testError";
target: TargetPanel<ExerciseTestsPanel>;
error: Error;
error: BaseError;
}
| {
type: "pasteResult";
Expand Down Expand Up @@ -523,3 +523,15 @@ export type Broadcast<M, T extends PanelType> = Omit<Targeted<M, T>, "target">;
export function assertUnreachable(x: never): never {
throw new Error(`Unreachable ${JSON.stringify(x, null, 2)}`);
}

/*
* ======== errors ========
*/
export class BaseError extends Error {
public readonly name: string = "Base Error";
public details: string;
constructor(message?: string, details?: string) {
super(message);
this.details = details ?? "";
}
}
14 changes: 8 additions & 6 deletions src/api/tmc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
import { Logger } from "../utilities/logger";

import { SubmissionFeedback } from "./types";
import { BaseError } from "../shared/shared";

interface Options {
apiCacheLifetime?: string;
Expand All @@ -68,7 +69,7 @@ interface LangsProcessArgs {

interface LangsProcessRunner {
interrupt(): void;
result: Promise<Result<OutputData, Error>>;
result: Promise<Result<OutputData, BaseError>>;
}

interface ResponseCacheEntry {
Expand Down Expand Up @@ -261,7 +262,7 @@ export default class TMC {
exercisePath: string,
pythonExecutablePath?: string,
progressCallback?: (progressPct: number, message?: string) => void,
): [Promise<Result<RunResult, Error>>, () => void] {
): [Promise<Result<RunResult, BaseError>>, () => void] {
const env: { [key: string]: string } = {};
if (pythonExecutablePath) {
env.TMC_LANGS_PYTHON_EXEC = pythonExecutablePath;
Expand All @@ -279,6 +280,7 @@ export default class TMC {
.andThen((x) => this._checkLangsResponse(x, "test-result"))
.map((x) => x.data["output-data"]),
);

return [postResult, interrupt];
}

Expand Down Expand Up @@ -946,21 +948,21 @@ export default class TMC {
private _checkLangsResponse<T extends DataKind["output-data-kind"] | null>(
langsResponse: OutputData,
outputDataKind: T,
): Result<OutputData & { data: T extends null ? null : { "output-data-kind": T } }, Error> {
): Result<OutputData & { data: T extends null ? null : { "output-data-kind": T } }, BaseError> {
if (!dataMatchesKind(langsResponse, outputDataKind)) {
Logger.error("Unexpected TMC-langs response.", langsResponse);
return Err(new Error("Unexpected TMC-langs response."));
return Err(new BaseError("Unexpected TMC-langs response."));
}
if (langsResponse.status === "crashed") {
Logger.error("Langs process crashed.", langsResponse.message, langsResponse.data);
return Err(new RuntimeError("Langs process crashed."));
return Err(new BaseError("Langs process crashed."));
}
if (langsResponse.result !== "error") {
return Ok(langsResponse);
}
if (langsResponse.data?.["output-data-kind"] !== "error") {
Logger.error("Unexpected data in error response.", langsResponse);
return Err(new Error("Unexpected data in error response"));
return Err(new BaseError("Unexpected data in error response"));
}

// after this point, we know we have an error
Expand Down
22 changes: 19 additions & 3 deletions src/commands/downloadOldSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,30 @@ export async function downloadOldSubmission(
return;
}

const submitFirst = await dialog.confirmation(
const submitFirstSelection = await dialog.selectItem(
"Do you want to save the current state of the exercise by submitting it to TMC Server?",
["Submit to server", "submit"],
["Discard current state", "discard"],
);
if (submitFirst === undefined) {
if (submitFirstSelection === undefined) {
Logger.debug("Answer for submitting first not provided, returning early.");
return;
}

let submitFirst = submitFirstSelection === "submit";
// if we're submitting first, nothing will be lost anyway so it's probably okay to not annoy the user with a double confirm
if (!submitFirst) {
const confirm = await dialog.selectItem(
"Are you sure?",
["No, save the current exercise state", "submit"],
["Yes, discard current state", "discard"],
);
if (confirm === undefined) {
return;
}
submitFirst = confirm === "submit";
}

const editor = vscode.window.activeTextEditor;
const document = editor?.document.uri;

Expand All @@ -78,6 +94,6 @@ export async function downloadOldSubmission(
}

if (editor && document) {
vscode.commands.executeCommand<undefined>("vscode.open", document, editor.viewColumn);
await vscode.commands.executeCommand("workbench.action.files.revert", document);
}
}
10 changes: 2 additions & 8 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
class BaseError extends Error {
public readonly name: string = "Base Error";
public details: string;
constructor(message?: string, details?: string) {
super(message);
this.details = details ? details : "";
}
}
import { BaseError } from "./shared/shared";

export class ApiError extends BaseError {
public readonly name = "API Error";
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"typeRoots": ["./types", "./node_modules/@types"],
"sourceMap": true,
"rootDir": "src",
"rootDirs": ["src", "shared"],
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
Expand Down
25 changes: 19 additions & 6 deletions webview-ui/src/panels/ExerciseTests.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<script lang="ts">
import { derived } from "svelte/store";
import { ExerciseTestsPanel, TestResultData, assertUnreachable } from "../shared/shared";
import {
BaseError,
ExerciseTestsPanel,
TestResultData,
assertUnreachable,
} from "../shared/shared";
import { addMessageListener, loadable } from "../utilities/script";
import { vscode } from "../utilities/vscode";
import PasteHelpBox from "../components/PasteHelpBox.svelte";
Expand All @@ -9,7 +14,7 @@
export let panel: ExerciseTestsPanel;
const testError = loadable<Error>();
const testError = loadable<BaseError>();
const pasteResult = loadable<string>();
const pasteError = loadable<string>();
const testResults = loadable<TestResultData>();
Expand Down Expand Up @@ -43,9 +48,6 @@
switch (message.type) {
case "testResults": {
testResults.set(message.testResults);
const allSuccessful =
message.testResults.testResult.testResults.find((tr) => !tr.successful) ===
undefined;
break;
}
case "pasteResult": {
Expand Down Expand Up @@ -88,7 +90,7 @@
}
</script>

{#if !$tryingToRunTestsForExam}
{#if !$tryingToRunTestsForExam && !$testError}
{#if $testResults === undefined}
<h1>{panel.exercise.name}: Running tests</h1>
{:else if $testResults.testResult.status === "PASSED"}
Expand Down Expand Up @@ -170,6 +172,14 @@
{/if}
{:else}
<h1>{panel.course.title}: {panel.exercise.name}</h1>

{#if $testError}
<h2>Error while trying to run tests</h2>
<code>
{$testError.details}
</code>
{/if}

<div>You can submit your answer with the button below.</div>
<div class="exam-submission-button-container">
<vscode-button role="button" tabindex="0" on:click={submit} on:keypress={submit}>
Expand Down Expand Up @@ -198,4 +208,7 @@
margin-top: 1rem;
margin-bottom: 1rem;
}
code {
white-space: pre-wrap;
}
</style>
11 changes: 11 additions & 0 deletions webview-ui/src/panels/Welcome.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@
<!-- This list should generally contain only the last couple versions/months worth of updates -->

<div class="content_section">
<h3>3.1.0 - 2024-12-17</h3>
<h4>Fixed downloading old submissions for C# exercises</h4>
<p>
There was an issue in tmc-langs that caused the extension to fail to detect the
project directory within a submission after downloading it.
</p>
<h4>Fixed error messages not displaying in some cases when running tests</h4>
<p>
Certain types of errors were not being displayed when they occurred while running
tests.
</p>
<h3>3.0.6 - 2024-11-07</h3>
<h4>Added a warning for a large number of open exercises</h4>
<p>
Expand Down

0 comments on commit 8abb947

Please sign in to comment.