@@ -28,7 +28,7 @@ import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
2828import { GlobPattern } from 'vs/workbench/api/common/extHostTypeConverters' ;
2929import { Range } from 'vs/workbench/api/common/extHostTypes' ;
3030import { IURITransformerService } from 'vs/workbench/api/common/extHostUriTransformerService' ;
31- import { ITextQueryBuilderOptions } from 'vs/workbench/services/search/common/queryBuilder' ;
31+ import { IFileQueryBuilderOptions , ITextQueryBuilderOptions } from 'vs/workbench/services/search/common/queryBuilder' ;
3232import { IRawFileMatch2 , ITextSearchResult , resultIsMatch } from 'vs/workbench/services/search/common/search' ;
3333import * as vscode from 'vscode' ;
3434import { ExtHostWorkspaceShape , IRelativePatternDto , IWorkspaceData , MainContext , MainThreadMessageOptions , MainThreadMessageServiceShape , MainThreadWorkspaceShape } from './extHost.protocol' ;
@@ -446,27 +446,73 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
446446 findFiles ( include : vscode . GlobPattern | undefined , exclude : vscode . GlobPattern | null | undefined , maxResults : number | undefined , extensionId : ExtensionIdentifier , token : vscode . CancellationToken = CancellationToken . None ) : Promise < vscode . Uri [ ] > {
447447 this . _logService . trace ( `extHostWorkspace#findFiles: fileSearch, extension: ${ extensionId . value } , entryPoint: findFiles` ) ;
448448
449- let excludePatternOrDisregardExcludes : string | false | undefined = undefined ;
449+ let excludeString : string = '' ;
450+ let useFileExcludes = true ;
450451 if ( exclude === null ) {
451- excludePatternOrDisregardExcludes = false ;
452- } else if ( exclude ) {
452+ useFileExcludes = false ;
453+ } else if ( exclude !== undefined ) {
453454 if ( typeof exclude === 'string' ) {
454- excludePatternOrDisregardExcludes = exclude ;
455+ excludeString = exclude ;
455456 } else {
456- excludePatternOrDisregardExcludes = exclude . pattern ;
457+ excludeString = exclude . pattern ;
457458 }
458459 }
459-
460+ return this . _findFilesImpl ( include , undefined , {
461+ exclude : excludeString ,
462+ maxResults,
463+ useDefaultExcludes : useFileExcludes ,
464+ useDefaultSearchExcludes : false ,
465+ useIgnoreFiles : true
466+ } , token ) ;
467+ }
468+
469+ findFiles2 ( filePattern : vscode . GlobPattern | undefined ,
470+ options : vscode . FindFiles2Options = { } ,
471+ extensionId : ExtensionIdentifier ,
472+ token : vscode . CancellationToken = CancellationToken . None ) : Promise < vscode . Uri [ ] > {
473+ this . _logService . trace ( `extHostWorkspace#findFiles2: fileSearch, extension: ${ extensionId . value } , entryPoint: findFiles2` ) ;
474+ return this . _findFilesImpl ( undefined , filePattern , options , token ) ;
475+ }
476+
477+ private async _findFilesImpl (
478+ // the old `findFiles` used `include` to query, but the new `findFiles2` uses `filePattern` to query.
479+ // `filePattern` is the proper way to handle this, since it takes less precedence than the ignore files.
480+ include : vscode . GlobPattern | undefined ,
481+ filePattern : vscode . GlobPattern | undefined ,
482+ options : vscode . FindFiles2Options ,
483+ token : vscode . CancellationToken = CancellationToken . None ) : Promise < vscode . Uri [ ] > {
460484 if ( token && token . isCancellationRequested ) {
461485 return Promise . resolve ( [ ] ) ;
462486 }
463487
464- const { includePattern, folder } = parseSearchInclude ( GlobPattern . from ( include ) ) ;
488+ const excludePattern = ( typeof options . exclude === 'string' ) ? options . exclude :
489+ options . exclude ? options . exclude . pattern : undefined ;
490+
491+ const fileQueries = < IFileQueryBuilderOptions > {
492+ ignoreSymlinks : typeof options . followSymlinks === 'boolean' ? ! options . followSymlinks : undefined ,
493+ disregardIgnoreFiles : typeof options . useIgnoreFiles === 'boolean' ? ! options . useIgnoreFiles : undefined ,
494+ disregardGlobalIgnoreFiles : typeof options . useGlobalIgnoreFiles === 'boolean' ? ! options . useGlobalIgnoreFiles : undefined ,
495+ disregardParentIgnoreFiles : typeof options . useParentIgnoreFiles === 'boolean' ? ! options . useParentIgnoreFiles : undefined ,
496+ disregardExcludeSettings : typeof options . useDefaultExcludes === 'boolean' ? ! options . useDefaultExcludes : false ,
497+ disregardSearchExcludeSettings : typeof options . useDefaultSearchExcludes === 'boolean' ? ! options . useDefaultSearchExcludes : false ,
498+ maxResults : options . maxResults ,
499+ excludePattern : excludePattern ,
500+ _reason : 'startFileSearch'
501+ } ;
502+ let folderToUse : URI | undefined ;
503+ if ( include ) {
504+ const { includePattern, folder } = parseSearchInclude ( GlobPattern . from ( include ) ) ;
505+ folderToUse = folder ;
506+ fileQueries . includePattern = includePattern ;
507+ } else {
508+ const { includePattern, folder } = parseSearchInclude ( GlobPattern . from ( filePattern ) ) ;
509+ folderToUse = folder ;
510+ fileQueries . filePattern = includePattern ;
511+ }
512+
465513 return this . _proxy . $startFileSearch (
466- includePattern ?? null ,
467- folder ?? null ,
468- excludePatternOrDisregardExcludes ?? null ,
469- maxResults ?? null ,
514+ folderToUse ?? null ,
515+ fileQueries ,
470516 token
471517 )
472518 . then ( data => Array . isArray ( data ) ? data . map ( d => URI . revive ( d ) ) : [ ] ) ;
0 commit comments