Working example
This commit is contained in:
+25
-13
@@ -1,12 +1,17 @@
|
|||||||
import * as vscode from 'vscode';
|
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 testCode from './tester';
|
import testCode from './tester';
|
||||||
|
|
||||||
let resetTimer = () => {}
|
let resetTimer = () => {}
|
||||||
|
|
||||||
const speedCodePath = path.join(os.homedir(), ".speed-code/");
|
const speedCodePath = path.join(os.homedir(), ".speed-code/");
|
||||||
|
|
||||||
|
if (!fs.existsSync(speedCodePath)) {
|
||||||
|
fs.mkdirSync(speedCodePath);
|
||||||
|
}
|
||||||
|
|
||||||
export async function openAndFocusFile(filePath: string) {
|
export async function openAndFocusFile(filePath: string) {
|
||||||
const document = await vscode.workspace.openTextDocument(filePath);
|
const document = await vscode.workspace.openTextDocument(filePath);
|
||||||
await vscode.window.showTextDocument(document, { preview: false, preserveFocus: false });
|
await vscode.window.showTextDocument(document, { preview: false, preserveFocus: false });
|
||||||
@@ -19,19 +24,6 @@ function isPalindrome(s) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
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);
|
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
|
||||||
statusBarItem.tooltip = 'Speedrun timer';
|
statusBarItem.tooltip = 'Speedrun timer';
|
||||||
statusBarItem.text = "No active Speedrun";
|
statusBarItem.text = "No active Speedrun";
|
||||||
@@ -49,6 +41,26 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
resetTimer();
|
resetTimer();
|
||||||
|
|
||||||
context.subscriptions.push(vscode.commands.registerCommand('speed-code.startSpeedRun', () => {
|
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();
|
const startTime = Date.now();
|
||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
const currentTime = Date.now();
|
const currentTime = Date.now();
|
||||||
|
|||||||
+1
-1
@@ -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];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user