1
- import { Event , EventEmitter , ExtensionContext , MarkdownString , TextDocument , ThemeIcon , TreeDataProvider , TreeItem , TreeItemCollapsibleState , Uri , commands , window , workspace } from "vscode" ;
1
+ import { Event , EventEmitter , ExtensionContext , FileSystemWatcher , MarkdownString , RelativePattern , TextDocument , ThemeIcon , TreeDataProvider , TreeItem , TreeItemCollapsibleState , Uri , commands , window , workspace } from "vscode" ;
2
2
import { Examples , SQLExample , ServiceInfoLabel , getMergedExamples } from "." ;
3
3
import { notebookFromStatements } from "../../notebooks/logic/openAsNotebook" ;
4
4
import { osDetail } from "../../config" ;
@@ -11,9 +11,12 @@ export class ExampleBrowser implements TreeDataProvider<any> {
11
11
private _onDidChangeTreeData : EventEmitter < TreeItem | undefined | null | void > = new EventEmitter < TreeItem | undefined | null | void > ( ) ;
12
12
readonly onDidChangeTreeData : Event < TreeItem | undefined | null | void > = this . _onDidChangeTreeData . event ;
13
13
14
+ private watchers : FileSystemWatcher [ ] = [ ] ;
14
15
private currentFilter : string | undefined ;
15
16
16
17
constructor ( context : ExtensionContext ) {
18
+ this . setupWatchers ( ) ;
19
+
17
20
context . subscriptions . push (
18
21
commands . registerCommand ( openExampleCommand , ( example : SQLExample ) => {
19
22
if ( example ) {
@@ -153,6 +156,7 @@ export class ExampleBrowser implements TreeDataProvider<any> {
153
156
154
157
workspace . onDidChangeConfiguration ( e => {
155
158
if ( e . affectsConfiguration ( 'vscode-db2i.examples.customExampleDirectories' ) ) {
159
+ this . setupWatchers ( ) ;
156
160
this . refresh ( ) ;
157
161
}
158
162
} )
@@ -190,6 +194,32 @@ export class ExampleBrowser implements TreeDataProvider<any> {
190
194
}
191
195
}
192
196
}
197
+
198
+ setupWatchers ( ) {
199
+ if ( this . watchers ) {
200
+ for ( const watcher of this . watchers ) {
201
+ watcher . dispose ( ) ;
202
+ }
203
+ this . watchers = [ ] ;
204
+ }
205
+
206
+ const existingDirectories = Configuration . get < string [ ] > ( `examples.customExampleDirectories` ) || [ ] ;
207
+ for ( const directory of existingDirectories ) {
208
+ const directoryUri = Uri . file ( directory ) ;
209
+ const relativePattern = new RelativePattern ( directoryUri , '**/*' ) ;
210
+ const watcher = workspace . createFileSystemWatcher ( relativePattern ) ;
211
+ watcher . onDidCreate ( async ( uri ) => {
212
+ this . refresh ( ) ;
213
+ } ) ;
214
+ watcher . onDidChange ( async ( uri ) => {
215
+ this . refresh ( ) ;
216
+ } ) ;
217
+ watcher . onDidDelete ( async ( uri ) => {
218
+ this . refresh ( ) ;
219
+ } ) ;
220
+ this . watchers . push ( watcher ) ;
221
+ }
222
+ }
193
223
}
194
224
195
225
class ExampleGroupItem extends TreeItem {
0 commit comments