mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
auto-fixed prefer-const violation
This commit is contained in:
@@ -33,7 +33,7 @@ function exec(command: string, options: cp.ExecOptions): Promise<{ stdout: strin
|
||||
|
||||
const buildNames: string[] = ['build', 'compile', 'watch'];
|
||||
function isBuildTask(name: string): boolean {
|
||||
for (let buildName of buildNames) {
|
||||
for (const buildName of buildNames) {
|
||||
if (name.indexOf(buildName) !== -1) {
|
||||
return true;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ function isBuildTask(name: string): boolean {
|
||||
|
||||
const testNames: string[] = ['test'];
|
||||
function isTestTask(name: string): boolean {
|
||||
for (let testName of testNames) {
|
||||
for (const testName of testNames) {
|
||||
if (name.indexOf(testName) !== -1) {
|
||||
return true;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ function showError() {
|
||||
|
||||
async function findJakeCommand(rootPath: string): Promise<string> {
|
||||
let jakeCommand: string;
|
||||
let platform = process.platform;
|
||||
const 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'))) {
|
||||
@@ -103,7 +103,7 @@ class FolderDetector {
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
let pattern = path.join(this._workspaceFolder.uri.fsPath, '{node_modules,Jakefile,Jakefile.js}');
|
||||
const pattern = path.join(this._workspaceFolder.uri.fsPath, '{node_modules,Jakefile,Jakefile.js}');
|
||||
this.fileWatcher = vscode.workspace.createFileSystemWatcher(pattern);
|
||||
this.fileWatcher.onDidChange(() => this.promise = undefined);
|
||||
this.fileWatcher.onDidCreate(() => this.promise = undefined);
|
||||
@@ -124,17 +124,17 @@ class FolderDetector {
|
||||
public async getTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||
const jakeTask = (<any>_task.definition).task;
|
||||
if (jakeTask) {
|
||||
let kind: JakeTaskDefinition = (<any>_task.definition);
|
||||
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));
|
||||
const kind: JakeTaskDefinition = (<any>_task.definition);
|
||||
const options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||
const 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[]> {
|
||||
let rootPath = this._workspaceFolder.uri.scheme === 'file' ? this._workspaceFolder.uri.fsPath : undefined;
|
||||
let emptyTasks: vscode.Task[] = [];
|
||||
const rootPath = this._workspaceFolder.uri.scheme === 'file' ? this._workspaceFolder.uri.fsPath : undefined;
|
||||
const emptyTasks: vscode.Task[] = [];
|
||||
if (!rootPath) {
|
||||
return emptyTasks;
|
||||
}
|
||||
@@ -146,32 +146,32 @@ class FolderDetector {
|
||||
}
|
||||
}
|
||||
|
||||
let commandLine = `${await this._jakeCommand} --tasks`;
|
||||
const commandLine = `${await this._jakeCommand} --tasks`;
|
||||
try {
|
||||
let { stdout, stderr } = await exec(commandLine, { cwd: rootPath });
|
||||
const { stdout, stderr } = await exec(commandLine, { cwd: rootPath });
|
||||
if (stderr) {
|
||||
getOutputChannel().appendLine(stderr);
|
||||
showError();
|
||||
}
|
||||
let result: vscode.Task[] = [];
|
||||
const result: vscode.Task[] = [];
|
||||
if (stdout) {
|
||||
let lines = stdout.split(/\r{0,1}\n/);
|
||||
for (let line of lines) {
|
||||
const lines = stdout.split(/\r{0,1}\n/);
|
||||
for (const line of lines) {
|
||||
if (line.length === 0) {
|
||||
continue;
|
||||
}
|
||||
let regExp = /^jake\s+([^\s]+)\s/g;
|
||||
let matches = regExp.exec(line);
|
||||
const regExp = /^jake\s+([^\s]+)\s/g;
|
||||
const matches = regExp.exec(line);
|
||||
if (matches && matches.length === 2) {
|
||||
let taskName = matches[1];
|
||||
let kind: JakeTaskDefinition = {
|
||||
const taskName = matches[1];
|
||||
const kind: JakeTaskDefinition = {
|
||||
type: 'jake',
|
||||
task: taskName
|
||||
};
|
||||
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||
let task = new vscode.Task(kind, taskName, 'jake', new vscode.ShellExecution(`${await this._jakeCommand} ${taskName}`, options));
|
||||
const options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||
const task = new vscode.Task(kind, taskName, 'jake', new vscode.ShellExecution(`${await this._jakeCommand} ${taskName}`, options));
|
||||
result.push(task);
|
||||
let lowerCaseLine = line.toLowerCase();
|
||||
const lowerCaseLine = line.toLowerCase();
|
||||
if (isBuildTask(lowerCaseLine)) {
|
||||
task.group = vscode.TaskGroup.Build;
|
||||
} else if (isTestTask(lowerCaseLine)) {
|
||||
@@ -182,7 +182,7 @@ class FolderDetector {
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
let channel = getOutputChannel();
|
||||
const channel = getOutputChannel();
|
||||
if (err.stderr) {
|
||||
channel.appendLine(err.stderr);
|
||||
}
|
||||
@@ -212,7 +212,7 @@ class TaskDetector {
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
let folders = vscode.workspace.workspaceFolders;
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (folders) {
|
||||
this.updateWorkspaceFolders(folders, []);
|
||||
}
|
||||
@@ -229,15 +229,15 @@ class TaskDetector {
|
||||
}
|
||||
|
||||
private updateWorkspaceFolders(added: readonly vscode.WorkspaceFolder[], removed: readonly vscode.WorkspaceFolder[]): void {
|
||||
for (let remove of removed) {
|
||||
let detector = this.detectors.get(remove.uri.toString());
|
||||
for (const remove of removed) {
|
||||
const detector = this.detectors.get(remove.uri.toString());
|
||||
if (detector) {
|
||||
detector.dispose();
|
||||
this.detectors.delete(remove.uri.toString());
|
||||
}
|
||||
}
|
||||
for (let add of added) {
|
||||
let detector = new FolderDetector(add, findJakeCommand(add.uri.fsPath));
|
||||
for (const add of added) {
|
||||
const detector = new FolderDetector(add, findJakeCommand(add.uri.fsPath));
|
||||
this.detectors.set(add.uri.toString(), detector);
|
||||
if (detector.isEnabled()) {
|
||||
detector.start();
|
||||
@@ -247,15 +247,15 @@ class TaskDetector {
|
||||
}
|
||||
|
||||
private updateConfiguration(): void {
|
||||
for (let detector of this.detectors.values()) {
|
||||
for (const detector of this.detectors.values()) {
|
||||
detector.dispose();
|
||||
this.detectors.delete(detector.workspaceFolder.uri.toString());
|
||||
}
|
||||
let folders = vscode.workspace.workspaceFolders;
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (folders) {
|
||||
for (let folder of folders) {
|
||||
for (const folder of folders) {
|
||||
if (!this.detectors.has(folder.uri.toString())) {
|
||||
let detector = new FolderDetector(folder, findJakeCommand(folder.uri.fsPath));
|
||||
const detector = new FolderDetector(folder, findJakeCommand(folder.uri.fsPath));
|
||||
this.detectors.set(folder.uri.toString(), detector);
|
||||
if (detector.isEnabled()) {
|
||||
detector.start();
|
||||
@@ -294,13 +294,13 @@ class TaskDetector {
|
||||
} else if (this.detectors.size === 1) {
|
||||
return this.detectors.values().next().value.getTasks();
|
||||
} else {
|
||||
let promises: Promise<vscode.Task[]>[] = [];
|
||||
for (let detector of this.detectors.values()) {
|
||||
const promises: Promise<vscode.Task[]>[] = [];
|
||||
for (const detector of this.detectors.values()) {
|
||||
promises.push(detector.getTasks().then((value) => value, () => []));
|
||||
}
|
||||
return Promise.all(promises).then((values) => {
|
||||
let result: vscode.Task[] = [];
|
||||
for (let tasks of values) {
|
||||
const result: vscode.Task[] = [];
|
||||
for (const tasks of values) {
|
||||
if (tasks && tasks.length > 0) {
|
||||
result.push(...tasks);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user