diff --git a/package.json b/package.json index 0b348a2..77f1073 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,19 @@ "categories": [ "Other" ], - "activationEvents": [], + "activationEvents": [ + "onStartupFinished" + ], "main": "./out/extension.js", "contributes": { "commands": [ { - "command": "devrun-vscode.helloWorld", - "title": "Hello World" + "command": "devrun-vscode.startRun", + "title": "DevRun: Start a Run" + }, + { + "command": "devrun-vscode.startServer", + "title": "DevRun: Start the run server (for quick run starts)" } ] }, diff --git a/src/extension.ts b/src/extension.ts index baec7cf..3bb95b2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,26 +1,39 @@ -// The module 'vscode' contains the VS Code extensibility API -// Import the module and reference it with the alias vscode in your code below -import * as vscode from 'vscode'; +import * as vscode from "vscode"; +import { startRun } from "./startRun"; -// This method is called when your extension is activated -// Your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { + console.log("dev-run Activated"); - // Use the console to output diagnostic information (console.log) and errors (console.error) - // This line of code will only be executed once when your extension is activated - console.log('Congratulations, your extension "devrun-vscode" is now active!'); + const statusBarItem = vscode.window.createStatusBarItem( + vscode.StatusBarAlignment.Left, + 10, + ); - // The command has been defined in the package.json file - // Now provide the implementation of the command with registerCommand - // The commandId parameter must match the command field in package.json - let disposable = vscode.commands.registerCommand('devrun-vscode.helloWorld', () => { - // The code you place here will be executed every time your command is executed - // Display a message box to the user - vscode.window.showInformationMessage('Hello World from devrun-vscode!'); - }); + statusBarItem.text = "$(clock) No run yet"; + statusBarItem.show(); - context.subscriptions.push(disposable); + let disposable = vscode.commands.registerCommand( + "devrun-vscode.startRun", + async () => { + const problemId = await vscode.window.showInputBox({ + prompt: "Enter a valid problem ID", + placeHolder: "my-problem", + validateInput: (text) => { + return text.match(/^[a-zA-Z0-9-]+$/) + ? null + : "Must only contain '-' and alphanumeric characters"; + }, + }); + + if (!problemId) { + return; + } + + startRun(statusBarItem, problemId); + }, + ); + + context.subscriptions.push(disposable); } -// This method is called when your extension is deactivated export function deactivate() {} diff --git a/src/startRun.ts b/src/startRun.ts new file mode 100644 index 0000000..8d42938 --- /dev/null +++ b/src/startRun.ts @@ -0,0 +1,25 @@ +import * as vscode from "vscode"; + +export async function startRun( + statusBarItem: vscode.StatusBarItem, + problemId: string, +) { + const mode = await vscode.window.showQuickPick(["any%", "100%"], { + placeHolder: "Select a mode", + canPickMany: false, + }); + + let start = Date.now(); + + const interval = setInterval(() => { + const elapsed = Date.now() - start; + + const minutes = Math.floor(elapsed / 60000); + const seconds = Math.floor((elapsed % 60000) / 1000); + const hundredths = Math.floor((elapsed % 1000) / 10); + + statusBarItem.text = `$(clock) ${minutes}:${seconds.toString().padStart(2, "0")}.${hundredths + .toString() + .padStart(2, "0")}`; + }, 50); +}