rescript-vscode icon indicating copy to clipboard operation
rescript-vscode copied to clipboard

Start build on the client via ProcessExecution

Open nojaf opened this issue 6 months ago • 0 comments

It has never been really obvious to me that this build

Image

is a watch build and you don't need to run rescript -w in a separate terminal anymore.

What would you think of the idea of running this in the vscode extension (instead of the LSP server) and use the TaskProvider instead.

(something along the lines of)

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    let disposable = vscode.commands.registerCommand('myExtension.runProcessTask', async () => {
        // Define the command to run
        // On Windows, you might need to specify the full path to echo.
        // For cross-platform compatibility, consider using a nodejs process
        // or checking the platform. For this example, 'echo' works on most systems.
        const command = 'echo';
        const args = ['Hello from VS Code Task (ProcessExecution)!'];

        // Create the task using ProcessExecution
        const task = new vscode.Task(
            { type: 'process', task: 'myProcessTask' }, // Task definition (type changed to 'process')
            vscode.TaskScope.Workspace,              // Task scope
            'My Process Task (ProcessExecution)',    // Task name
            'My Extension',                          // Task source
            new vscode.ProcessExecution(command, args),  // Execution details using ProcessExecution
            {                                        // Presentation options
                reveal: vscode.TaskRevealKind.Always,
                panel: vscode.TaskPanelKind.Dedicated,
                clear: true
            }
        );

        // Execute the task
        try {
            await vscode.tasks.executeTask(task);
        } catch (error: any) {
            vscode.window.showErrorMessage(`Failed to execute task: ${error.message}`);
        }
    });

    context.subscriptions.push(disposable);
}

export function deactivate() {}

nojaf avatar May 19 '25 18:05 nojaf