@@ -40,14 +40,25 @@ export class FindFilesTool implements ICopilotTool<IFindFilesToolParams> {
40
40
// The input _should_ be a pattern matching inside a workspace, folder, but sometimes we get absolute paths, so try to resolve them
41
41
const pattern = inputGlobToPattern ( options . input . query , this . workspaceService ) ;
42
42
43
- const results = await this . searchService . findFiles ( pattern , undefined , token ) ;
43
+ // try find files with a timeout of 10s
44
+ // TODO: consider making the timeout configurable
45
+ const timeoutInMs = 10_000 ;
46
+ const results = await Promise . race ( [
47
+ this . searchService . findFiles ( pattern , undefined , token ) ,
48
+ new Promise < never > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( 'Timeout in searching files' ) ) , timeoutInMs ) )
49
+ ] ) ;
50
+
44
51
checkCancellation ( token ) ;
45
52
46
53
const maxResults = options . input . maxResults ?? 20 ;
47
54
const resultsToShow = results . slice ( 0 , maxResults ) ;
48
- const result = new ExtendedLanguageModelToolResult ( [
49
- new LanguageModelPromptTsxPart (
50
- await renderPromptElementJSON ( this . instantiationService , FindFilesResult , { fileResults : resultsToShow , totalResults : results . length } , options . tokenizationOptions , token ) ) ] ) ;
55
+ // Render the prompt element with a timeout
56
+ const prompt = await Promise . race ( [
57
+ renderPromptElementJSON ( this . instantiationService , FindFilesResult , { fileResults : resultsToShow , totalResults : results . length } , options . tokenizationOptions , token ) ,
58
+ new Promise < never > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( 'Timeout in rendering prompt element' ) ) , timeoutInMs ) )
59
+ ] ) ;
60
+
61
+ const result = new ExtendedLanguageModelToolResult ( [ new LanguageModelPromptTsxPart ( prompt ) ] ) ;
51
62
const query = `\`${ options . input . query } \`` ;
52
63
result . toolResultMessage = resultsToShow . length === 0 ?
53
64
new MarkdownString ( l10n . t `Searched for files matching ${ query } , no matches` ) :
0 commit comments