@@ -3,13 +3,18 @@ import * as elements from './elements';
33import * as services from './services' ;
44import * as models from './models' ;
55import { TaskTreeItem } from './providers/tasks' ;
6+ import { Settings } from './settings' ;
67
78export class TaskExtension {
89 private _taskfile ?: models . Taskfile ;
10+ private _settings : Settings ;
911 private _activityBar : elements . ActivityBar ;
12+ private _watcher : vscode . FileSystemWatcher ;
1013
1114 constructor ( ) {
15+ this . _settings = new Settings ( ) ;
1216 this . _activityBar = new elements . ActivityBar ( ) ;
17+ this . _watcher = vscode . workspace . createFileSystemWatcher ( "**/*.{yml,yaml}" ) ;
1318 }
1419
1520 public async update ( ) : Promise < void > {
@@ -22,6 +27,14 @@ export class TaskExtension {
2227 this . _activityBar . refresh ( this . _taskfile ) ;
2328 }
2429
30+ public async updateAndRefresh ( ) : Promise < void > {
31+ await this . update ( ) . then ( ( ) => {
32+ this . refresh ( ) ;
33+ } ) . catch ( ( err : string ) => {
34+ console . error ( err ) ;
35+ } ) ;
36+ }
37+
2538 public registerCommands ( context : vscode . ExtensionContext ) : void {
2639
2740 // Run task
@@ -46,11 +59,30 @@ export class TaskExtension {
4659
4760 // Refresh tasks
4861 context . subscriptions . push ( vscode . commands . registerCommand ( 'vscode-task.refresh' , ( ) => {
49- this . update ( ) . then ( ( ) => {
50- this . refresh ( ) ;
51- } ) . catch ( ( err : string ) => {
52- console . error ( err ) ;
53- } ) ;
62+ this . updateAndRefresh ( ) ;
5463 } ) ) ;
5564 }
65+
66+ public registerListeners ( context : vscode . ExtensionContext ) : void {
67+ // When a file on the system is changed, created or deleted
68+ this . _watcher . onDidChange ( async _ => { await this . _onDidTaskfileChange ( ) ; } ) ;
69+ this . _watcher . onDidCreate ( async _ => { await this . _onDidTaskfileChange ( ) ; } ) ;
70+ this . _watcher . onDidDelete ( async _ => { await this . _onDidTaskfileChange ( ) ; } ) ;
71+
72+ // Listen for configuration changes
73+ vscode . workspace . onDidChangeConfiguration ( event => { this . _onDidChangeConfiguration ( event ) ; } ) ;
74+ }
75+
76+ private async _onDidTaskfileChange ( ) {
77+ // If manual updating is turned off (update on save)
78+ if ( this . _settings . updateOn !== "manual" ) {
79+ await this . updateAndRefresh ( ) ;
80+ }
81+ }
82+
83+ private _onDidChangeConfiguration ( event : vscode . ConfigurationChangeEvent ) {
84+ if ( event . affectsConfiguration ( "task" ) ) {
85+ this . _settings . update ( ) ;
86+ }
87+ }
5688}
0 commit comments