refactor: Rename CargoTask to RustTask in extension

This commit is contained in:
Wilfred Hughes 2024-03-13 15:47:34 -07:00
parent 14558af15e
commit d472fd932b
2 changed files with 13 additions and 13 deletions

View file

@ -113,7 +113,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
const args = createArgs(runnable); const args = createArgs(runnable);
const definition: tasks.CargoTaskDefinition = { const definition: tasks.RustTargetDefinition = {
type: tasks.TASK_TYPE, type: tasks.TASK_TYPE,
command: args[0], // run, test, etc... command: args[0], // run, test, etc...
args: args.slice(1), args: args.slice(1),
@ -124,7 +124,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate() const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()
const cargoTask = await tasks.buildCargoTask( const task = await tasks.buildRustTask(
target, target,
definition, definition,
runnable.label, runnable.label,
@ -134,12 +134,12 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
true, true,
); );
cargoTask.presentationOptions.clear = true; task.presentationOptions.clear = true;
// Sadly, this doesn't prevent focus stealing if the terminal is currently // Sadly, this doesn't prevent focus stealing if the terminal is currently
// hidden, and will become revealed due to task execution. // hidden, and will become revealed due to task execution.
cargoTask.presentationOptions.focus = false; task.presentationOptions.focus = false;
return cargoTask; return task;
} }
export function createArgs(runnable: ra.Runnable): string[] { export function createArgs(runnable: ra.Runnable): string[] {

View file

@ -9,7 +9,7 @@ import { unwrapUndefinable } from "./undefinable";
export const TASK_TYPE = "cargo"; export const TASK_TYPE = "cargo";
export const TASK_SOURCE = "rust"; export const TASK_SOURCE = "rust";
export interface CargoTaskDefinition extends vscode.TaskDefinition { export interface RustTargetDefinition extends vscode.TaskDefinition {
command?: string; command?: string;
args?: string[]; args?: string[];
cwd?: string; cwd?: string;
@ -17,7 +17,7 @@ export interface CargoTaskDefinition extends vscode.TaskDefinition {
overrideCargo?: string; overrideCargo?: string;
} }
class CargoTaskProvider implements vscode.TaskProvider { class RustTaskProvider implements vscode.TaskProvider {
private readonly config: Config; private readonly config: Config;
constructor(config: Config) { constructor(config: Config) {
@ -42,7 +42,7 @@ class CargoTaskProvider implements vscode.TaskProvider {
const tasks: vscode.Task[] = []; const tasks: vscode.Task[] = [];
for (const workspaceTarget of vscode.workspace.workspaceFolders || []) { for (const workspaceTarget of vscode.workspace.workspaceFolders || []) {
for (const def of defs) { for (const def of defs) {
const vscodeTask = await buildCargoTask( const vscodeTask = await buildRustTask(
workspaceTarget, workspaceTarget,
{ type: TASK_TYPE, command: def.command }, { type: TASK_TYPE, command: def.command },
`cargo ${def.command}`, `cargo ${def.command}`,
@ -63,11 +63,11 @@ class CargoTaskProvider implements vscode.TaskProvider {
// we need to inform VSCode how to execute that command by creating // we need to inform VSCode how to execute that command by creating
// a ShellExecution for it. // a ShellExecution for it.
const definition = task.definition as CargoTaskDefinition; const definition = task.definition as RustTargetDefinition;
if (definition.type === TASK_TYPE && definition.command) { if (definition.type === TASK_TYPE && definition.command) {
const args = [definition.command].concat(definition.args ?? []); const args = [definition.command].concat(definition.args ?? []);
return await buildCargoTask( return await buildRustTask(
task.scope, task.scope,
definition, definition,
task.name, task.name,
@ -81,9 +81,9 @@ class CargoTaskProvider implements vscode.TaskProvider {
} }
} }
export async function buildCargoTask( export async function buildRustTask(
scope: vscode.WorkspaceFolder | vscode.TaskScope | undefined, scope: vscode.WorkspaceFolder | vscode.TaskScope | undefined,
definition: CargoTaskDefinition, definition: RustTargetDefinition,
name: string, name: string,
args: string[], args: string[],
problemMatcher: string[], problemMatcher: string[],
@ -138,6 +138,6 @@ export async function buildCargoTask(
} }
export function activateTaskProvider(config: Config): vscode.Disposable { export function activateTaskProvider(config: Config): vscode.Disposable {
const provider = new CargoTaskProvider(config); const provider = new RustTaskProvider(config);
return vscode.tasks.registerTaskProvider(TASK_TYPE, provider); return vscode.tasks.registerTaskProvider(TASK_TYPE, provider);
} }