@@ -11,6 +11,7 @@ import { IPromptPathRepresentationService } from '../../../platform/prompts/comm
11
11
import { ISearchService } from '../../../platform/search/common/searchService' ;
12
12
import { IWorkspaceService } from '../../../platform/workspace/common/workspaceService' ;
13
13
import { asArray } from '../../../util/vs/base/common/arrays' ;
14
+ import { raceCancellation , raceTimeout } from '../../../util/vs/base/common/async' ;
14
15
import { CancellationToken } from '../../../util/vs/base/common/cancellation' ;
15
16
import { count } from '../../../util/vs/base/common/strings' ;
16
17
import { URI } from '../../../util/vs/base/common/uri' ;
@@ -55,22 +56,35 @@ export class FindTextInFilesTool implements ICopilotTool<IFindTextInFilesToolPar
55
56
// try find text with a timeout of 10s
56
57
// TODO: consider making the timeout configurable
57
58
const timeoutInMs = 10_000 ;
58
- let results = await Promise . race ( [
59
- this . searchAndCollectResults ( options . input . query , isRegExp , patterns , maxResults , token ) ,
60
- new Promise < never > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( "Timeout in searching text in files" ) ) , timeoutInMs ) ) ] ) ;
59
+ let results = await raceTimeout (
60
+ raceCancellation (
61
+ this . searchAndCollectResults ( options . input . query , isRegExp , patterns , maxResults , token ) ,
62
+ token
63
+ ) ,
64
+ timeoutInMs
65
+ ) ;
66
+
67
+ if ( results && ! results . length && queryIsValidRegex ) {
68
+ results = await raceTimeout (
69
+ raceCancellation (
70
+ this . searchAndCollectResults ( options . input . query , ! isRegExp , patterns , maxResults , token ) ,
71
+ token
72
+ ) ,
73
+ timeoutInMs
74
+ ) ;
75
+ }
61
76
62
- checkCancellation ( token ) ;
63
- if ( ! results . length && queryIsValidRegex ) {
64
- results = await Promise . race ( [
65
- this . searchAndCollectResults ( options . input . query , ! isRegExp , patterns , maxResults , token ) ,
66
- new Promise < never > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( "Timeout in searching text in files" ) ) , timeoutInMs ) ) ] ) ;
77
+ if ( results === undefined ) {
78
+ throw new Error ( 'Timeout in searching files' ) ;
67
79
}
68
80
69
- checkCancellation ( token ) ;
70
- const prompt = await Promise . race ( [
71
- renderPromptElementJSON ( this . instantiationService , FindTextInFilesResult , { textResults : results , maxResults, askedForTooManyResults : Boolean ( askedForTooManyResults ) } , options . tokenizationOptions , token ) ,
72
- new Promise < never > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( 'Timeout in rendering prompt element' ) ) , timeoutInMs ) )
73
- ] ) ;
81
+ const prompt = await raceTimeout (
82
+ raceCancellation (
83
+ renderPromptElementJSON ( this . instantiationService , FindTextInFilesResult , { textResults : results , maxResults, askedForTooManyResults : Boolean ( askedForTooManyResults ) } , options . tokenizationOptions , token ) ,
84
+ token
85
+ ) ,
86
+ timeoutInMs
87
+ ) ;
74
88
75
89
const result = new ExtendedLanguageModelToolResult ( [ new LanguageModelPromptTsxPart ( prompt ) ] ) ;
76
90
const textMatches = results . flatMap ( r => {
0 commit comments