|
3 | 3 | * SPDX-License-Identifier: Apache-2.0
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -import { glob } from 'glob' |
7 | 6 | import * as fs from 'fs-extra'
|
8 | 7 | import * as path from 'path'
|
9 | 8 | import * as vscode from 'vscode'
|
@@ -115,7 +114,7 @@ function generateSupplementalContextFromFocalFile(
|
115 | 114 | strategy: UtgStrategy,
|
116 | 115 | cancellationToken: vscode.CancellationToken
|
117 | 116 | ): CodeWhispererSupplementalContextItem[] {
|
118 |
| - const fileContent = fs.readFileSync(vscode.Uri.file(filePath!).fsPath, 'utf-8') |
| 117 | + const fileContent = fs.readFileSync(vscode.Uri.parse(filePath!).fsPath, 'utf-8') |
119 | 118 |
|
120 | 119 | // DO NOT send code chunk with empty content
|
121 | 120 | if (fileContent.trim().length === 0) {
|
@@ -190,9 +189,6 @@ async function findSourceFileByName(
|
190 | 189 | languageConfig: utgLanguageConfig,
|
191 | 190 | cancellationToken: vscode.CancellationToken
|
192 | 191 | ): Promise<string | undefined> {
|
193 |
| - const uri = editor.document.uri |
194 |
| - const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri) |
195 |
| - const projectPath = workspaceFolder ? workspaceFolder.uri.fsPath : path.dirname(uri.fsPath) |
196 | 192 | const testFileName = path.basename(editor.document.fileName)
|
197 | 193 |
|
198 | 194 | let basenameSuffix = testFileName
|
@@ -222,25 +218,16 @@ async function findSourceFileByName(
|
222 | 218 |
|
223 | 219 | throwIfCancelled(cancellationToken)
|
224 | 220 |
|
225 |
| - // TODO: vscode.workspace.findFiles is preferred but doesn't seems to be working for now. |
226 |
| - // TODO: Enable this later. |
227 |
| - //const sourceFiles = |
228 |
| - // await vscode.workspace.findFiles(`${projectPath}/**/${basenameSuffix}${languageConfig.extension}`); |
229 |
| - const sourceFiles = await globPromise(`${projectPath}/**/${basenameSuffix}${languageConfig.extension}`) |
| 221 | + const sourceFiles = await vscode.workspace.findFiles(`**/${basenameSuffix}${languageConfig.extension}`) |
230 | 222 |
|
231 | 223 | throwIfCancelled(cancellationToken)
|
232 | 224 |
|
233 | 225 | if (sourceFiles.length > 0) {
|
234 |
| - return sourceFiles[0] |
| 226 | + return sourceFiles[0].toString() |
235 | 227 | }
|
236 | 228 | return undefined
|
237 | 229 | }
|
238 | 230 |
|
239 |
| -// TODO: Replace this by vscode.workspace.findFiles |
240 |
| -function globPromise(pattern: string): Promise<string[]> { |
241 |
| - return glob(pattern) |
242 |
| -} |
243 |
| - |
244 | 231 | function throwIfCancelled(token: vscode.CancellationToken): void | never {
|
245 | 232 | if (token.isCancellationRequested) {
|
246 | 233 | throw new ToolkitError(supplemetalContextFetchingTimeoutMsg, { cause: new CancellationError('timeout') })
|
|
0 commit comments