From 9ab72c9ccbf093d1ffaea4810c52ca5c9bb66147 Mon Sep 17 00:00:00 2001 From: Atreya Bain Date: Sun, 20 Jul 2025 00:02:45 +0100 Subject: [PATCH] [add] task configs --- client/src/extension.ts | 5 +- client/src/task/CustomExecutionTerminal.ts | 68 ++++++++++++---------- package.json | 13 ++++- tsconfig.json | 3 +- 4 files changed, 53 insertions(+), 36 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index b391c95..7f4634c 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -4,7 +4,7 @@ * ------------------------------------------------------------------------------------------ */ import * as path from 'path'; -import { commands, tasks, workspace } from 'vscode'; +import { commands, tasks, workspace,window } from 'vscode'; import type { Disposable, ExtensionContext } from 'vscode'; import { LanguageClient, @@ -71,7 +71,8 @@ export function activate(context: ExtensionContext) { const workspaceRoot = (workspace.workspaceFolders && (workspace.workspaceFolders.length > 0)) ? workspace.workspaceFolders[0].uri.fsPath : undefined; - bfRunTaskProvider = tasks.registerTaskProvider(CustomExecutionTaskProvider.type, new CustomExecutionTaskProvider(workspaceRoot, undefined)); + + bfRunTaskProvider = tasks.registerTaskProvider(CustomExecutionTaskProvider.type, new CustomExecutionTaskProvider(workspaceRoot)); } export function deactivate(): Thenable | undefined { diff --git a/client/src/task/CustomExecutionTerminal.ts b/client/src/task/CustomExecutionTerminal.ts index a9b5990..5389268 100644 --- a/client/src/task/CustomExecutionTerminal.ts +++ b/client/src/task/CustomExecutionTerminal.ts @@ -1,45 +1,48 @@ -import path = require('node:path'); import * as vscode from 'vscode'; -interface BFRunTaskDefinition { - type: 'current'; +interface BFRunTaskDefinition extends vscode.TaskDefinition { file?: string; } export class CustomExecutionTaskProvider implements vscode.TaskProvider { - static type: string = 'BFExec'; + static type: string = 'bf-run'; tasks: vscode.Task[] | undefined; - constructor(private workspaceRoot: string|undefined,private currentDocument:string |undefined){ + constructor(private workspaceRoot: string|undefined){ } provideTasks(token?: vscode.CancellationToken): vscode.ProviderResult { if (this.tasks !== undefined) { return this.tasks; } - const types: BFRunTaskDefinition['type'][] = ['current']; - this.tasks = []; - types.forEach(e=> - this.tasks.push(this.getTaskFromDefinition(e)) - ); - - + this.tasks = [this.getTaskFromDefinition(undefined)]; + return this.tasks; } - getTaskFromDefinition(e: string): vscode.Task { + + + getTaskFromDefinition(fileName: string|undefined): vscode.Task { const definition:BFRunTaskDefinition = { - type: 'current', - file: undefined + type: CustomExecutionTaskProvider.type, + file: fileName }; return new vscode.Task(definition, vscode.TaskScope.Workspace,`bf: run: current file`,CustomExecutionTaskProvider.type, new vscode.CustomExecution(async ()=>{ - return new CustomBuildTaskTerminal(this.workspaceRoot); + return new CustomBuildTaskTerminal(definition.file); }) ); } resolveTask(_task: vscode.Task, token?: vscode.CancellationToken): vscode.ProviderResult { - return undefined; + const definition:BFRunTaskDefinition = _task.definition; + + const fileNameRecovered = definition.file; + const taskName = `bf: run: `+ ( fileNameRecovered??'current file'); + return new vscode.Task(definition,vscode.TaskScope.Workspace, taskName, CustomExecutionTaskProvider.type, + new vscode.CustomExecution(async ()=>{ + return new CustomBuildTaskTerminal(definition.file); + }) + ); } } @@ -50,34 +53,35 @@ class CustomBuildTaskTerminal implements vscode.Pseudoterminal { private closeEmitter = new vscode.EventEmitter(); - + private openDocument:vscode.TextDocument|undefined; onDidWrite: vscode.Event = this.writeEmitter.event; onDidClose?: vscode.Event = this.closeEmitter.event; - private fileWatcher: vscode.FileSystemWatcher | undefined; + handleInput(data: string): void { + this.writeEmitter.fire(`Echo`+data); + } - constructor(private workspaceRoot: string) { + + constructor(private fileName?:string) { } open(initialDimensions: vscode.TerminalDimensions | undefined): void { // At this point we can start using the terminal. - this.doBuild(); + + const openDocument = vscode.window.activeTextEditor.document; + this.openDocument = openDocument; + console.log(openDocument.languageId); + this.doExecution(); } close(): void { // The terminal has been closed. Shutdown the build. - if (this.fileWatcher) { - this.fileWatcher.dispose(); - } } - private async doBuild(): Promise { - return new Promise((resolve) => { - this.writeEmitter.fire('Starting build...\r\n'); - // Since we don't actually build anything in this example set a timeout instead. - this.writeEmitter.fire('Build complete.\r\n\r\n'); - this.closeEmitter.fire(0); - resolve(); - }); + private async doExecution(): Promise { + this.writeEmitter.fire('Build complete.\r\n\r\n'); + this.writeEmitter.fire('Requested build of '+this.fileName); + this.writeEmitter.fire(this.openDocument.getText()); + this.closeEmitter.fire(0); } } \ No newline at end of file diff --git a/package.json b/package.json index 498a163..39aecec 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,18 @@ "description": "Traces the communication between VS Code and the language server." } } - } + }, + "taskDefinitions": [ + { + "type": "bf-run", + "properties": { + "file":{ + "type":"string", + "description": "The BF file to be executed. Can be omitted to run current file" + } + } + } + ] }, "scripts": { "vscode:prepublish": "npm run compile", diff --git a/tsconfig.json b/tsconfig.json index 98bd0c3..652b34e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "lib": ["ES2019"], "outDir": "out", "rootDir": "src", - "sourceMap": true + "sourceMap": true, + "strict": true }, "include": [ "src"