Skip to content

Commit

Permalink
style: refresh() method extractions
Browse files Browse the repository at this point in the history
  • Loading branch information
spmeesseman committed Feb 7, 2021
1 parent c75d9aa commit 208a5f1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 45 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Provides a view in either (or both) the SideBar and/or Explorer that displays al
- [Features by Version](#features-by-version)
- [Configuring Global Excludes and Apache Ant Includes](#configuring-global-excludes-and-apache-ant-includes)
- [Ant and Gulp Self-Provided Tasks](#ant-and-gulp-self-provided-tasks)
- [Using Groups With A Separator](#using-groups-with-a-separator)
- [Using Groups with a Separator](#using-groups-with-a-separator)
- [Internally Provided Tasks vs. VSCode Provided Tasks](#internally-provided-tasks-vs-vscode-provided-tasks)
- [Running bash/sh scripts in Windows Environment](#running-bashsh-scripts-in-windows-environment)
- [Feedback & Contributing](#feedback--contributing)
Expand All @@ -50,7 +50,7 @@ Provides a view in either (or both) the SideBar and/or Explorer that displays al
| ---------------------------------- | ---------------------------------- | ---------------------------------- |
| ![ss0](res/taskview1.png?raw=true) | ![ss1](res/taskview2.png?raw=true) | ![ss2](res/taskview3.png?raw=true) |

| Grunt/Gulp in Subfolders (v1.14) | Npm Commands (v1.16) | Task Dashed Groups (v1.23) |
| Grunt/Gulp in Subfolders (v1.14) | Npm Commands (v1.16) | Task Groupings (v1.23) |
| ---------------------------------- | ---------------------------------- | ---------------------------------- |
| ![ss4](res/taskview4.png?raw=true) | ![ss5](res/taskview5.png?raw=true) | ![ss6](res/taskview6.png?raw=true) |

Expand Down Expand Up @@ -115,7 +115,7 @@ Note that the glob pattern "\*\*/[Bb]uild.xml" is applied by default to the **An

By default, a custom parser is used to locate Ant and Gulp tasks in respective files. This may be fine in most cases, but in cases where the script and/or build files become complex, or there is something in the file that was not coded into the parser, you can use the *ant* and *gulp* programs themselves to find their own tasks. Note however that turning this on has a negative performance impact when refreshing and providing tasks to the VSCode Task Host.

## Using Groups With A Separator
## Using Groups with a Separator

**EXPERIMENTAL**
The *Groups With Separator* option is simply an extra level of task groupings that can be made based on a configured separation character in the script name. This option can be turned on/off with the *Group With Sepator* option in Settings, the default is OFF. The default separator is a dash ("-").
Expand Down
99 changes: 57 additions & 42 deletions src/taskTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,16 +775,8 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
}


public async refresh(invalidate?: any, opt?: Uri | boolean, task?: Task)
private _showStatusMessage(task: Task)
{
util.log("Refresh task tree");
util.logValue(" invalidate", invalidate, 2);
util.logValue(" opt fsPath", opt && opt instanceof Uri ? opt.fsPath : "n/a", 2);
util.logValue(" task name", task ? task.name : "n/a", 2);

//
// Show status bar message (if ON in settings)
//
if (task && configuration.get<boolean>("showRunningTask") === true)
{
const exec = tasks.taskExecutions.find(e => e.task.name === task.name && e.task.source === task.source &&
Expand All @@ -810,6 +802,56 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
}
}
}
}


private _handleVisibleEvent()
{
util.log(" Handling 'visible' event");
if (this.needsRefresh && this.needsRefresh.length > 0)
{
// If theres more than one pending refresh request, just refresh the tree
//
if (this.needsRefresh.length > 1 || this.needsRefresh[0].invalidate === undefined)
{
this.refresh();
}
else
{
this.refresh(this.needsRefresh[0].invalidate, this.needsRefresh[0].uri, this.needsRefresh[0].task);
}

this.needsRefresh = [];
}
}


private async _handleInvalidation(invalidate: any, opt: boolean | Uri)
{
if ((invalidate === true || invalidate === "tests") && !opt) {
util.log(" Handling 'rebuild cache' event");
this.busy = true;
await rebuildCache();
this.busy = false;
}
if (invalidate !== "tests") {
util.log(" Handling 'invalidate tasks cache' event");
await this.invalidateTasksCache(invalidate, opt);
}
}


public async refresh(invalidate?: any, opt?: Uri | boolean, task?: Task): Promise<boolean>
{
util.log("Refresh task tree");
util.logValue(" invalidate", invalidate, 2);
util.logValue(" opt fsPath", opt && opt instanceof Uri ? opt.fsPath : "n/a", 2);
util.logValue(" task name", task ? task.name : "n/a", 2);

//
// Show status bar message (if ON in settings)
//
this._showStatusMessage(task);

//
// If a view was turned off in settings, the disposable view still remains
Expand All @@ -823,7 +865,7 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
{
util.log(" Delay refresh, exit");
this.needsRefresh.push({ invalidate, opt, task });
return;
return false;
}
}

Expand All @@ -835,30 +877,12 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>
// parameters in an object (above block of code). When the view becomes visible again, we refresh if we
// need to, if not then just exit on this refresh request
//
if (this.taskTree && invalidate === "visible-event")
{
util.log(" Handling 'visible' event");
if (this.needsRefresh && this.needsRefresh.length > 0)
{
// If theres more than one pending refresh request, just refresh the tree
//
if (this.needsRefresh.length > 1 || this.needsRefresh[0].invalidate === undefined)
{
this.refresh();
}
else
{
this.refresh(this.needsRefresh[0].invalidate, this.needsRefresh[0].uri, this.needsRefresh[0].task);
}

this.needsRefresh = [];
}

return;
}

if (invalidate === "visible-event")
{
if (this.taskTree) {
this._handleVisibleEvent();
return;
}
invalidate = undefined;
}

Expand Down Expand Up @@ -886,16 +910,7 @@ export class TaskTreeDataProvider implements TreeDataProvider<TreeItem>

if (invalidate !== false)
{
if ((invalidate === true || invalidate === "tests") && !opt) {
util.log(" Handling 'rebuild cache' event");
this.busy = true;
await rebuildCache();
this.busy = false;
}
if (invalidate !== "tests") {
util.log(" Handling 'invalidate tasks cache' event");
await this.invalidateTasksCache(invalidate, opt);
}
await this._handleInvalidation(invalidate, opt);
}

if (task)
Expand Down

0 comments on commit 208a5f1

Please sign in to comment.