Skip to content

Commit

Permalink
Merge pull request #18 from codeitlikemiley/v1.4.4
Browse files Browse the repository at this point in the history
V1.4.4 - Leverage VScode Task Runner
  • Loading branch information
codeitlikemiley authored Jul 3, 2024
2 parents 5b58cd8 + ee897f7 commit d8594dc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
All notable changes to the "cargo-runner" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## 1.4.4
- make running command vscode task
## 1.4.2
- add support running test on bin/* folders
## 1.4.1
Expand Down
23 changes: 21 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "git",
"url": "https://github.com/codeitlikemiley/cargo-runner"
},
"version": "1.4.2",
"version": "1.4.4",
"engines": {
"vscode": "^1.85.0"
},
Expand All @@ -18,6 +18,25 @@
"activationEvents": [],
"main": "./dist/extension.js",
"contributes": {
"taskDefinitions": [
{
"type": "cargo-runner",
"required": [
"command",
"title"
],
"properties": {
"command": {
"type": "string",
"description": "The cargo command to execute."
},
"title": {
"type": "string",
"description": "The title of the task."
}
}
}
],
"commands": [
{
"command": "cargo-runner.exec",
Expand Down Expand Up @@ -72,4 +91,4 @@
"@iarna/toml": "^2.2.5",
"@types/iarna__toml": "^2.0.5"
}
}
}
48 changes: 42 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,48 @@ import * as vscode from 'vscode';
import addArgsToToml from './add_args_to_toml';
import exec from './exec';

class CargoRunnerTaskProvider implements vscode.TaskProvider {
static cargoType: string = 'cargo-runner';

provideTasks(): vscode.ProviderResult<vscode.Task[]> {
// Define static tasks if needed
return [];
}

resolveTask(_task: vscode.Task): vscode.Task | undefined {
const command: string = _task.definition.command;
const title: string = _task.definition.title;
if (command) {
const task = new vscode.Task(
_task.definition,
vscode.TaskScope.Workspace,
title,
'cargo-runner',
new vscode.ShellExecution(command),
'$rustc'
);
return task;
}
return undefined;
}
}

function createAndExecuteTask(command: string) {
const task = new vscode.Task(
{ type: 'cargo-runner', command },
vscode.TaskScope.Workspace,
command,
'cargo-runner',
new vscode.ShellExecution(command),
'$rustc'
);
vscode.tasks.executeTask(task);
}

export function activate(context: vscode.ExtensionContext) {
const taskProvider = vscode.tasks.registerTaskProvider(CargoRunnerTaskProvider.cargoType, new CargoRunnerTaskProvider());
context.subscriptions.push(taskProvider);

context.subscriptions.push(vscode.commands.registerCommand('cargo-runner.exec', async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
Expand All @@ -17,12 +58,7 @@ export function activate(context: vscode.ExtensionContext) {
}
const command = await exec();
if (command) {
let terminal = vscode.window.activeTerminal;
if (!terminal) {
terminal = vscode.window.createTerminal(`Cargo Run Terminal`);
}
terminal.sendText(command);
terminal.show();
createAndExecuteTask(command);
} else {
let analyzer = vscode.extensions.getExtension('rust-lang.rust-analyzer');
if (analyzer) {
Expand Down

0 comments on commit d8594dc

Please sign in to comment.