Skip to content

Commit

Permalink
automatically de-duplicate task names
Browse files Browse the repository at this point in the history
  • Loading branch information
CsCherrYY committed Aug 15, 2022
1 parent e3992ea commit 510efc2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions extension/src/tasks/taskUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
import * as path from "path";
import { parseArgsStringToArgv } from "string-argv";
import { GradleProject, GradleTask } from "../proto/gradle_pb";
import { TaskArgs } from "../stores/types";
Expand Down Expand Up @@ -278,6 +279,27 @@ export async function loadTasksForProjectRoots(
}
}
}
// detect duplicate task names
const tasksMap: Map<string, vscode.Task[]> = new Map();
for (const task of allTasks) {
if (tasksMap.has(task.name)) {
tasksMap.get(task.name)!.push(task);
} else {
tasksMap.set(task.name, [task]);
}
}
// rename duplicate task names with additional relative path
for (const tasks of tasksMap.values()) {
if (tasks.length !== 1) {
for (const task of tasks) {
const definition = task.definition as GradleTaskDefinition;
const relativePath = path.relative(definition.workspaceFolder, definition.projectFolder);
if (relativePath) {
task.name = task.name + ` (${relativePath})`;
}
}
}
}
return allTasks;
}

Expand Down

0 comments on commit 510efc2

Please sign in to comment.