mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
parent
b0006ef261
commit
2d4617876b
|
@ -66,6 +66,19 @@ function showError() {
|
|||
});
|
||||
}
|
||||
|
||||
async function findJakeCommand(rootPath: string): Promise<string> {
|
||||
let jakeCommand: string;
|
||||
let platform = process.platform;
|
||||
if (platform === 'win32' && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake.cmd'))) {
|
||||
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake.cmd');
|
||||
} else if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake'))) {
|
||||
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake');
|
||||
} else {
|
||||
jakeCommand = 'jake';
|
||||
}
|
||||
return jakeCommand;
|
||||
}
|
||||
|
||||
interface JakeTaskDefinition extends vscode.TaskDefinition {
|
||||
task: string;
|
||||
file?: string;
|
||||
|
@ -76,7 +89,9 @@ class FolderDetector {
|
|||
private fileWatcher: vscode.FileSystemWatcher | undefined;
|
||||
private promise: Thenable<vscode.Task[]> | undefined;
|
||||
|
||||
constructor(private _workspaceFolder: vscode.WorkspaceFolder) {
|
||||
constructor(
|
||||
private _workspaceFolder: vscode.WorkspaceFolder,
|
||||
private _jakeCommand: Promise<string>) {
|
||||
}
|
||||
|
||||
public get workspaceFolder(): vscode.WorkspaceFolder {
|
||||
|
@ -96,10 +111,28 @@ class FolderDetector {
|
|||
}
|
||||
|
||||
public async getTasks(): Promise<vscode.Task[]> {
|
||||
if (!this.promise) {
|
||||
this.promise = this.computeTasks();
|
||||
if (this.isEnabled()) {
|
||||
if (!this.promise) {
|
||||
this.promise = this.computeTasks();
|
||||
}
|
||||
return this.promise;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return this.promise;
|
||||
}
|
||||
|
||||
public async getTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||
const jakeTask = (<any>_task.definition).task;
|
||||
if (jakeTask) {
|
||||
let kind: JakeTaskDefinition = {
|
||||
type: 'jake',
|
||||
task: jakeTask
|
||||
};
|
||||
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||
let task = new vscode.Task(kind, this.workspaceFolder, jakeTask, 'jake', new vscode.ShellExecution(await this._jakeCommand, [jakeTask], options));
|
||||
return task;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private async computeTasks(): Promise<vscode.Task[]> {
|
||||
|
@ -116,17 +149,7 @@ class FolderDetector {
|
|||
}
|
||||
}
|
||||
|
||||
let jakeCommand: string;
|
||||
let platform = process.platform;
|
||||
if (platform === 'win32' && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake.cmd'))) {
|
||||
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake.cmd');
|
||||
} else if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake'))) {
|
||||
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake');
|
||||
} else {
|
||||
jakeCommand = 'jake';
|
||||
}
|
||||
|
||||
let commandLine = `${jakeCommand} --tasks`;
|
||||
let commandLine = `${await this._jakeCommand} --tasks`;
|
||||
try {
|
||||
let { stdout, stderr } = await exec(commandLine, { cwd: rootPath });
|
||||
if (stderr) {
|
||||
|
@ -149,7 +172,7 @@ class FolderDetector {
|
|||
task: taskName
|
||||
};
|
||||
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||
let task = new vscode.Task(kind, taskName, 'jake', new vscode.ShellExecution(`${jakeCommand} ${taskName}`, options));
|
||||
let task = new vscode.Task(kind, taskName, 'jake', new vscode.ShellExecution(`${await this._jakeCommand} ${taskName}`, options));
|
||||
result.push(task);
|
||||
let lowerCaseLine = line.toLowerCase();
|
||||
if (isBuildTask(lowerCaseLine)) {
|
||||
|
@ -217,9 +240,9 @@ class TaskDetector {
|
|||
}
|
||||
}
|
||||
for (let add of added) {
|
||||
let detector = new FolderDetector(add);
|
||||
let detector = new FolderDetector(add, findJakeCommand(add.uri.fsPath));
|
||||
this.detectors.set(add.uri.toString(), detector);
|
||||
if (detector.isEnabled()) {
|
||||
this.detectors.set(add.uri.toString(), detector);
|
||||
detector.start();
|
||||
}
|
||||
}
|
||||
|
@ -228,18 +251,16 @@ class TaskDetector {
|
|||
|
||||
private updateConfiguration(): void {
|
||||
for (let detector of this.detectors.values()) {
|
||||
if (!detector.isEnabled()) {
|
||||
detector.dispose();
|
||||
this.detectors.delete(detector.workspaceFolder.uri.toString());
|
||||
}
|
||||
detector.dispose();
|
||||
this.detectors.delete(detector.workspaceFolder.uri.toString());
|
||||
}
|
||||
let folders = vscode.workspace.workspaceFolders;
|
||||
if (folders) {
|
||||
for (let folder of folders) {
|
||||
if (!this.detectors.has(folder.uri.toString())) {
|
||||
let detector = new FolderDetector(folder);
|
||||
let detector = new FolderDetector(folder, findJakeCommand(folder.uri.fsPath));
|
||||
this.detectors.set(folder.uri.toString(), detector);
|
||||
if (detector.isEnabled()) {
|
||||
this.detectors.set(folder.uri.toString(), detector);
|
||||
detector.start();
|
||||
}
|
||||
}
|
||||
|
@ -250,12 +271,13 @@ class TaskDetector {
|
|||
|
||||
private updateProvider(): void {
|
||||
if (!this.taskProvider && this.detectors.size > 0) {
|
||||
const thisCapture = this;
|
||||
this.taskProvider = vscode.workspace.registerTaskProvider('gulp', {
|
||||
provideTasks: () => {
|
||||
return this.getTasks();
|
||||
provideTasks(): Promise<vscode.Task[]> {
|
||||
return thisCapture.getTasks();
|
||||
},
|
||||
resolveTask(_task: vscode.Task): vscode.Task | undefined {
|
||||
return undefined;
|
||||
resolveTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||
return thisCapture.getTask(_task);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -290,6 +312,25 @@ class TaskDetector {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async getTask(task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||
if (this.detectors.size === 0) {
|
||||
return undefined;
|
||||
} else if (this.detectors.size === 1) {
|
||||
return this.detectors.values().next().value.getTask(task);
|
||||
} else {
|
||||
if ((task.scope === vscode.TaskScope.Workspace) || (task.scope === vscode.TaskScope.Global)) {
|
||||
// Not supported, we don't have enough info to create the task.
|
||||
return undefined;
|
||||
} else if (task.scope) {
|
||||
const detector = this.detectors.get(task.scope.uri.toString());
|
||||
if (detector) {
|
||||
return detector.getTask(task);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let detector: TaskDetector;
|
||||
|
|
Loading…
Reference in a new issue