From d8f435997cad48c589c72e2cd43644ea8c0c07c6 Mon Sep 17 00:00:00 2001 From: lisandrasilva Date: Mon, 5 Aug 2024 14:57:42 +0100 Subject: [PATCH] Added forge clean task --- src/foundry.ts | 22 +++++++++++++++++++++- src/startDebugging.ts | 9 ++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/foundry.ts b/src/foundry.ts index e19d42b..ac33dc3 100644 --- a/src/foundry.ts +++ b/src/foundry.ts @@ -2,6 +2,26 @@ import * as vscode from 'vscode'; import {getConfigValue} from './utils'; import {parse as parseToml} from 'smol-toml'; +export +function forgeCleanTask(file: string) { + const forgePath = getConfigValue('forge-path', 'forge'); + const cwd = file.substring(0, file.lastIndexOf('/')); + const task = new vscode.Task( + { + label: 'forge clean', + type: 'shell', + }, + vscode.TaskScope.Workspace, + 'forge', + 'simbolik', + new vscode.ShellExecution(forgePath, ['clean'], { + cwd, + }) + ); + task.isBackground = true; + task.presentationOptions.reveal = vscode.TaskRevealKind.Always; + return task; +} export function forgeBuildTask(file: string) { @@ -110,4 +130,4 @@ async function getSortedFilesByCreationTime(buildInfoDir: string, buildInfoFiles // Sort files by creation time (ctime) return filesWithStats.sort((a, b) => b.ctime - a.ctime); -} \ No newline at end of file +} diff --git a/src/startDebugging.ts b/src/startDebugging.ts index f8589fd..1fe95ed 100644 --- a/src/startDebugging.ts +++ b/src/startDebugging.ts @@ -7,7 +7,7 @@ import { import * as vscode from 'vscode'; import { getConfigValue } from './utils'; import { Supervisor } from './supevervisor'; -import { forgeBuildTask, foundryRoot, loadBuildInfo } from './foundry'; +import { forgeCleanTask, forgeBuildTask, foundryRoot, loadBuildInfo } from './foundry'; export async function startDebugging( this: Supervisor, @@ -63,6 +63,13 @@ export async function startDebugging( const rpcUrl = `http://localhost:${anvilPort}`; const autobuild = getConfigValue('autobuild', true); if (autobuild) { + const clean = forgeCleanTask(activeTextEditor.document.uri.fsPath); + const cleanExecution = await vscode.tasks.executeTask(clean); + try { + await completed(cleanExecution); + } catch (e) { + vscode.window.showErrorMessage('Failed to clean project.'); + } const build = forgeBuildTask(activeTextEditor.document.uri.fsPath); const buildExecution = await vscode.tasks.executeTask(build); try {