Skip to content

Commit

Permalink
fix: after disabling a task type in settings, modification or additio…
Browse files Browse the repository at this point in the history
…ns to files of that type still refresh the tree view.
  • Loading branch information
spmeesseman committed Feb 7, 2021
1 parent 10e0283 commit 0fb783d
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 58 deletions.
82 changes: 82 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@
"dark": "res/dark/continue.svg"
}
},
{
"command": "taskExplorerSideBar.runNoTerm",
"title": "%command.runNoTerm%",
"when": "config.taskExplorer.enableSideBar",
"icon": {
"light": "res/light/continue.svg",
"dark": "res/dark/continue.svg"
}
},
{
"command": "taskExplorerSideBar.runWithArgs",
"title": "%command.runWithArgs%",
"when": "config.taskExplorer.enableSideBar",
"icon": {
"light": "res/light/continue.svg",
"dark": "res/dark/continue.svg"
}
},
{
"command": "taskExplorerSideBar.runLastTask",
"title": "%command.runLastTask%",
Expand Down Expand Up @@ -303,6 +321,24 @@
"dark": "res/dark/continue.svg"
}
},
{
"command": "taskExplorerSideBar.runNoTerm",
"title": "%command.runNoTerm%",
"when": "config.taskExplorer.enableExplorerView",
"icon": {
"light": "res/light/continue.svg",
"dark": "res/dark/continue.svg"
}
},
{
"command": "taskExplorerSideBar.runWithArgs",
"title": "%command.runWithArgs%",
"when": "config.taskExplorer.enableExplorerView",
"icon": {
"light": "res/light/continue.svg",
"dark": "res/dark/continue.svg"
}
},
{
"command": "taskExplorer.runLastTask",
"title": "%command.runLastTask%",
Expand Down Expand Up @@ -466,6 +502,14 @@
"command": "taskExplorer.run",
"when": "config.taskExplorer.enableExplorerView && view == taskExplorer && viewItem == script"
},
{
"command": "taskExplorer.runWithArgs",
"when": "config.taskExplorer.enableExplorerView && view == taskExplorer && viewItem == script"
},
{
"command": "taskExplorer.runNoTerm",
"when": "config.taskExplorer.enableExplorerView && view == taskExplorer && viewItem == script"
},
{
"command": "taskExplorer.addToExcludes",
"when": "config.taskExplorer.enableExplorerView && view == taskExplorer && viewItem == taskFileApp-publiser"
Expand Down Expand Up @@ -586,6 +630,16 @@
"command": "taskExplorer.addToExcludes",
"when": "config.taskExplorer.enableExplorerView && view == taskExplorer && viewItem == taskGroupNsis"
},
{
"command": "taskExplorer.runNoTerm",
"when": "config.taskExplorer.enableExplorerView && config.taskExplorer.showExecuteWithNoTerminalButton && view == taskExplorer && viewItem == script",
"group": "inline"
},
{
"command": "taskExplorer.runWithArgs",
"when": "config.taskExplorer.enableExplorerView && config.taskExplorer.showExecuteWithArgumentsButton && view == taskExplorer && viewItem == script",
"group": "inline"
},
{
"command": "taskExplorer.run",
"when": "config.taskExplorer.enableExplorerView && view == taskExplorer && viewItem == script",
Expand Down Expand Up @@ -644,6 +698,14 @@
"command": "taskExplorerSideBar.run",
"when": "config.taskExplorer.enableSideBar && view == taskExplorerSideBar && viewItem == script"
},
{
"command": "taskExplorer.runWithArgs",
"when": "config.taskExplorer.enableSideBar && view == taskExplorerSideBar && viewItem == script"
},
{
"command": "taskExplorer.runNoTerm",
"when": "config.taskExplorer.enableSideBar && view == taskExplorerSideBar && viewItem == script"
},
{
"command": "taskExplorerSideBar.addToExcludes",
"when": "config.taskExplorer.enableSideBar && view == taskExplorerSideBar && viewItem == taskFileApp-publiser"
Expand Down Expand Up @@ -764,6 +826,16 @@
"command": "taskExplorerSideBar.addToExcludes",
"when": "config.taskExplorer.enableSideBar && view == taskExplorerSideBar && viewItem == taskGroupNsis"
},
{
"command": "taskExplorer.runNoTerm",
"when": "config.taskExplorer.enableSideBar && config.taskExplorer.showExecuteWithNoTerminalButton && view == taskExplorerSideBar && viewItem == script",
"group": "inline"
},
{
"command": "taskExplorer.runWithArgs",
"when": "config.taskExplorer.enableSideBar && config.taskExplorer.showExecuteWithArgumentsButton && view == taskExplorerSideBar && viewItem == script",
"group": "inline"
},
{
"command": "taskExplorerSideBar.run",
"when": "config.taskExplorer.enableSideBar && view == taskExplorerSideBar && viewItem == script",
Expand Down Expand Up @@ -982,6 +1054,16 @@
"title": "%config.taskExplorer.pathToRuby%",
"description": "%config.taskExplorer.pathToRubyDsc%"
},
"taskExplorer.showExecuteWithArgumentsButton": {
"type": "boolean",
"default": true,
"description": "%config.taskExplorer.showExecuteWithArgumentsButton%"
},
"taskExplorer.showExecuteWithNoTerminalButton": {
"type": "boolean",
"default": true,
"description": "%config.taskExplorer.showExecuteWithNoTerminalButton%"
},
"taskExplorer.showLastTasks": {
"type": "boolean",
"default": true,
Expand Down
5 changes: 5 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
"config.taskExplorer.showLastTasks": "Show the 'last tasks' as a node in the task tree.",
"config.taskExplorer.showRunningTask": "Show the last ran running task in the status bar.",

"config.taskExplorer.showExecuteWithNoTerminalButton": "Show the 'Execute with No Terminal' button inline with the 'Execute' button",
"config.taskExplorer.showExecuteWithArgumentsButton": "Show the 'Execute with Arguments' button inline with the 'Execute' button",

"taskExplorer.parseError": "Task Explorer task detection: failed to parse the file {0}",

"taskdef.task.fileName": "The ant file that target was found in. Can be omitted.",
Expand All @@ -122,6 +125,8 @@
"command.refresh": "Refresh",
"command.run": "Run",
"command.restart": "Restart",
"command.runNoTerm": "Run with no terminal",
"command.runWithArgs": "Run with arguments",
"command.runLastTask": "Run last task",
"command.addToExcludes": "Add to excludes list",
"command.stop": "Stop",
Expand Down
65 changes: 39 additions & 26 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export let appDataPath: string;


const watchers: Map<string, FileSystemWatcher> = new Map();
const watcherDisposables: Map<string, Disposable> = new Map();


export interface TaskExplorerApi
Expand Down Expand Up @@ -252,7 +253,7 @@ async function processConfigChanges(context: ExtensionContext, e: ConfigurationC
refresh = true;
}

if (e.affectsConfiguration("npm.packageManager")) {
if (e.affectsConfiguration("npm.packageManager", null)) {
refresh = true;
}

Expand Down Expand Up @@ -316,16 +317,16 @@ async function registerFileWatchers(context: ExtensionContext)
}

if (configuration.get<boolean>("enableAppPublisher")) {
await registerFileWatcher(context, "app-publisher", "**/.publishrc*", true);
await registerFileWatcher(context, "app-publisher", "**/.publishrc*");
}

if (configuration.get<boolean>("enableBash")) {
await registerFileWatcher(context, "bash", "**/*.[Ss][Hh]", true);
await registerFileWatcher(context, "bash", "**/*.[Ss][Hh]");
}

if (configuration.get<boolean>("enableBatch")) {
await registerFileWatcher(context, "batch", "**/*.[Bb][Aa][Tt]", true);
await registerFileWatcher(context, "batch2", "**/*.[Cc][Mm][Dd]", true);
await registerFileWatcher(context, "batch", "**/*.[Bb][Aa][Tt]");
await registerFileWatcher(context, "batch2", "**/*.[Cc][Mm][Dd]");
}

if (configuration.get<boolean>("enableGradle")) {
Expand All @@ -351,23 +352,23 @@ async function registerFileWatchers(context: ExtensionContext)
}

if (configuration.get<boolean>("enableNsis")) {
await registerFileWatcher(context, "nsis", "**/*.[Nn][Ss][Ii]", true);
await registerFileWatcher(context, "nsis", "**/*.[Nn][Ss][Ii]");
}

if (configuration.get<boolean>("enablePerl")) {
await registerFileWatcher(context, "perl", "**/*.[Pp][Ll]", true);
await registerFileWatcher(context, "perl", "**/*.[Pp][Ll]");
}

if (configuration.get<boolean>("enablePowershell")) {
await registerFileWatcher(context, "powershell", "**/*.[Pp][Ss]1", true);
await registerFileWatcher(context, "powershell", "**/*.[Pp][Ss]1");
}

if (configuration.get<boolean>("enablePython")) {
await registerFileWatcher(context, "python", "**/[Ss][Ee][Tt][Uu][Pp].[Pp][Yy]", true);
await registerFileWatcher(context, "python", "**/[Ss][Ee][Tt][Uu][Pp].[Pp][Yy]");
}

if (configuration.get<boolean>("enableRuby")) {
await registerFileWatcher(context, "ruby", "**/*.[Rr][Bb]", true);
await registerFileWatcher(context, "ruby", "**/*.[Rr][Bb]");
}

if (configuration.get<boolean>("enableTsc")) {
Expand Down Expand Up @@ -477,9 +478,9 @@ async function registerFileWatcher(context: ExtensionContext, taskType: string,
{
util.log("Register file watcher for task type '" + taskType + "'");

let watcher: FileSystemWatcher = watchers.get(taskType);
let taskAlias = taskType;
let taskTypeR = taskType !== "batch2" ? taskType : "batch";
let watcher: FileSystemWatcher = watchers.get(taskTypeR);

if (taskType && taskType.indexOf("ant-") !== -1) {
taskAlias = "ant";
Expand All @@ -492,37 +493,41 @@ async function registerFileWatcher(context: ExtensionContext, taskType: string,
if (workspace.workspaceFolders) {
await cache.buildCache(isScriptType && taskAlias !== "app-publisher" ? "script" : taskAlias, taskTypeR, fileBlob);
}

if (watcher)
{
let watcherDisposable = watcherDisposables.get(taskTypeR);
if (watcherDisposable)
{
watcherDisposable.dispose();
watcherDisposables.delete(taskTypeR);
}
}

if (enabled !== false) {
if (enabled !== false)
{
if (!watcher) {
watcher = workspace.createFileSystemWatcher(fileBlob);
watchers.set(taskTypeR, watcher);
context.subscriptions.push(watcher);
}
if (!isScriptType) {
watcher.onDidChange(async _e => {
watcherDisposables.set(taskTypeR, watcher.onDidChange(async _e => {
logFileWatcherEvent(_e, "change");
await refreshTree(taskTypeR, _e);
});
}));
}
watcher.onDidDelete(async _e => {
watcherDisposables.set(taskTypeR, watcher.onDidDelete(async _e => {
logFileWatcherEvent(_e, "delete");
await cache.removeFileFromCache(taskTypeR, _e);
await refreshTree(taskTypeR, _e);
});
watcher.onDidCreate(async _e => {
}));
watcherDisposables.set(taskTypeR, watcher.onDidCreate(async _e => {
logFileWatcherEvent(_e, "create");
await cache.addFileToCache(taskTypeR, _e);
await refreshTree(taskTypeR, _e);
});
}
else if (watcher) {
if (!isScriptType) {
watcher.onDidChange(_e => undefined);
}
watcher.onDidDelete(_e => undefined);
watcher.onDidCreate(_e => undefined);
}
}));
}
}


Expand Down Expand Up @@ -566,5 +571,13 @@ function registerExplorer(name: string, context: ExtensionContext, enabled?: boo

export async function deactivate()
{
watcherDisposables.forEach((d) => {
d.dispose();
});

watchers.forEach((w) => {
w.dispose();
});

await cache.cancelBuildCache(true);
}
Loading

0 comments on commit 0fb783d

Please sign in to comment.