2
2
// Licensed under the MIT license.
3
3
4
4
import * as path from "path" ;
5
- import { commands , Disposable , FileSystemWatcher , Uri , workspace } from "vscode" ;
5
+ import { commands , Disposable , FileSystemWatcher , RelativePattern , Uri , workspace } from "vscode" ;
6
6
import { instrumentOperation } from "vscode-extension-telemetry-wrapper" ;
7
7
import { Commands } from "./commands" ;
8
8
import { NodeKind } from "./java/nodeData" ;
@@ -19,10 +19,11 @@ class SyncHandler implements Disposable {
19
19
private disposables : Disposable [ ] = [ ] ;
20
20
21
21
public updateFileWatcher ( autoRefresh ?: boolean ) : void {
22
+ this . dispose ( ) ;
22
23
if ( autoRefresh ) {
23
24
instrumentOperation ( ENABLE_AUTO_REFRESH , ( ) => this . enableAutoRefresh ( ) ) ( ) ;
24
25
} else {
25
- instrumentOperation ( DISABLE_AUTO_REFRESH , ( ) => this . dispose ( ) ) ( ) ;
26
+ instrumentOperation ( DISABLE_AUTO_REFRESH , ( ) => { } ) ( ) ;
26
27
}
27
28
}
28
29
@@ -40,9 +41,25 @@ class SyncHandler implements Disposable {
40
41
this . refresh ( ) ;
41
42
} ) ) ;
42
43
43
- const fileSystemWatcher : FileSystemWatcher = workspace . createFileSystemWatcher ( "**/{*.java,src/**}" ) ;
44
- this . setupWatchers ( fileSystemWatcher ) ;
45
- this . disposables . push ( fileSystemWatcher ) ;
44
+ try {
45
+ const result : IListCommandResult | undefined = await commands . executeCommand < IListCommandResult > ( Commands . EXECUTE_WORKSPACE_COMMAND ,
46
+ Commands . JAVA_PROJECT_LIST_SOURCE_PATHS ) ;
47
+ if ( ! result || ! result . status || ! result . data || result . data . length === 0 ) {
48
+ throw new Error ( "Failed to list the source paths" ) ;
49
+ }
50
+
51
+ for ( const sourcePathData of result . data ) {
52
+ const normalizedPath : string = Uri . file ( sourcePathData . path ) . fsPath ;
53
+ const pattern : RelativePattern = new RelativePattern ( normalizedPath , "**/*" ) ;
54
+ const watcher : FileSystemWatcher = workspace . createFileSystemWatcher ( pattern ) ;
55
+ this . disposables . push ( watcher ) ;
56
+ this . setupWatchers ( watcher ) ;
57
+ }
58
+ } catch ( e ) {
59
+ const fileSystemWatcher : FileSystemWatcher = workspace . createFileSystemWatcher ( "**/{*.java,src/**}" ) ;
60
+ this . disposables . push ( fileSystemWatcher ) ;
61
+ this . setupWatchers ( fileSystemWatcher ) ;
62
+ }
46
63
}
47
64
48
65
private setupWatchers ( watcher : FileSystemWatcher ) : void {
@@ -100,4 +117,17 @@ class SyncHandler implements Disposable {
100
117
}
101
118
}
102
119
120
+ interface ISourcePath {
121
+ path : string ;
122
+ displayPath : string ;
123
+ projectName : string ;
124
+ projectType : string ;
125
+ }
126
+
127
+ interface IListCommandResult {
128
+ status : boolean ;
129
+ message : string ;
130
+ data ?: ISourcePath [ ] ;
131
+ }
132
+
103
133
export const syncHandler : SyncHandler = new SyncHandler ( ) ;
0 commit comments