Skip to content

Commit

Permalink
Add locks task to run the current open file in vs code
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleect committed Nov 4, 2023
1 parent a828d7b commit 234fb9b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
6 changes: 3 additions & 3 deletions vsc/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import {
ExtensionContext,
commands,
tasks,
ShellExecution,
Task,
TaskScope,
TaskDefinition,
window,
} from "vscode";
Expand All @@ -16,6 +13,7 @@ import {
LanguageClientOptions,
ServerOptions,
} from "vscode-languageclient/node";
import { LocksTaskProvider } from "./locksTaskProvider";

let lc: LanguageClient;

Expand Down Expand Up @@ -81,6 +79,8 @@ export function activate(context: ExtensionContext) {
commands.registerCommand("locks.runCurrentFile", runFileHandler)
);

tasks.registerTaskProvider("locks", new LocksTaskProvider());

lc.start();
}

Expand Down
43 changes: 43 additions & 0 deletions vsc/locksTaskProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as vscode from "vscode";

export class LocksTaskProvider implements vscode.TaskProvider {
static TaskType = "locks";
private task: vscode.Task | undefined;

constructor() {
this.task = new vscode.Task(
{
type: LocksTaskProvider.TaskType,
},
vscode.TaskScope.Workspace,
"run",
"locks"
);
}

async provideTasks(token: vscode.CancellationToken): Promise<vscode.Task[]> {
const tasks = [];
tasks.push(this.task);
return tasks;
}

resolveTask(
task: vscode.Task,
_token: vscode.CancellationToken
): vscode.Task | undefined {
return new vscode.Task(
task.definition,
vscode.TaskScope.Workspace,
task.name,
task.source,
new vscode.ShellExecution(
`locks run ${this.getCurrentOpenFilePath()}`,
{}
)
);
}

private getCurrentOpenFilePath(): string {
return vscode.window.activeTextEditor.document.uri.path;
}
}
7 changes: 7 additions & 0 deletions vsc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@
"command": "locks.runCurrentFile",
"title": "Locks: Run Current File"
}
],
"taskDefinitions": [
{
"type": "locks",
"required": [],
"properties": {}
}
]
},
"activationEvents": [],
Expand Down

0 comments on commit 234fb9b

Please sign in to comment.