[vscode-spring-cli] Simple TaskProvider implementation
This commit is contained in:
@@ -104,6 +104,10 @@
|
||||
"arguments": {
|
||||
"type": "array",
|
||||
"description": "The parameters of the command"
|
||||
},
|
||||
"cwd": {
|
||||
"type": "string",
|
||||
"description": "Path for Spring CLI process execution"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { BootAddMetadata, BootNewMetadata, Project, ProjectCatalog, commandAddMetadata } from "./cli-types";
|
||||
import { ProcessExecution, ProgressLocation, Task, TaskScope, Uri, env, tasks, window, workspace } from "vscode";
|
||||
import { CancellationToken, ProcessExecution, ProgressLocation, ProviderResult, Task, TaskProvider, TaskScope, Uri, tasks, window, workspace } from "vscode";
|
||||
import cp from "child_process";
|
||||
import { homedir } from "os";
|
||||
import { getWorkspaceRoot } from "./utils";
|
||||
|
||||
const SPRING_CLI_TASK_TYPE = 'spring-cli';
|
||||
export const SPRING_CLI_TASK_TYPE = 'spring-cli';
|
||||
|
||||
export class Cli {
|
||||
|
||||
private get executable(): string {
|
||||
get executable(): string {
|
||||
return workspace.getConfiguration("spring-cli").get("executable") || "spring";
|
||||
}
|
||||
|
||||
@@ -203,3 +203,23 @@ export class Cli {
|
||||
|
||||
}
|
||||
|
||||
export class CliTaskProvider implements TaskProvider {
|
||||
|
||||
constructor(private cli: Cli) {}
|
||||
|
||||
provideTasks(token: CancellationToken): ProviderResult<Task[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
resolveTask(task: Task, token: CancellationToken): ProviderResult<Task> {
|
||||
if (task.definition.type === SPRING_CLI_TASK_TYPE) {
|
||||
const processOpts = { cwd: task.definition.cwd || getWorkspaceRoot()?.fsPath || homedir() };
|
||||
task.execution = this.cli.executable.endsWith(".jar") ?
|
||||
new ProcessExecution("java", [ "-jar", this.cli.executable, ...(task.definition.args || [])], processOpts)
|
||||
: new ProcessExecution(this.cli.executable, task.definition.args || [], processOpts);
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,33 @@
|
||||
"use strict";
|
||||
import * as vscode from "vscode";
|
||||
import { Cli } from "./cli";
|
||||
import { Cli, CliTaskProvider, SPRING_CLI_TASK_TYPE } from "./cli";
|
||||
import { handleBootAdd, handleBootNew } from "./boot";
|
||||
import { handleCatalogAdd, handleCatalogRemove } from "./project-catalog";
|
||||
import { handleProjectAdd, handleProjectRemove } from "./project";
|
||||
import { handleCommandAdd, handleCommandNew, handleCommandRemove } from "./command";
|
||||
import { ExtensionContext, commands, tasks } from "vscode";
|
||||
|
||||
export const CLI = new Cli();
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||
export async function activate(context: ExtensionContext): Promise<void> {
|
||||
|
||||
vscode.commands.registerCommand('vscode-spring-cli.boot.new', handleBootNew);
|
||||
vscode.commands.registerCommand('vscode-spring-cli.boot.add', handleBootAdd);
|
||||
context.subscriptions.push(...[
|
||||
|
||||
]);
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.boot.new', handleBootNew));
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.boot.add', handleBootAdd));
|
||||
|
||||
vscode.commands.registerCommand('vscode-spring-cli.project-catalog.add', handleCatalogAdd);
|
||||
vscode.commands.registerCommand('vscode-spring-cli.project-catalog.remove', handleCatalogRemove);
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.project-catalog.add', handleCatalogAdd));
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.project-catalog.remove', handleCatalogRemove));
|
||||
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.project.add', handleProjectAdd));
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.project.remove', handleProjectRemove));
|
||||
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.command.add', handleCommandAdd));
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.command.remove', handleCommandRemove));
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-cli.command.new', handleCommandNew));
|
||||
|
||||
context.subscriptions.push(tasks.registerTaskProvider(SPRING_CLI_TASK_TYPE, new CliTaskProvider(CLI)));
|
||||
|
||||
vscode.commands.registerCommand('vscode-spring-cli.project.add', handleProjectAdd);
|
||||
vscode.commands.registerCommand('vscode-spring-cli.project.remove', handleProjectRemove);
|
||||
}
|
||||
|
||||
export async function deactivate(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user