MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / showPackagePicker

Function showPackagePicker

src/extension/utils/vscode/projects.ts:79–104  ·  view source on GitHub ↗
(folders: PubWorkspaceOrPackageFolderInfo[], placeHolder: string)

Source from the content-addressed store, hash-verified

77}
78
79async function showPackagePicker(folders: PubWorkspaceOrPackageFolderInfo[], placeHolder: string): Promise<string | undefined> {
80 // No point asking the user if there's only one.
81 if (folders.length === 1) {
82 return folders[0]?.path;
83 }
84
85 const items = folders.map((folderInfo) => {
86 const folderPath = folderInfo.path;
87 const workspaceFolder = vs.workspace.getWorkspaceFolder(Uri.file(folderPath));
88 const workspacePathParent = workspaceFolder
89 ? path.dirname(fsPath(workspaceFolder.uri))
90 : path.dirname(folderPath);
91 const detail = folderInfo.workspacePackageCount
92 ? `Pub Workspace, ${folderInfo.workspacePackageCount} package${folderInfo.workspacePackageCount === 1 ? "" : "s"}`
93 : undefined;
94 return {
95 description: homeRelativePath(workspacePathParent),
96 label: path.relative(workspacePathParent, folderPath),
97 detail,
98 path: folderPath,
99 } satisfies vs.QuickPickItem & { path: string };
100 }).filter(notUndefined);
101
102 const selectedFolder = await vs.window.showQuickPick(items, { placeHolder });
103 return selectedFolder?.path;
104}
105
106async function showFolderMultiPicker(selectableFolderPaths: string[], prePickedFolders: Set<string> | undefined, placeHolder: string): Promise<string[] | undefined> {
107 // No point asking the user if there's only one.

Callers 1

getFolderToRunCommandInFunction · 0.85

Calls 2

fsPathFunction · 0.90
homeRelativePathFunction · 0.90

Tested by

no test coverage detected