Fix workspace utils file selection logic (#727)

This commit is contained in:
Matthew Fisher 2024-08-20 22:44:53 -07:00 коммит произвёл GitHub
Родитель 8d85381db3
Коммит 9f85e22c2c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 34 добавлений и 36 удалений

Просмотреть файл

@ -46,7 +46,7 @@ export class ImageSourceListStep extends AzureWizardPromptStep<ImageSourceContex
picks.unshift({ label: imageSourceLabels[1], detail: imageSourceDetails[1], data: ImageSource.QuickstartImage, suppressPersistence: true });
}
const isVirtualWorkspace = workspace.workspaceFolders && workspace.workspaceFolders.every(f => f.uri.scheme !== 'file');
const isVirtualWorkspace = !!workspace.workspaceFolders?.length && workspace.workspaceFolders.every(f => f.uri.scheme !== 'file');
if (env.uiKind === UIKind.Desktop && !isVirtualWorkspace) {
picks.push({ label: imageSourceLabels[2], detail: imageSourceDetails[2], data: ImageSource.RemoteAcrBuild, suppressPersistence: true })
}

Просмотреть файл

@ -13,7 +13,7 @@ import { type BuildImageInAzureImageSourceContext } from './BuildImageInAzureIma
export class RootFolderStep extends AzureWizardPromptStep<BuildImageInAzureImageSourceContext> {
public async prompt(context: BuildImageInAzureImageSourceContext): Promise<void> {
const prompt: string = localize('selectRootWorkspace', 'Select a project with a Dockerfile');
const prompt: string = localize('selectRootWorkspace', 'Select the project\'s root directory');
const rootFolder: WorkspaceFolder | undefined = await getRootWorkspaceFolder(context, prompt);
if (!rootFolder) {

Просмотреть файл

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type IActionContext, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { nonNullValue, type IActionContext, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { basename, relative } from "path";
import { RelativePattern, Uri, workspace, type OpenDialogOptions, type WorkspaceFolder } from "vscode";
import { browseItem, dockerfileGlobPattern, envFileGlobPattern } from "../constants";
@ -37,40 +37,38 @@ export async function selectWorkspaceFile(
options: SelectWorkspaceFileOptions,
globPattern?: string
): Promise<string | undefined> {
if (!workspace.workspaceFolders?.length) {
throw new Error(localize('noWorkspaceOpen', 'No workspace is open to search through.'));
} else if (workspace.workspaceFolders.length > 1 && !context.rootFolder) {
throw new Error(localize('couldNotDetermineWorkspaceFolder', 'Could not determine which workspace folder to search through.'));
}
const pattern: RelativePattern = new RelativePattern(
context.rootFolder ?? workspace.workspaceFolders[0],
globPattern ?? '**/*'
);
const files: Uri[] = await workspace.findFiles(pattern);
// If dockerfile(s), log the count
if (globPattern === dockerfileGlobPattern || globPattern === `**/${dockerfileGlobPattern}`) {
context.telemetry.properties.dockerfileCount = String(files.length);
}
// If environment variable file(s), log the count
if (globPattern === envFileGlobPattern || globPattern === `**/${envFileGlobPattern}`) {
context.telemetry.properties.environmentVariableFileCount = String(files.length);
}
if (options.autoSelectIfOne && files.length === 1) {
return files[0].fsPath;
}
const quickPicks: IAzureQuickPickItem<string | undefined>[] = [];
quickPicks.push(...files.map((uri: Uri) => {
return {
label: basename(uri.path),
description: relative(pattern.baseUri.path, uri.path),
data: uri.fsPath
};
}));
if (context.rootFolder || workspace.workspaceFolders?.length === 1) {
const pattern: RelativePattern = new RelativePattern(
context.rootFolder ?? nonNullValue(workspace.workspaceFolders?.[0]),
globPattern ?? '**/*'
);
const files: Uri[] = await workspace.findFiles(pattern);
// If dockerfile(s), log the count
if (globPattern === dockerfileGlobPattern || globPattern === `**/${dockerfileGlobPattern}`) {
context.telemetry.properties.dockerfileCount = String(files.length);
}
// If environment variable file(s), log the count
if (globPattern === envFileGlobPattern || globPattern === `**/${envFileGlobPattern}`) {
context.telemetry.properties.environmentVariableFileCount = String(files.length);
}
if (options.autoSelectIfOne && files.length === 1) {
return files[0].fsPath;
}
quickPicks.push(...files.map((uri: Uri) => {
return {
label: basename(uri.path),
description: relative(pattern.baseUri.path, uri.path),
data: uri.fsPath
};
}));
}
quickPicks.push(browseItem);
const skipForNow: string = 'skipForNow';