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

Function getFolderToRunCommandIn

src/extension/utils/vscode/projects.ts:15–55  ·  view source on GitHub ↗
(
	logger: Logger,
	placeHolder: string,
	{
		selection,
		flutterOnly = false,
		// TODO(dantup): Consider making this required.
		onlyShowWorkspaceRoots = false
	}: {
		selection?: vs.Uri;
		flutterOnly?: boolean;
		onlyShowWorkspaceRoots?: boolean;
	} = {})

Source from the content-addressed store, hash-verified

13import { getExcludedFolders } from "../../utils";
14
15export 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
57export 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.

Callers 8

packages.test.tsFile · 0.90
runTaskFunction · 0.90
listOutdatedPackagesMethod · 0.90
flutterCleanMethod · 0.90
flutterCreateMethod · 0.90

Calls 6

fsPathFunction · 0.90
getActiveRealFileEditorFunction · 0.90
locateBestProjectRootFunction · 0.90
getAllProjectFoldersFunction · 0.90
showPackagePickerFunction · 0.85

Tested by

no test coverage detected