@@ -59,7 +59,7 @@ export async function fetchSupplementalContextForTest(
59
59
// TODO (Metrics): 1. Total number of calls to fetchSupplementalContextForTest
60
60
throwIfCancelled ( cancellationToken )
61
61
62
- let crossSourceFile = await findSourceFileByName ( editor , languageConfig )
62
+ let crossSourceFile = await findSourceFileByName ( editor , languageConfig , cancellationToken )
63
63
if ( crossSourceFile ) {
64
64
// TODO (Metrics): 2. Success count for fetchSourceFileByName (find source file by name)
65
65
return generateSupplementalContextFromFocalFile ( crossSourceFile , cancellationToken )
@@ -102,7 +102,13 @@ async function findSourceFileByContent(
102
102
) : Promise < string | undefined > {
103
103
const testFileContent = fs . readFileSync ( editor . document . fileName , 'utf-8' )
104
104
const testElementList = extractFunctions ( testFileContent , languageConfig . functionExtractionPattern )
105
+
106
+ throwIfCancelled ( cancellationToken )
107
+
105
108
testElementList . push ( ...extractClasses ( editor . document . fileName , languageConfig . classExtractionPattern ) )
109
+
110
+ throwIfCancelled ( cancellationToken )
111
+
106
112
let sourceFilePath : string | undefined = undefined
107
113
let maxMatchCount = 0
108
114
@@ -113,6 +119,8 @@ async function findSourceFileByContent(
113
119
114
120
const relevantFilePaths = await getRelevantUtgFiles ( editor )
115
121
122
+ throwIfCancelled ( cancellationToken )
123
+
116
124
// TODO (Metrics):Add metrics for relevantFilePaths length
117
125
relevantFilePaths . forEach ( filePath => {
118
126
throwIfCancelled ( cancellationToken )
@@ -144,7 +152,8 @@ async function getRelevantUtgFiles(editor: vscode.TextEditor): Promise<string[]>
144
152
145
153
async function findSourceFileByName (
146
154
editor : vscode . TextEditor ,
147
- languageConfig : utgLanguageConfig
155
+ languageConfig : utgLanguageConfig ,
156
+ cancellationToken : vscode . CancellationToken
148
157
) : Promise < string | undefined > {
149
158
const uri = editor . document . uri
150
159
const workspaceFolder = vscode . workspace . getWorkspaceFolder ( uri )
@@ -157,6 +166,8 @@ async function findSourceFileByName(
157
166
basenameSuffix = match [ 1 ] || match [ 2 ]
158
167
}
159
168
169
+ throwIfCancelled ( cancellationToken )
170
+
160
171
// Assuming the convention of using similar path structure for test and src files.
161
172
const dirPath = path . dirname ( editor . document . uri . fsPath )
162
173
let newPath = ''
@@ -174,12 +185,16 @@ async function findSourceFileByName(
174
185
return newPath
175
186
}
176
187
188
+ throwIfCancelled ( cancellationToken )
189
+
177
190
// TODO: vscode.workspace.findFiles is preferred but doesn't seems to be working for now.
178
191
// TODO: Enable this later.
179
192
//const sourceFiles =
180
193
// await vscode.workspace.findFiles(`${projectPath}/**/${basenameSuffix}${languageConfig.extension}`);
181
194
const sourceFiles = await globPromise ( `${ projectPath } /**/${ basenameSuffix } ${ languageConfig . extension } ` )
182
195
196
+ throwIfCancelled ( cancellationToken )
197
+
183
198
if ( sourceFiles . length > 0 ) {
184
199
return sourceFiles [ 0 ]
185
200
}
0 commit comments