Working example

This commit is contained in:
2025-08-06 13:35:14 -05:00
parent 9d72732cfd
commit 7f0aa63843
2 changed files with 28 additions and 16 deletions
+25 -13
View File
@@ -1,12 +1,17 @@
import * as vscode from 'vscode';
import os from 'os';
import path from 'path';
import fs from 'fs';
import testCode from './tester';
let resetTimer = () => {}
const speedCodePath = path.join(os.homedir(), ".speed-code/");
if (!fs.existsSync(speedCodePath)) {
fs.mkdirSync(speedCodePath);
}
export async function openAndFocusFile(filePath: string) {
const document = await vscode.workspace.openTextDocument(filePath);
await vscode.window.showTextDocument(document, { preview: false, preserveFocus: false });
@@ -19,19 +24,6 @@ function isPalindrome(s) {
`;
export function activate(context: vscode.ExtensionContext) {
const [isValid, res] = testCode(userCode, [{
input: ["racecar"],
expected: true
},{
input: ["hello"],
expected: false
},{
input: ["madam"],
expected: true
},]);
vscode.window.showInformationMessage('Speedrun info: ' + JSON.stringify(res));
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
statusBarItem.tooltip = 'Speedrun timer';
statusBarItem.text = "No active Speedrun";
@@ -49,6 +41,26 @@ export function activate(context: vscode.ExtensionContext) {
resetTimer();
context.subscriptions.push(vscode.commands.registerCommand('speed-code.startSpeedRun', () => {
const runFilePath = path.join(speedCodePath, 'isPalindrome.js');
fs.writeFileSync(runFilePath, '');
openAndFocusFile(runFilePath);
setTimeout(() => {
const [isValid, res] = testCode(fs.readFileSync(runFilePath).toString(), [{
input: ["racecar"],
expected: true
},{
input: ["hello"],
expected: false
},{
input: ["madam"],
expected: true
},]);
vscode.window.showInformationMessage('Speedrun info: ' + JSON.stringify(res) + 'Summary: ' + isValid);
}, 2000);
const startTime = Date.now();
timer = setInterval(() => {
const currentTime = Date.now();
+1 -1
View File
@@ -38,5 +38,5 @@ export default function testCode(code: string, testCases: TestCase[]): [boolean,
}
});
return [tests.every(t => t), tests];
return [tests.every(t => t.valid), tests];
}