Merge pull request #1 from orus-dev/mvp-timer

Mvp timer
This commit is contained in:
Klesti Selimaj
2026-02-08 03:09:56 +01:00
committed by GitHub
16 changed files with 4526 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": [
"warn",
{
"selector": "import",
"format": [ "camelCase", "PascalCase" ]
}
],
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
+5
View File
@@ -0,0 +1,5 @@
import { defineConfig } from '@vscode/test-cli';
export default defineConfig({
files: 'out/test/**/*.test.js',
});
+8
View File
@@ -0,0 +1,8 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-vscode.extension-test-runner"
]
}
+21
View File
@@ -0,0 +1,21 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
+11
View File
@@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
+20
View File
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
+11
View File
@@ -0,0 +1,11 @@
.vscode/**
.vscode-test/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/.vscode-test.*
+9
View File
@@ -0,0 +1,9 @@
# Change Log
All notable changes to the "devrun-vscode" extension will be documented in this file.
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## [Unreleased]
- Initial release
+4098
View File
File diff suppressed because it is too large Load Diff
+61
View File
@@ -0,0 +1,61 @@
{
"name": "devrun-vscode",
"displayName": "devrun-vscode",
"description": "",
"version": "0.0.1",
"engines": {
"vscode": "^1.109.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onStartupFinished"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "devrun-vscode.startRun",
"title": "DevRun: Start a Run"
},
{
"command": "devrun-vscode.stopRun",
"title": "DevRun: Stop the Run"
},
{
"command": "devrun-vscode.startServer",
"title": "DevRun: Start the run server (for quick run starts)"
},
{
"command": "devrun-vscode.stopServer",
"title": "DevRun: Stop the run server (for quick run starts)"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "vscode-test"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/node": "18.x",
"@types/vscode": "^1.109.0",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@vscode/test-cli": "^0.0.4",
"@vscode/test-electron": "^2.3.8",
"eslint": "^8.56.0",
"typescript": "^5.3.3"
},
"dependencies": {
"@types/cors": "^2.8.19",
"@types/express": "^5.0.6",
"cors": "^2.8.6",
"express": "^5.2.1"
}
}
+13
View File
@@ -0,0 +1,13 @@
export interface LiveRunMove {
latency: number;
cursor: number;
changes?: {
from: number;
to: number;
insert: string;
};
}
export async function submitRun() {}
export async function addRunMoves() {}
+56
View File
@@ -0,0 +1,56 @@
import * as vscode from "vscode";
import { currentRun, startRun, stopRun } from "./run";
import { startServer, stopServer } from "./server";
export function activate(context: vscode.ExtensionContext) {
console.log("dev-run Activated");
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
10,
);
statusBarItem.text = "$(clock) No active run";
statusBarItem.show();
context.subscriptions.push(
vscode.commands.registerCommand(
"devrun-vscode.startRun",
async (problemId?: string) => startRun(statusBarItem, problemId),
),
);
context.subscriptions.push(
vscode.commands.registerCommand("devrun-vscode.stopRun", async () => {
if (!currentRun) return;
const isStop = await vscode.window.showWarningMessage(
"Are you sure you want to stop the run?",
{ modal: true },
"Yes",
"No",
);
if (isStop === "Yes") {
stopRun();
statusBarItem.text = "$(clock) No active run";
}
}),
);
context.subscriptions.push(
vscode.commands.registerCommand("devrun-vscode.startServer", async () =>
startServer(statusBarItem),
),
);
context.subscriptions.push(
vscode.commands.registerCommand("devrun-vscode.stopServer", async () =>
stopServer(statusBarItem),
),
);
}
export function deactivate() {
stopRun();
}
+63
View File
@@ -0,0 +1,63 @@
import * as vscode from "vscode";
export var currentRun: {
interval: NodeJS.Timeout;
problemId: string;
start: Date;
} | null = null;
export async function startRun(
statusBarItem: vscode.StatusBarItem,
problemId?: string,
) {
if (currentRun) {
vscode.window.showErrorMessage("You are already in a run");
return;
}
if (!problemId) {
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;
const mode = await vscode.window.showQuickPick(["any%", "100%"], {
placeHolder: "Select a mode",
canPickMany: false,
});
if (!mode) return;
let start = Date.now();
currentRun = {
problemId,
start: new Date(),
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),
};
}
export async function stopRun() {
if (currentRun) {
clearTimeout(currentRun.interval);
currentRun = null;
}
}
+60
View File
@@ -0,0 +1,60 @@
import * as vscode from "vscode";
import express from "express";
import * as http from "http";
import cors from "cors";
let server: http.Server | undefined;
const app = express();
app.use(
cors({
origin: (origin, callback) => {
// allow requests with no origin (e.g., direct curl)
if (
!origin ||
origin.includes("localhost") ||
origin.includes("127.0.0.1") ||
origin === "https://dev-run.netlify.app"
) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
}),
);
app.get("/start-run/:problemId", (req, res) => {
const { problemId } = req.params;
// trigger VS Code command
vscode.commands.executeCommand("devrun-vscode.startRun", problemId);
res.json({ ok: true, problemId });
});
export async function startServer(statusBarItem: vscode.StatusBarItem) {
if (server) return;
statusBarItem.text = "$(clock) Starting server";
server = app.listen(63780, "127.0.0.1", () => {
setTimeout(() => (statusBarItem.text = "$(clock) No active run"), 500);
});
}
export async function stopServer(statusBarItem: vscode.StatusBarItem) {
if (!server) {
return;
}
statusBarItem.text = "$(clock) Stopping server";
await new Promise<void>((resolve) => {
server!.close(() => resolve());
});
server = undefined;
setTimeout(() => (statusBarItem.text = "$(clock) No active run"), 500);
}
+17
View File
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "Node16",
"target": "ES2022",
"outDir": "out",
"lib": [
"ES2022"
],
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
}
}
+43
View File
@@ -0,0 +1,43 @@
# Welcome to your VS Code Extension
## What's in the folder
* This folder contains all of the files necessary for your extension.
* `package.json` - this is the manifest file in which you declare your extension and command.
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
## Get up and running straight away
* Press `F5` to open a new window with your extension loaded.
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
* Find output from your extension in the debug console.
## Make changes
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
## Explore the API
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
## Run tests
* Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner)
* Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered.
* Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A`
* See the output of the test result in the Test Results view.
* Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder.
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
* You can create folders inside the `test` folder to structure your tests any way you want.
## Go further
* [Follow UX guidelines](https://code.visualstudio.com/api/ux-guidelines/overview) to create extensions that seamlessly integrate with VS Code's native interface and patterns.
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace.
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).