2025-07-19 14:39:44 +01:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
interface BFRunTaskDefinition extends vscode.TaskDefinition {
|
2025-07-19 18:50:14 +01:00
|
|
|
file?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CustomExecutionTaskProvider implements vscode.TaskProvider {
|
2025-07-20 00:02:45 +01:00
|
|
|
static type: string = 'bf-run';
|
2025-07-19 18:50:14 +01:00
|
|
|
tasks: vscode.Task[] | undefined;
|
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
constructor(private workspaceRoot: string|undefined){
|
2025-07-19 18:50:14 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-07-19 14:39:44 +01:00
|
|
|
provideTasks(token?: vscode.CancellationToken): vscode.ProviderResult<vscode.Task[]> {
|
2025-07-19 18:50:14 +01:00
|
|
|
if (this.tasks !== undefined) { return this.tasks; }
|
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
this.tasks = [this.getTaskFromDefinition(undefined)];
|
|
|
|
return this.tasks;
|
|
|
|
}
|
2025-07-19 18:50:14 +01:00
|
|
|
|
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
getTaskFromDefinition(fileName: string|undefined): vscode.Task {
|
2025-07-19 18:50:14 +01:00
|
|
|
const definition:BFRunTaskDefinition = {
|
2025-07-20 00:02:45 +01:00
|
|
|
type: CustomExecutionTaskProvider.type,
|
|
|
|
file: fileName
|
2025-07-19 18:50:14 +01:00
|
|
|
};
|
|
|
|
return new vscode.Task(definition, vscode.TaskScope.Workspace,`bf: run: current file`,CustomExecutionTaskProvider.type,
|
|
|
|
new vscode.CustomExecution(async ()=>{
|
2025-07-20 00:02:45 +01:00
|
|
|
return new CustomBuildTaskTerminal(definition.file);
|
2025-07-19 18:50:14 +01:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveTask(_task: vscode.Task, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.Task> {
|
2025-07-20 00:02:45 +01:00
|
|
|
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);
|
|
|
|
})
|
|
|
|
);
|
2025-07-19 14:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CustomBuildTaskTerminal implements vscode.Pseudoterminal {
|
|
|
|
private writeEmitter = new vscode.EventEmitter<string>();
|
|
|
|
private closeEmitter = new vscode.EventEmitter<number>();
|
2025-07-19 18:50:14 +01:00
|
|
|
|
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
private openDocument:vscode.TextDocument|undefined;
|
2025-07-19 18:50:14 +01:00
|
|
|
onDidWrite: vscode.Event<string> = this.writeEmitter.event;
|
2025-07-19 14:39:44 +01:00
|
|
|
onDidClose?: vscode.Event<number> = this.closeEmitter.event;
|
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
handleInput(data: string): void {
|
|
|
|
this.writeEmitter.fire(`Echo`+data);
|
|
|
|
}
|
2025-07-19 14:39:44 +01:00
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
|
|
|
|
constructor(private fileName?:string) {
|
2025-07-19 14:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
open(initialDimensions: vscode.TerminalDimensions | undefined): void {
|
|
|
|
// At this point we can start using the terminal.
|
2025-07-20 00:02:45 +01:00
|
|
|
|
|
|
|
const openDocument = vscode.window.activeTextEditor.document;
|
|
|
|
this.openDocument = openDocument;
|
|
|
|
console.log(openDocument.languageId);
|
|
|
|
this.doExecution();
|
2025-07-19 14:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close(): void {
|
|
|
|
// The terminal has been closed. Shutdown the build.
|
|
|
|
}
|
|
|
|
|
2025-07-20 00:02:45 +01:00
|
|
|
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);
|
2025-07-19 14:39:44 +01:00
|
|
|
}
|
|
|
|
}
|