[add] task configs

This commit is contained in:
2025-07-20 00:02:45 +01:00
parent 6f5357ea5c
commit 9ab72c9ccb
4 changed files with 53 additions and 36 deletions

View File

@@ -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<void> | undefined {

View File

@@ -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<vscode.Task[]> {
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<vscode.Task> {
return undefined;
const definition:BFRunTaskDefinition = <any>_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<number>();
private openDocument:vscode.TextDocument|undefined;
onDidWrite: vscode.Event<string> = this.writeEmitter.event;
onDidClose?: vscode.Event<number> = 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<void> {
return new Promise<void>((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<void> {
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);
}
}

View File

@@ -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",

View File

@@ -5,7 +5,8 @@
"lib": ["ES2019"],
"outDir": "out",
"rootDir": "src",
"sourceMap": true
"sourceMap": true,
"strict": true
},
"include": [
"src"