Online repo for problems
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
+36
-8
@@ -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,19 +94,45 @@ 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 () => {
|
||||||
|
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.testSummary = undefined;
|
||||||
treeDataProvider.testResults = [];
|
treeDataProvider.testResults = [];
|
||||||
treeDataProvider.blunders = [];
|
treeDataProvider.blunders = [];
|
||||||
updateTreeMessage();
|
updateTreeMessage();
|
||||||
const runFilePath = path.join(speedCodePath, "isPalindrome.js");
|
const runFilePath = path.join(speedCodePath, name + ".js");
|
||||||
fs.writeFileSync(runFilePath, "");
|
fs.writeFileSync(runFilePath, "");
|
||||||
openAndFocusFile(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();
|
const startTime = Date.now();
|
||||||
run = {
|
run = {
|
||||||
path: runFilePath,
|
path: runFilePath,
|
||||||
elapsed: 0,
|
elapsed: 0,
|
||||||
|
name,
|
||||||
|
testCases: (await response.json()) as TestCase[],
|
||||||
timer: setInterval(() => {
|
timer: setInterval(() => {
|
||||||
if (!run) return;
|
if (!run) return;
|
||||||
const currentTime = Date.now();
|
const currentTime = Date.now();
|
||||||
@@ -119,6 +143,10 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vscode.window.showInformationMessage("Speedrun Started!");
|
vscode.window.showInformationMessage("Speedrun Started!");
|
||||||
|
}
|
||||||
|
quickPick.hide();
|
||||||
|
});
|
||||||
|
quickPick.show();
|
||||||
}),
|
}),
|
||||||
statusBarItem
|
statusBarItem
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user