|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { type IActionContext, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils"; |
| 6 | +import { nonNullValue, type IActionContext, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils"; |
7 | 7 | import { basename, relative } from "path"; |
8 | 8 | import { RelativePattern, Uri, workspace, type OpenDialogOptions, type WorkspaceFolder } from "vscode"; |
9 | 9 | import { browseItem, dockerfileGlobPattern, envFileGlobPattern } from "../constants"; |
@@ -37,40 +37,38 @@ export async function selectWorkspaceFile( |
37 | 37 | options: SelectWorkspaceFileOptions, |
38 | 38 | globPattern?: string |
39 | 39 | ): Promise<string | undefined> { |
40 | | - if (!workspace.workspaceFolders?.length) { |
41 | | - throw new Error(localize('noWorkspaceOpen', 'No workspace is open to search through.')); |
42 | | - } else if (workspace.workspaceFolders.length > 1 && !context.rootFolder) { |
43 | | - throw new Error(localize('couldNotDetermineWorkspaceFolder', 'Could not determine which workspace folder to search through.')); |
44 | | - } |
| 40 | + const quickPicks: IAzureQuickPickItem<string | undefined>[] = []; |
45 | 41 |
|
46 | | - const pattern: RelativePattern = new RelativePattern( |
47 | | - context.rootFolder ?? workspace.workspaceFolders[0], |
48 | | - globPattern ?? '**/*' |
49 | | - ); |
50 | | - const files: Uri[] = await workspace.findFiles(pattern); |
| 42 | + if (context.rootFolder || workspace.workspaceFolders?.length === 1) { |
| 43 | + const pattern: RelativePattern = new RelativePattern( |
| 44 | + context.rootFolder ?? nonNullValue(workspace.workspaceFolders?.[0]), |
| 45 | + globPattern ?? '**/*' |
| 46 | + ); |
| 47 | + const files: Uri[] = await workspace.findFiles(pattern); |
51 | 48 |
|
52 | | - // If dockerfile(s), log the count |
53 | | - if (globPattern === dockerfileGlobPattern || globPattern === `**/${dockerfileGlobPattern}`) { |
54 | | - context.telemetry.properties.dockerfileCount = String(files.length); |
55 | | - } |
| 49 | + // If dockerfile(s), log the count |
| 50 | + if (globPattern === dockerfileGlobPattern || globPattern === `**/${dockerfileGlobPattern}`) { |
| 51 | + context.telemetry.properties.dockerfileCount = String(files.length); |
| 52 | + } |
56 | 53 |
|
57 | | - // If environment variable file(s), log the count |
58 | | - if (globPattern === envFileGlobPattern || globPattern === `**/${envFileGlobPattern}`) { |
59 | | - context.telemetry.properties.environmentVariableFileCount = String(files.length); |
60 | | - } |
| 54 | + // If environment variable file(s), log the count |
| 55 | + if (globPattern === envFileGlobPattern || globPattern === `**/${envFileGlobPattern}`) { |
| 56 | + context.telemetry.properties.environmentVariableFileCount = String(files.length); |
| 57 | + } |
| 58 | + |
| 59 | + if (options.autoSelectIfOne && files.length === 1) { |
| 60 | + return files[0].fsPath; |
| 61 | + } |
61 | 62 |
|
62 | | - if (options.autoSelectIfOne && files.length === 1) { |
63 | | - return files[0].fsPath; |
| 63 | + quickPicks.push(...files.map((uri: Uri) => { |
| 64 | + return { |
| 65 | + label: basename(uri.path), |
| 66 | + description: relative(pattern.baseUri.path, uri.path), |
| 67 | + data: uri.fsPath |
| 68 | + }; |
| 69 | + })); |
64 | 70 | } |
65 | 71 |
|
66 | | - const quickPicks: IAzureQuickPickItem<string | undefined>[] = []; |
67 | | - quickPicks.push(...files.map((uri: Uri) => { |
68 | | - return { |
69 | | - label: basename(uri.path), |
70 | | - description: relative(pattern.baseUri.path, uri.path), |
71 | | - data: uri.fsPath |
72 | | - }; |
73 | | - })); |
74 | 72 | quickPicks.push(browseItem); |
75 | 73 |
|
76 | 74 | const skipForNow: string = 'skipForNow'; |
|
0 commit comments