Skip to content

Commit

Permalink
fix: vscode tasks - compound tasks with no 'command' property do not …
Browse files Browse the repository at this point in the history
…launch. [fixes #130]
  • Loading branch information
spmeesseman committed Feb 6, 2021
1 parent 82aa4bd commit f5a92fc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 33 deletions.
50 changes: 50 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,55 @@
"problemMatcher": [
"$tsc"
]
},
{
"label": "cmd1",
"type": "shell",
"command": "cmd",
"args": [
"/c",
"echo",
"hello1"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "cmd2",
"type": "shell",
"command": "cmd",
"args": [
"/c",
"echo",
"hello111112222"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "tetcmpx",
"detail": "",
"type": "shell",
"dependsOn": ["cmd1", "cmd2"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"promptOnClose": true,

}]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-taskexplorer",
"version": "1.28.0",
"displayName": "Task Explorer",
"description": "Tasks management for npm, yarn, vscode, ant, gradle, grunt, gulp, batch, bash, make, python, perl, powershell, ruby, and nsis",
"description": "Tasks management for npm, vscode, yarn, ant, gradle, grunt, gulp, batch, bash, make, python, perl, powershell, ruby, and nsis",
"icon": "res/gears-r-colors.png",
"publisher": "spmeesseman",
"license": "MIT",
Expand Down
73 changes: 44 additions & 29 deletions src/taskTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
util.logValue(" is install task", this.isInstallTask(each));
}
});

console.log(1);
//
// Sort nodes. By default the project folders are sorted in the same order as that
// of the Explorer. Sort TaskFile nodes and TaskItems nodes alphabetically, by default
Expand Down Expand Up @@ -1547,7 +1547,7 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
subfolders.set(id, subfolder);
folder.addTaskFile(subfolder);
subfolder.addScript(prevTaskFile);
util.logValue(" Added source file sub-container", each.path);
util.logValue(" Added source file sub-container", each.path);console.log(3);
}
subfolder.addScript(each);
}
Expand All @@ -1558,13 +1558,12 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
this.createTaskGroupingsBySep(folder, each, subfolders);
});

//folder.taskFiles.forEach(each =>
//{
// if (!(each instanceof TaskFile)) {
// return; // continue forEach()
// }
this.removeGroupedTasks(folder, subfolders);
//});
//
// For groupings with separator, when building the task tree, when tasks are grouped new task definitions
// are created but the old task remains in the parent folder. Remove all tasks that have been moved down
// into the tree hierarchy due to groupings
//
this.removeGroupedTasks(folder, subfolders);

//
// For groupings with separator, now go through and rename the labels within each group minus the
Expand Down Expand Up @@ -1622,16 +1621,30 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
*
* build-prod
* build-dev
* build-server
* build-server-dev
* build-server-prod
* build-sass
*
* If the option 'groupWithSeparator' is ON and 'groupSeparator' is set to '-', then group this set of tasks like so:
* If the option 'groupWithSeparator' is ON and 'groupSeparator' is set, then group this set of tasks.
* By default the hierarchy would look like:
*
* build
* prod
* dev
* server
* server-dev
* server-prod
* sass
*
* If 'groupMaxLevel' is > 1 (default), then the hierarchy continunes to be broken down until the max
* nesting level is reached. The example above, with 'groupMaxLevel' set > 1, would look like:
*
* build
* prod
* dev
* server
* dev
* prod
* sass
*
* @param folder The base task folder
* @param each Task file to process
Expand All @@ -1642,11 +1655,26 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
private createTaskGroupingsBySep(folder: TaskFolder, taskFile: TaskFile, subfolders: Map<string, TaskFile>, treeLevel = 0)
{
let prevName: string[];
let prevTaskItem: TaskItem | TaskFile;
let prevTaskItem: TaskItem;
const newNodes: TaskFile[] = [];
const groupSeparator = configuration.get<string>("groupSeparator") || "-";
const atMaxLevel: Boolean = configuration.get<number>("groupMaxLevel") <= treeLevel + 1;

function _setNodePath(t: TaskItem, cPath: string)
{
if (!atMaxLevel) {
if (!t.nodePath && taskFile.taskSource === "Workspace") {
t.nodePath = path.join(".vscode", prevName[treeLevel]);
}
else if (!t.nodePath) {
t.nodePath = prevName[treeLevel];
}
else {
t.nodePath = path.join(cPath, prevName[treeLevel]);
}
}
}

taskFile.scripts.forEach(each =>
{
if (!(each instanceof TaskItem)) {
Expand Down Expand Up @@ -1708,26 +1736,13 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
each.taskFile.path, true, prevName[treeLevel], treeLevel);
subfolders.set(id, subfolder);

if (!atMaxLevel) {
if (!each.nodePath && taskFile.taskSource === "Workspace") {
prevTaskItem.nodePath = path.join(".vscode", prevName[treeLevel]);
}
else {
prevTaskItem.nodePath = path.join(each.nodePath, prevName[treeLevel]);
}
}
_setNodePath(prevTaskItem, each.nodePath);

subfolder.addScript(prevTaskItem);
newNodes.push(subfolder);
}

if (!atMaxLevel) {
if (!each.nodePath && taskFile.taskSource === "Workspace") {
each.nodePath = path.join(".vscode", prevName[treeLevel]);
}
else {
each.nodePath = path.join(each.nodePath, prevName[treeLevel]);
}
}
_setNodePath(each, each.nodePath);
subfolder.addScript(each);
}

Expand Down
11 changes: 8 additions & 3 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ export class TaskFile extends TreeItem
return fileName;
}


constructor(context: ExtensionContext, folder: TaskFolder, taskDef: TaskDefinition, source: string, relativePath: string, group?: boolean, label?: string, groupLevel?: number)
{
super(TaskFile.getLabel(taskDef, label ? label : source, relativePath, group), TreeItemCollapsibleState.Collapsed);
Expand All @@ -204,15 +203,18 @@ export class TaskFile extends TreeItem
this.nodePath = relativePath;
this.taskSource = source;
this.isGroup = (group === true);

const labelI = TaskFile.getLabel(taskDef, label ? label : source, relativePath, group);

if (group && labelI) {
this.nodePath = path.join(this.nodePath, labelI);
}

if (!this.nodePath && labelI === "vscode") {
this.nodePath = path.join(".vscode", labelI);
}
if (!this.nodePath) {
this.nodePath = "";
}

if (!group)
{
Expand Down Expand Up @@ -242,12 +244,15 @@ export class TaskFile extends TreeItem
{
let src = this.taskSource;
//
// If npm, check package manager set in vscode settings
// If npm, check package manager set in vscode settings, (npm, pnpm, or yarn)
//
if (src === "npm")
{
let pkgMgr = workspace.getConfiguration("npm").get<string>("packageManager");
src = pkgMgr || this.taskSource;
if (src.indexOf("npm") != -1) { // pnpm?
src = "npm";
}
}
this.iconPath = {
light: context.asAbsolutePath(path.join("res", "sources", src + ".svg")),
Expand Down

0 comments on commit f5a92fc

Please sign in to comment.