[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 * as path from 'path';
import { commands, tasks, workspace } from 'vscode'; import { commands, tasks, workspace,window } from 'vscode';
import type { Disposable, ExtensionContext } from 'vscode'; import type { Disposable, ExtensionContext } from 'vscode';
import { import {
LanguageClient, LanguageClient,
@@ -71,7 +71,8 @@ export function activate(context: ExtensionContext) {
const workspaceRoot = (workspace.workspaceFolders && (workspace.workspaceFolders.length > 0)) const workspaceRoot = (workspace.workspaceFolders && (workspace.workspaceFolders.length > 0))
? workspace.workspaceFolders[0].uri.fsPath : undefined; ? 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 { export function deactivate(): Thenable<void> | undefined {

View File

@@ -1,45 +1,48 @@
import path = require('node:path');
import * as vscode from 'vscode'; import * as vscode from 'vscode';
interface BFRunTaskDefinition { interface BFRunTaskDefinition extends vscode.TaskDefinition {
type: 'current';
file?: string; file?: string;
} }
export class CustomExecutionTaskProvider implements vscode.TaskProvider { export class CustomExecutionTaskProvider implements vscode.TaskProvider {
static type: string = 'BFExec'; static type: string = 'bf-run';
tasks: vscode.Task[] | undefined; 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[]> { provideTasks(token?: vscode.CancellationToken): vscode.ProviderResult<vscode.Task[]> {
if (this.tasks !== undefined) { return this.tasks; } if (this.tasks !== undefined) { return this.tasks; }
const types: BFRunTaskDefinition['type'][] = ['current']; this.tasks = [this.getTaskFromDefinition(undefined)];
this.tasks = []; return this.tasks;
types.forEach(e=>
this.tasks.push(this.getTaskFromDefinition(e))
);
} }
getTaskFromDefinition(e: string): vscode.Task {
getTaskFromDefinition(fileName: string|undefined): vscode.Task {
const definition:BFRunTaskDefinition = { const definition:BFRunTaskDefinition = {
type: 'current', type: CustomExecutionTaskProvider.type,
file: undefined file: fileName
}; };
return new vscode.Task(definition, vscode.TaskScope.Workspace,`bf: run: current file`,CustomExecutionTaskProvider.type, return new vscode.Task(definition, vscode.TaskScope.Workspace,`bf: run: current file`,CustomExecutionTaskProvider.type,
new vscode.CustomExecution(async ()=>{ 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> { 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 closeEmitter = new vscode.EventEmitter<number>();
private openDocument:vscode.TextDocument|undefined;
onDidWrite: vscode.Event<string> = this.writeEmitter.event; onDidWrite: vscode.Event<string> = this.writeEmitter.event;
onDidClose?: vscode.Event<number> = this.closeEmitter.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 { open(initialDimensions: vscode.TerminalDimensions | undefined): void {
// At this point we can start using the terminal. // 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 { close(): void {
// The terminal has been closed. Shutdown the build. // The terminal has been closed. Shutdown the build.
if (this.fileWatcher) {
this.fileWatcher.dispose();
}
} }
private async doBuild(): Promise<void> { private async doExecution(): Promise<void> {
return new Promise<void>((resolve) => { this.writeEmitter.fire('Build complete.\r\n\r\n');
this.writeEmitter.fire('Starting build...\r\n'); this.writeEmitter.fire('Requested build of '+this.fileName);
// Since we don't actually build anything in this example set a timeout instead. this.writeEmitter.fire(this.openDocument.getText());
this.writeEmitter.fire('Build complete.\r\n\r\n'); this.closeEmitter.fire(0);
this.closeEmitter.fire(0);
resolve();
});
} }
} }

View File

@@ -85,7 +85,18 @@
"description": "Traces the communication between VS Code and the language server." "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": { "scripts": {
"vscode:prepublish": "npm run compile", "vscode:prepublish": "npm run compile",

View File

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