Skip to content

Commit

Permalink
Merge pull request #729 from rage/warn-open
Browse files Browse the repository at this point in the history
Add warning for having too many exercises open
  • Loading branch information
nygrenh authored Nov 7, 2024
2 parents 0cfa964 + aaab0a5 commit 4434824
Show file tree
Hide file tree
Showing 13 changed files with 1,201 additions and 8,318 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [3.0.6] - 2024-11-07

- Added a warning for a large number of open exercises

## [3.0.5] - 2024-10-29

- Bumped TMC-langs version to 0.36.4
Expand Down
2 changes: 1 addition & 1 deletion bin/package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ npm run ci:all
npm run webview:build

# create package
npx vsce package ${PRERELEASE_ARG}
BACKEND=production npx vsce package "${PRERELEASE_ARG}"
9,438 changes: 1,136 additions & 8,302 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions 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.5",
"version": "3.0.6",
"description": "TestMyCode extension for Visual Studio Code",
"categories": [
"Education",
Expand Down Expand Up @@ -444,11 +444,12 @@
"trailingComma": "all"
},
"dependencies": {
"del": "^7.1.0",
"del": "^8.0.0",
"fs-extra": "^11.2.0",
"get-folder-size": "^5.0.0",
"handlebars": "^4.7.8",
"lodash": "^4.17.21",
"systeminformation": "^5.23.5",
"tree-kill": "^1.2.2",
"ts-results": "^3.3.0",
"typia": "^6.9.0",
Expand All @@ -463,8 +464,8 @@
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.10.0",
"@playwright/test": "1.46.1",
"@types/chai": "^4.3.18",
"@types/chai-as-promised": "^7.1.2",
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.8",
"@types/du": "^1.0.3",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.7",
Expand Down
2 changes: 1 addition & 1 deletion shared/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type CourseDetailsPanel = {
exerciseGroups?: Array<ExerciseGroup>;
updateableExercises?: Array<number>;
disabled?: boolean;
exerciseStatuses: Record<number, ExerciseStatus>;
exerciseStatuses?: Record<number, ExerciseStatus>;
};

export type SelectOrganizationPanel = {
Expand Down
1 change: 0 additions & 1 deletion src/actions/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export async function displayLocalCourseDetails(
type: "CourseDetails",
id: randomPanelId(),
courseId: course.id,
exerciseStatuses: {},
};
TmcPanel.renderMain(context.extensionUri, context, actionContext, panel);

Expand Down
37 changes: 32 additions & 5 deletions src/actions/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
* -------------------------------------------------------------------------------------------------
*/

import * as vscode from "vscode";

import { compact } from "lodash";
import { Ok, Result } from "ts-results";

import { ExerciseStatus } from "../api/workspaceManager";
import { TmcPanel } from "../panels/TmcPanel";
import { ExtensionToWebview } from "../shared/shared";
import { randomPanelId, TmcPanel } from "../panels/TmcPanel";
import { CourseDetailsPanel, ExtensionToWebview } from "../shared/shared";
import { Logger } from "../utilities";

import * as systeminformation from "systeminformation";
import { ActionContext } from "./types";

/**
* Opens given exercises, showing them in TMC workspace.
* @param exerciseIdsToOpen Array of exercise IDs
*/
export async function openExercises(
context: vscode.ExtensionContext,
actionContext: ActionContext,
exerciseIdsToOpen: number[],
courseName: string,
): Promise<Result<number[], Error>> {
Logger.info("Opening exercises", exerciseIdsToOpen);

const { workspaceManager, userData, tmc } = actionContext;
const { workspaceManager, userData, tmc, dialog } = actionContext;

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

// check open exercise count and warn if it's too high
const under8GbRam = (await systeminformation.mem()).available < 9_000_000_000;
const weakThreshold = 50;
const strongThreshold = 100;
const warningThreshold = under8GbRam ? weakThreshold : strongThreshold;
const openExercises = workspaceManager
.getExercisesByCourseSlug(courseName)
.filter((x) => x.status === ExerciseStatus.Open);
if (openExercises.length > warningThreshold) {
dialog.warningNotification(
`You have over ${warningThreshold} exercises open, which may cause performance issues. You can close completed exercises from the TMC extension menu in the sidebar.`,
[
"Open course details",
(): void => {
const panel: CourseDetailsPanel = {
id: randomPanelId(),
type: "CourseDetails",
courseId: course.id,
};
TmcPanel.renderMain(context.extensionUri, context, actionContext, panel);
},
],
);
}

TmcPanel.postMessage(
...exerciseIdsToOpen.map<ExtensionToWebview>((id) => ({
type: "exerciseStatusChange",
Expand Down
1 change: 0 additions & 1 deletion src/init/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export function registerCommands(
id: randomPanelId(),
type: "CourseDetails",
courseId,
exerciseStatuses: {},
});
}
}),
Expand Down
3 changes: 1 addition & 2 deletions src/panels/TmcPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ export class TmcPanel {
id: randomPanelId(),
type: "CourseDetails",
courseId: message.courseId,
exerciseStatuses: {},
},
webview,
);
Expand Down Expand Up @@ -616,6 +615,7 @@ export class TmcPanel {

// now, actually open the exercises
const result = await openExercises(
extensionContext,
actionContext,
message.ids,
message.courseName,
Expand Down Expand Up @@ -655,7 +655,6 @@ export class TmcPanel {
id: randomPanelId(),
type: "CourseDetails",
courseId: courseId,
exerciseStatuses: {},
},
webview,
);
Expand Down
5 changes: 5 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const config = () => {
return mockTmcLocalMooc;
case "mockBackend":
return mockBackend;
case "production":
return productionApi;
default:
console.warn("No backend set, defaulting to `production`");
return productionApi;
}
})();
Expand Down Expand Up @@ -49,6 +52,8 @@ const config = () => {
extensions: [".ts", ".js"],
alias: {
handlebars: "handlebars/dist/handlebars.min.js",
// systeminformation issue https://github.com/sebhildebrandt/systeminformation/issues/701
"osx-temperature-sensor": false,
},
// solves an issue with ts-loader with ttypescript
// using the incorrect import paths for .d.ts files:
Expand Down
2 changes: 2 additions & 0 deletions webview-ui/src/components/Card.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<script lang="ts"></script>

<div class="card">
<slot />
</div>
Expand Down
8 changes: 7 additions & 1 deletion webview-ui/src/panels/CourseDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
break;
}
case "exerciseStatusChange": {
if (panel.exerciseStatuses === undefined) {
panel.exerciseStatuses = {};
}
panel.exerciseStatuses[message.exerciseId] = message.status;
savePanelState(panel);
break;
Expand All @@ -58,6 +61,9 @@
break;
}
case "exerciseStatusChange": {
if (panel.exerciseStatuses === undefined) {
panel.exerciseStatuses = {};
}
panel.exerciseStatuses[message.exerciseId] = message.status;
savePanelState(panel);
break;
Expand Down Expand Up @@ -237,7 +243,7 @@
<div class="exercise-part">
<ExercisePart
{exerciseGroup}
exerciseStatuses={panel.exerciseStatuses}
exerciseStatuses={panel.exerciseStatuses ?? {}}
bind:checkedExercises={$checkedExercises}
onDownloadAll={(exercises) =>
panel.course && downloadExercises(panel.course, exercises)}
Expand Down
7 changes: 7 additions & 0 deletions webview-ui/src/panels/Welcome.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@
<!-- This list should generally contain only the last couple versions/months worth of updates -->

<div class="content_section">
<h3>3.0.6 - 2024-11-07</h3>
<h4>Added a warning for a large number of open exercises</h4>
<p>
A high amount of open exercises may cause performance issues. Since it's usually not
necessary to have so many exercises open, the warning recommends the user close some
of them.
</p>
<h3>3.0.5 - 2024-10-29</h3>
<h4>Fixed file locking issues</h4>
<p>
Expand Down

0 comments on commit 4434824

Please sign in to comment.