(
logger: Logger,
placeHolder: string,
{
selection,
flutterOnly = false,
// TODO(dantup): Consider making this required.
onlyShowWorkspaceRoots = false
}: {
selection?: vs.Uri;
flutterOnly?: boolean;
onlyShowWorkspaceRoots?: boolean;
} = {})
| 13 | import { getExcludedFolders } from "../../utils"; |
| 14 | |
| 15 | export async function getFolderToRunCommandIn( |
| 16 | logger: Logger, |
| 17 | placeHolder: string, |
| 18 | { |
| 19 | selection, |
| 20 | flutterOnly = false, |
| 21 | // TODO(dantup): Consider making this required. |
| 22 | onlyShowWorkspaceRoots = false |
| 23 | }: { |
| 24 | selection?: vs.Uri; |
| 25 | flutterOnly?: boolean; |
| 26 | onlyShowWorkspaceRoots?: boolean; |
| 27 | } = {}): Promise<string | undefined> { |
| 28 | // Attempt to find a project based on the supplied folder of active file. |
| 29 | let file = selection && fsPath(selection); |
| 30 | if (!file) { |
| 31 | const editor = getActiveRealFileEditor(); |
| 32 | if (editor) |
| 33 | file = fsPath(editor.document.uri); |
| 34 | } |
| 35 | const folder = file && locateBestProjectRoot(file, !!selection); |
| 36 | |
| 37 | if (folder) |
| 38 | return folder; |
| 39 | |
| 40 | // Otherwise look for what projects we have. |
| 41 | const selectableFolders = (await getAllProjectFolders(logger, getExcludedFolders, { requirePubspec: true, sort: true, searchDepth: config.projectSearchDepth })) |
| 42 | .filter(flutterOnly ? isFlutterProjectFolder : () => true); |
| 43 | |
| 44 | if (!selectableFolders?.length) { |
| 45 | const projectTypes = flutterOnly ? "Flutter" : "Dart/Flutter"; |
| 46 | void vs.window.showWarningMessage(`No ${projectTypes} project roots were found. Do you have a pubspec.yaml file?`); |
| 47 | return undefined; |
| 48 | } |
| 49 | |
| 50 | const selectableFolderInfo: PubWorkspaceOrPackageFolderInfo[] = onlyShowWorkspaceRoots |
| 51 | ? getPubWorkspaceOrPackageFolderInfo(selectableFolders) |
| 52 | : selectableFolders.map((folder) => ({ path: folder })); |
| 53 | |
| 54 | return showPackagePicker(selectableFolderInfo, placeHolder); // TODO: What if the user didn't pick anything? |
| 55 | } |
| 56 | |
| 57 | export async function getProjectSelection(logger: Logger, placeHolder: string): Promise<string[] | undefined> { |
| 58 | // Attempt to find a project based on the supplied folder of active file so we can pre-selected it. |
no test coverage detected