@@ -7,13 +7,7 @@ import * as vscode from 'vscode'
77import { FeatureConfigProvider , fs } from '../../../shared'
88import path = require( 'path' )
99import { BM25Document , BM25Okapi } from './rankBm25'
10- import { ToolkitError } from '../../../shared/errors'
11- import {
12- crossFileContextConfig ,
13- supplementalContextTimeoutInMs ,
14- supplemetalContextFetchingTimeoutMsg ,
15- } from '../../models/constants'
16- import { CancellationError } from '../../../shared/utilities/timeoutUtils'
10+ import { crossFileContextConfig , supplementalContextTimeoutInMs } from '../../models/constants'
1711import { isTestFile } from './codeParsingUtil'
1812import { getFileDistance } from '../../../shared/filesystemUtilities'
1913import { getOpenFilesInWindow } from '../../../shared/utilities/editorUtilities'
@@ -77,9 +71,17 @@ export async function fetchSupplementalContextForSrc(
7771 return undefined
7872 }
7973
74+ // fallback to opentabs if projectContext timeout
75+ const opentabsContextPromise = waitUntil (
76+ async function ( ) {
77+ return await fetchOpentabsContext ( editor , cancellationToken )
78+ } ,
79+ { timeout : supplementalContextTimeoutInMs , interval : 5 , truthy : false }
80+ )
81+
8082 // opentabs context will use bm25 and users' open tabs to fetch supplemental context
8183 if ( supplementalContextConfig === 'opentabs' ) {
82- const supContext = ( await fetchOpentabsContext ( editor , cancellationToken ) ) ?? [ ]
84+ const supContext = ( await opentabsContextPromise ) ?? [ ]
8385 return {
8486 supplementalContextItems : supContext ,
8587 strategy : supContext . length === 0 ? 'Empty' : 'opentabs' ,
@@ -126,14 +128,6 @@ export async function fetchSupplementalContextForSrc(
126128 }
127129 }
128130
129- // fallback to opentabs if projectContext timeout for 'default' | 'bm25'
130- const opentabsContextPromise = waitUntil (
131- async function ( ) {
132- return await fetchOpentabsContext ( editor , cancellationToken )
133- } ,
134- { timeout : supplementalContextTimeoutInMs , interval : 5 , truthy : false }
135- )
136-
137131 // global bm25 without repomap
138132 if ( supplementalContextConfig === 'bm25' ) {
139133 const projectBM25Promise = waitUntil (
@@ -207,14 +201,12 @@ export async function fetchOpentabsContext(
207201
208202 // Step 1: Get relevant cross files to refer
209203 const relevantCrossFilePaths = await getCrossFileCandidates ( editor )
210- throwIfCancelled ( cancellationToken )
211204
212205 // Step 2: Split files to chunks with upper bound on chunkCount
213206 // We restrict the total number of chunks to improve on latency.
214207 // Chunk linking is required as we want to pass the next chunk value for matched chunk.
215208 let chunkList : Chunk [ ] = [ ]
216209 for ( const relevantFile of relevantCrossFilePaths ) {
217- throwIfCancelled ( cancellationToken )
218210 const chunks : Chunk [ ] = await splitFileToChunks ( relevantFile , crossFileContextConfig . numberOfLinesEachChunk )
219211 const linkedChunks = linkChunks ( chunks )
220212 chunkList . push ( ...linkedChunks )
@@ -230,14 +222,11 @@ export async function fetchOpentabsContext(
230222 // and Find Best K chunks w.r.t input chunk using BM25
231223 const inputChunk : Chunk = getInputChunk ( editor )
232224 const bestChunks : Chunk [ ] = findBestKChunkMatches ( inputChunk , chunkList , crossFileContextConfig . topK )
233- throwIfCancelled ( cancellationToken )
234225
235226 // Step 4: Transform best chunks to supplemental contexts
236227 const supplementalContexts : CodeWhispererSupplementalContextItem [ ] = [ ]
237228 let totalLength = 0
238229 for ( const chunk of bestChunks ) {
239- throwIfCancelled ( cancellationToken )
240-
241230 totalLength += chunk . nextContent . length
242231
243232 if ( totalLength > crossFileContextConfig . maximumTotalLength ) {
@@ -390,9 +379,3 @@ export async function getCrossFileCandidates(editor: vscode.TextEditor): Promise
390379 return fileToDistance . file
391380 } )
392381}
393-
394- function throwIfCancelled ( token : vscode . CancellationToken ) : void | never {
395- if ( token . isCancellationRequested ) {
396- throw new ToolkitError ( supplemetalContextFetchingTimeoutMsg , { cause : new CancellationError ( 'timeout' ) } )
397- }
398- }
0 commit comments