[add] task configs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user