@@ -51,14 +51,28 @@ export class FindTextInFilesTool implements ICopilotTool<IFindTextInFilesToolPar
51
51
const maxResults = Math . min ( options . input . maxResults ?? 20 , MaxResultsCap ) ;
52
52
const isRegExp = options . input . isRegexp ?? true ;
53
53
const queryIsValidRegex = this . isValidRegex ( options . input . query ) ;
54
- let results = await this . searchAndCollectResults ( options . input . query , isRegExp , patterns , maxResults , token ) ;
54
+
55
+ // try find text with a timeout of 10s
56
+ // TODO: consider making the timeout configurable
57
+ 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 ) ) ] ) ;
61
+
62
+ checkCancellation ( token ) ;
55
63
if ( ! results . length && queryIsValidRegex ) {
56
- results = await this . searchAndCollectResults ( options . input . query , ! isRegExp , patterns , maxResults , token ) ;
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 ) ) ] ) ;
57
67
}
58
68
59
- const result = new ExtendedLanguageModelToolResult ( [
60
- new LanguageModelPromptTsxPart (
61
- await renderPromptElementJSON ( this . instantiationService , FindTextInFilesResult , { textResults : results , maxResults, askedForTooManyResults : Boolean ( askedForTooManyResults ) } , options . tokenizationOptions , token ) ) ] ) ;
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
+ ] ) ;
74
+
75
+ const result = new ExtendedLanguageModelToolResult ( [ new LanguageModelPromptTsxPart ( prompt ) ] ) ;
62
76
const textMatches = results . flatMap ( r => {
63
77
if ( 'ranges' in r ) {
64
78
return asArray ( r . ranges ) . map ( rangeInfo => new Location ( r . uri , rangeInfo . sourceRange ) ) ;
0 commit comments