Online repo for problems

This commit is contained in:
2025-08-06 23:45:41 +02:00
parent 663c085f34
commit 77909c5684
3 changed files with 60 additions and 27 deletions
+3
View File
@@ -1,2 +1,5 @@
# extension # extension
The VSCode extension for SpeedCode The VSCode extension for SpeedCode
All the problems and their test cases [here](https://github.com/SpeedCodeHQ/problems)
+55 -27
View File
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import testCode, { TestResult } from "./tester"; import testCode, { TestCase } from "./tester";
import * as utils from "./utils"; import * as utils from "./utils";
import { MyTreeDataProvider } from "./resultViewer"; import { MyTreeDataProvider } from "./resultViewer";
@@ -47,6 +47,8 @@ export function activate(context: vscode.ExtensionContext) {
| undefined | undefined
| { | {
path: string; path: string;
name: string;
testCases: TestCase[];
elapsed: number; elapsed: number;
timer: NodeJS.Timeout; timer: NodeJS.Timeout;
}; };
@@ -68,11 +70,7 @@ export function activate(context: vscode.ExtensionContext) {
try { try {
const [isValid, res] = testCode( const [isValid, res] = testCode(
fs.readFileSync(run.path).toString(), fs.readFileSync(run.path).toString(),
[ run.testCases
{ input: ["racecar"], expected: true },
{ input: ["hello"], expected: false },
{ input: ["madam"], expected: true },
]
); );
if (isValid) { if (isValid) {
@@ -96,29 +94,59 @@ export function activate(context: vscode.ExtensionContext) {
); );
context.subscriptions.push( context.subscriptions.push(
vscode.commands.registerCommand("speed-code.startSpeedRun", () => { vscode.commands.registerCommand("speed-code.startSpeedRun", async () => {
treeDataProvider.testSummary = undefined; const quickPick = vscode.window.createQuickPick();
treeDataProvider.testResults = []; quickPick.placeholder = "Type to search";
treeDataProvider.blunders = []; quickPick.matchOnDescription = true;
updateTreeMessage(); quickPick.items = utils.problems.map((label) => ({ label }));
const runFilePath = path.join(speedCodePath, "isPalindrome.js"); quickPick.onDidChangeValue((value) => {
fs.writeFileSync(runFilePath, ""); quickPick.items = utils.problems
openAndFocusFile(runFilePath); .filter((prob) => prob.toLowerCase().includes(value.toLowerCase()))
.map((label) => ({ label }));
});
quickPick.onDidAccept(async () => {
const selection = quickPick.selectedItems[0];
if (selection) {
const name = selection.label.toLowerCase();
treeDataProvider.testSummary = undefined;
treeDataProvider.testResults = [];
treeDataProvider.blunders = [];
updateTreeMessage();
const runFilePath = path.join(speedCodePath, name + ".js");
fs.writeFileSync(runFilePath, "");
openAndFocusFile(runFilePath);
const startTime = Date.now(); const response = await fetch(
run = { `https://raw.githubusercontent.com/SpeedCodeHQ/problems/refs/heads/main/${name}.json`
path: runFilePath, );
elapsed: 0,
timer: setInterval(() => {
if (!run) return;
const currentTime = Date.now();
run.elapsed = (currentTime - startTime) / 1000;
statusBarItem.text = utils.format(run.elapsed);
statusBarItem.color = "#fff";
}, 10),
};
vscode.window.showInformationMessage("Speedrun Started!"); if (!response.ok) {
vscode.window.showErrorMessage(
`Failed to fetch test cases for ${name}: ${response.statusText}`
);
return;
}
const startTime = Date.now();
run = {
path: runFilePath,
elapsed: 0,
name,
testCases: (await response.json()) as TestCase[],
timer: setInterval(() => {
if (!run) return;
const currentTime = Date.now();
run.elapsed = (currentTime - startTime) / 1000;
statusBarItem.text = utils.format(run.elapsed);
statusBarItem.color = "#fff";
}, 10),
};
vscode.window.showInformationMessage("Speedrun Started!");
}
quickPick.hide();
});
quickPick.show();
}), }),
statusBarItem statusBarItem
); );
+2
View File
@@ -1,3 +1,5 @@
export const problems = ["Palindrome"];
export function format(timeSeconds: number): string { export function format(timeSeconds: number): string {
if (timeSeconds > 86400) { if (timeSeconds > 86400) {
const days = Math.floor(timeSeconds / 86400); const days = Math.floor(timeSeconds / 86400);