Skip to content

Commit 4434824

Browse files
authored
Merge pull request #729 from rage/warn-open
Add warning for having too many exercises open
2 parents 0cfa964 + aaab0a5 commit 4434824

File tree

13 files changed

+1201
-8318
lines changed

13 files changed

+1201
-8318
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [3.0.6] - 2024-11-07
4+
5+
- Added a warning for a large number of open exercises
6+
37
## [3.0.5] - 2024-10-29
48

59
- Bumped TMC-langs version to 0.36.4

bin/package.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ npm run ci:all
1515
npm run webview:build
1616

1717
# create package
18-
npx vsce package ${PRERELEASE_ARG}
18+
BACKEND=production npx vsce package "${PRERELEASE_ARG}"

package-lock.json

Lines changed: 1136 additions & 8302 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "test-my-code",
33
"displayName": "TestMyCode",
4-
"version": "3.0.5",
4+
"version": "3.0.6",
55
"description": "TestMyCode extension for Visual Studio Code",
66
"categories": [
77
"Education",
@@ -444,11 +444,12 @@
444444
"trailingComma": "all"
445445
},
446446
"dependencies": {
447-
"del": "^7.1.0",
447+
"del": "^8.0.0",
448448
"fs-extra": "^11.2.0",
449449
"get-folder-size": "^5.0.0",
450450
"handlebars": "^4.7.8",
451451
"lodash": "^4.17.21",
452+
"systeminformation": "^5.23.5",
452453
"tree-kill": "^1.2.2",
453454
"ts-results": "^3.3.0",
454455
"typia": "^6.9.0",
@@ -463,8 +464,8 @@
463464
"@eslint/eslintrc": "^3.1.0",
464465
"@eslint/js": "^9.10.0",
465466
"@playwright/test": "1.46.1",
466-
"@types/chai": "^4.3.18",
467-
"@types/chai-as-promised": "^7.1.2",
467+
"@types/chai": "^4.3.3",
468+
"@types/chai-as-promised": "^7.1.8",
468469
"@types/du": "^1.0.3",
469470
"@types/fs-extra": "^11.0.4",
470471
"@types/lodash": "^4.17.7",

shared/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export type CourseDetailsPanel = {
7878
exerciseGroups?: Array<ExerciseGroup>;
7979
updateableExercises?: Array<number>;
8080
disabled?: boolean;
81-
exerciseStatuses: Record<number, ExerciseStatus>;
81+
exerciseStatuses?: Record<number, ExerciseStatus>;
8282
};
8383

8484
export type SelectOrganizationPanel = {

src/actions/webview.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export async function displayLocalCourseDetails(
156156
type: "CourseDetails",
157157
id: randomPanelId(),
158158
courseId: course.id,
159-
exerciseStatuses: {},
160159
};
161160
TmcPanel.renderMain(context.extensionUri, context, actionContext, panel);
162161

src/actions/workspace.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@
44
* -------------------------------------------------------------------------------------------------
55
*/
66

7+
import * as vscode from "vscode";
8+
79
import { compact } from "lodash";
810
import { Ok, Result } from "ts-results";
9-
1011
import { ExerciseStatus } from "../api/workspaceManager";
11-
import { TmcPanel } from "../panels/TmcPanel";
12-
import { ExtensionToWebview } from "../shared/shared";
12+
import { randomPanelId, TmcPanel } from "../panels/TmcPanel";
13+
import { CourseDetailsPanel, ExtensionToWebview } from "../shared/shared";
1314
import { Logger } from "../utilities";
14-
15+
import * as systeminformation from "systeminformation";
1516
import { ActionContext } from "./types";
1617

1718
/**
1819
* Opens given exercises, showing them in TMC workspace.
1920
* @param exerciseIdsToOpen Array of exercise IDs
2021
*/
2122
export async function openExercises(
23+
context: vscode.ExtensionContext,
2224
actionContext: ActionContext,
2325
exerciseIdsToOpen: number[],
2426
courseName: string,
2527
): Promise<Result<number[], Error>> {
2628
Logger.info("Opening exercises", exerciseIdsToOpen);
2729

28-
const { workspaceManager, userData, tmc } = actionContext;
30+
const { workspaceManager, userData, tmc, dialog } = actionContext;
2931

3032
const course = userData.getCourseByName(courseName);
3133
const courseExercises = new Map(course.exercises.map((x) => [x.id, x]));
@@ -51,6 +53,31 @@ export async function openExercises(
5153
return settingsResult;
5254
}
5355

56+
// check open exercise count and warn if it's too high
57+
const under8GbRam = (await systeminformation.mem()).available < 9_000_000_000;
58+
const weakThreshold = 50;
59+
const strongThreshold = 100;
60+
const warningThreshold = under8GbRam ? weakThreshold : strongThreshold;
61+
const openExercises = workspaceManager
62+
.getExercisesByCourseSlug(courseName)
63+
.filter((x) => x.status === ExerciseStatus.Open);
64+
if (openExercises.length > warningThreshold) {
65+
dialog.warningNotification(
66+
`You have over ${warningThreshold} exercises open, which may cause performance issues. You can close completed exercises from the TMC extension menu in the sidebar.`,
67+
[
68+
"Open course details",
69+
(): void => {
70+
const panel: CourseDetailsPanel = {
71+
id: randomPanelId(),
72+
type: "CourseDetails",
73+
courseId: course.id,
74+
};
75+
TmcPanel.renderMain(context.extensionUri, context, actionContext, panel);
76+
},
77+
],
78+
);
79+
}
80+
5481
TmcPanel.postMessage(
5582
...exerciseIdsToOpen.map<ExtensionToWebview>((id) => ({
5683
type: "exerciseStatusChange",

src/init/commands.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export function registerCommands(
7474
id: randomPanelId(),
7575
type: "CourseDetails",
7676
courseId,
77-
exerciseStatuses: {},
7877
});
7978
}
8079
}),

src/panels/TmcPanel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ export class TmcPanel {
497497
id: randomPanelId(),
498498
type: "CourseDetails",
499499
courseId: message.courseId,
500-
exerciseStatuses: {},
501500
},
502501
webview,
503502
);
@@ -616,6 +615,7 @@ export class TmcPanel {
616615

617616
// now, actually open the exercises
618617
const result = await openExercises(
618+
extensionContext,
619619
actionContext,
620620
message.ids,
621621
message.courseName,
@@ -655,7 +655,6 @@ export class TmcPanel {
655655
id: randomPanelId(),
656656
type: "CourseDetails",
657657
courseId: courseId,
658-
exerciseStatuses: {},
659658
},
660659
webview,
661660
);

webpack.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ const config = () => {
2020
return mockTmcLocalMooc;
2121
case "mockBackend":
2222
return mockBackend;
23+
case "production":
24+
return productionApi;
2325
default:
26+
console.warn("No backend set, defaulting to `production`");
2427
return productionApi;
2528
}
2629
})();
@@ -49,6 +52,8 @@ const config = () => {
4952
extensions: [".ts", ".js"],
5053
alias: {
5154
handlebars: "handlebars/dist/handlebars.min.js",
55+
// systeminformation issue https://github.com/sebhildebrandt/systeminformation/issues/701
56+
"osx-temperature-sensor": false,
5257
},
5358
// solves an issue with ts-loader with ttypescript
5459
// using the incorrect import paths for .d.ts files:

0 commit comments

Comments
 (0)