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
The VSCode extension for SpeedCode
All the problems and their test cases [here](https://github.com/SpeedCodeHQ/problems)
+36 -8
View File
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
import os from "os";
import path from "path";
import fs from "fs";
import testCode, { TestResult } from "./tester";
import testCode, { TestCase } from "./tester";
import * as utils from "./utils";
import { MyTreeDataProvider } from "./resultViewer";
@@ -47,6 +47,8 @@ export function activate(context: vscode.ExtensionContext) {
| undefined
| {
path: string;
name: string;
testCases: TestCase[];
elapsed: number;
timer: NodeJS.Timeout;
};
@@ -68,11 +70,7 @@ export function activate(context: vscode.ExtensionContext) {
try {
const [isValid, res] = testCode(
fs.readFileSync(run.path).toString(),
[
{ input: ["racecar"], expected: true },
{ input: ["hello"], expected: false },
{ input: ["madam"], expected: true },
]
run.testCases
);
if (isValid) {
@@ -96,19 +94,45 @@ export function activate(context: vscode.ExtensionContext) {
);
context.subscriptions.push(
vscode.commands.registerCommand("speed-code.startSpeedRun", () => {
vscode.commands.registerCommand("speed-code.startSpeedRun", async () => {
const quickPick = vscode.window.createQuickPick();
quickPick.placeholder = "Type to search";
quickPick.matchOnDescription = true;
quickPick.items = utils.problems.map((label) => ({ label }));
quickPick.onDidChangeValue((value) => {
quickPick.items = utils.problems
.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, "isPalindrome.js");
const runFilePath = path.join(speedCodePath, name + ".js");
fs.writeFileSync(runFilePath, "");
openAndFocusFile(runFilePath);
const response = await fetch(
`https://raw.githubusercontent.com/SpeedCodeHQ/problems/refs/heads/main/${name}.json`
);
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();
@@ -119,6 +143,10 @@ export function activate(context: vscode.ExtensionContext) {
};
vscode.window.showInformationMessage("Speedrun Started!");
}
quickPick.hide();
});
quickPick.show();
}),
statusBarItem
);
+2
View File
@@ -1,3 +1,5 @@
export const problems = ["Palindrome"];
export function format(timeSeconds: number): string {
if (timeSeconds > 86400) {
const days = Math.floor(timeSeconds / 86400);