1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
- import { CancellationToken , commands } from "vscode" ;
4
+
5
+ import * as minimatch from "minimatch" ;
6
+ import { CancellationToken , Uri , commands , workspace } from "vscode" ;
5
7
import { Commands , executeJavaLanguageServerCommand } from "../commands" ;
6
8
import { IClasspath } from "../tasks/buildArtifact/IStepMetadata" ;
7
9
import { IMainClassInfo } from "../tasks/buildArtifact/ResolveMainClassExecutor" ;
@@ -20,8 +22,32 @@ export namespace Jdtls {
20
22
return commands . executeCommand ( Commands . EXECUTE_WORKSPACE_COMMAND , Commands . JAVA_PROJECT_REFRESH_LIB_SERVER , params ) ;
21
23
}
22
24
23
- export async function getPackageData ( params : { [ key : string ] : any } ) : Promise < INodeData [ ] > {
24
- return await commands . executeCommand ( Commands . EXECUTE_WORKSPACE_COMMAND , Commands . JAVA_GETPACKAGEDATA , params ) || [ ] ;
25
+ export async function getPackageData ( params : IPackageDataParam ) : Promise < INodeData [ ] > {
26
+ const uri : Uri | null = ! params . projectUri ? null : Uri . parse ( params . projectUri ) ;
27
+ const excludePatterns : { [ key : string ] : boolean } | undefined = workspace . getConfiguration ( "files" , uri ) . get ( "exclude" ) ;
28
+
29
+ let nodeData : INodeData [ ] = await commands . executeCommand ( Commands . EXECUTE_WORKSPACE_COMMAND ,
30
+ Commands . JAVA_GETPACKAGEDATA , params ) || [ ] ;
31
+ if ( excludePatterns && nodeData . length ) {
32
+ const uriOfChildren : string [ ] = nodeData . map ( ( node : INodeData ) => node . uri ) . filter ( Boolean ) as string [ ] ;
33
+ const urisToExclude : Set < string > = new Set < string > ( ) ;
34
+ for ( const pattern in excludePatterns ) {
35
+ if ( excludePatterns [ pattern ] ) {
36
+ const toExclude : string [ ] = minimatch . match ( uriOfChildren , pattern ) ;
37
+ toExclude . forEach ( ( uri : string ) => urisToExclude . add ( uri ) ) ;
38
+ }
39
+ }
40
+
41
+ if ( urisToExclude . size ) {
42
+ nodeData = nodeData . filter ( ( node : INodeData ) => {
43
+ if ( ! node . uri ) {
44
+ return true ;
45
+ }
46
+ return ! urisToExclude . has ( node . uri ) ;
47
+ } )
48
+ }
49
+ }
50
+ return nodeData ;
25
51
}
26
52
27
53
export async function resolvePath ( params : string ) : Promise < INodeData [ ] > {
@@ -49,3 +75,8 @@ export namespace Jdtls {
49
75
return < Promise < string [ ] > > executeJavaLanguageServerCommand ( Commands . JAVA_RESOLVE_BUILD_FILES ) ;
50
76
}
51
77
}
78
+
79
+ interface IPackageDataParam {
80
+ projectUri : string | undefined ,
81
+ [ key : string ] : any ,
82
+ }
0 commit comments