Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/utils/FileSystem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { t } from "@vscode/l10n";
import { dirname, join } from "path";
import { commands, env, FileType, Uri, window, workspace, type CancellationToken } from "vscode";
import { commands, env, FileType, Uri, window, workspace, type CancellationToken, type OpenDialogOptions } from "vscode";
import type { GetWorkspaceFolderOptions, TaskData } from "../@types";
import { BLOCKED_FILES } from "./constants";
import lazy from "./lazy";
Expand All @@ -23,6 +23,8 @@ export interface FileSystemOptions {
ignoreList?: string[]
}

export type OpenFolderDialogOptions = Omit<OpenDialogOptions, "canSelectFiles" | "canSelectFolders" | "canSelectMany">

export default class FileSystem {
static get singleWorkspaceFolder() {
const folders = workspace.workspaceFolders;
Expand All @@ -33,20 +35,6 @@ export default class FileSystem {
return Boolean(workspace.workspaceFolders?.length);
}

static async getFolderDialog(task?: TaskData | null, title?: string, openLabel?: string) {
task?.progress.report({ increment: -1, message: t("folder.get.one") });

const uris = await window.showOpenDialog({
canSelectFolders: true,
title,
openLabel,
});

if (uris?.length) task?.progress.report({ message: t("folder.selected") });

return uris?.at(0);
}

static async findIgnoreFile(filename: string, ignoreList?: string | string[] | Set<string>, token?: CancellationToken) {
if (!ignoreList) ignoreList = lazyDefaultBlockedFilesPattern();

Expand Down Expand Up @@ -79,6 +67,21 @@ export default class FileSystem {
return Array.from(result);
}

static async getFolderDialog(task?: TaskData | null, options?: OpenFolderDialogOptions) {
task?.progress.report({ increment: -1, message: t("folder.get.one") });

const uris = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
...options,
});

if (uris?.length) task?.progress.report({ message: t("folder.selected") });

return uris?.at(0);
}

static async getWorkspaceFolder(options?: GetWorkspaceFolderOptions | null): Promise<Uri | undefined> {
options ??= {};

Expand Down
Loading