in src/commands/createNewProject/verifyIsProject.ts [34:67]
export async function tryGetFunctionProjectRoot(context: IActionContext, workspaceFolder: WorkspaceFolder | string, promptBehavior: MultiProjectPromptBehavior = 'silent'): Promise<string | undefined> {
return await telemetryUtils.runWithDurationTelemetry(context, 'tryGetProject', async () => {
const folderPath = typeof workspaceFolder === 'string' ? workspaceFolder : workspaceFolder.uri.fsPath;
if (!getWorkspaceSetting<boolean>('suppressProject', workspaceFolder)) {
const subpath: string | undefined = getWorkspaceSetting(projectSubpathSetting, workspaceFolder);
if (subpath) {
return path.join(folderPath, subpath);
} else if (await fse.pathExists(folderPath)) {
if (await isFunctionProject(folderPath)) {
return folderPath;
} else {
const hostJsonUris = await findFiles(workspaceFolder, `*/${hostFileName}`);
if (hostJsonUris.length !== 1) {
// NOTE: If we found a single project at the root or one level down, we will use that without searching any further.
// This will reduce false positives in the case of compiled languages like C# where a 'host.json' file is often copied to a build/publish directory a few levels down
// It also maintains consistent historical behavior by giving that project priority because we used to _only_ look at the root and one level down
hostJsonUris.push(...await findFiles(workspaceFolder, `*/*/**/${hostFileName}`));
}
const projectPaths = hostJsonUris.map(uri => path.dirname(uri.fsPath));
if (projectPaths.length === 1) {
return projectPaths[0];
} else if (projectPaths.length > 1 && promptBehavior !== 'silent') {
const subpaths = projectPaths.map(p => path.relative(folderPath, p));
const pickedSubpath = await promptForProjectSubpath(context, folderPath, subpaths, promptBehavior);
return path.join(folderPath, pickedSubpath);
}
}
}
}
return undefined;
});
}