import * as path from 'path' ; import * as vscode from 'vscode' ; import { IActionContext , IAzureQuickPickItem } from 'vscode-azureextensionui' ; import { localize } from '../localize' ; export async function selectWorkspaceFolder ( context , placeHolder ) { return await selectWorkspaceItem ( context , placeHolder , { canSelectFiles : false , canSelectFolders : true , canSelectMany : false , defaultUri : vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 ? vscode . workspace . workspaceFolders [ 0 ] . uri : undefined , openLabel : localize ( 'select' , 'Select' ) } ) ; } export async function selectWorkspaceFile ( context , placeHolder , fileExtensions ? ) { const filters = { } ; if ( fileExtensions ) { filters . Artifacts = fileExtensions ; } return await selectWorkspaceItem ( context , placeHolder , { canSelectFiles : true , canSelectFolders : false , canSelectMany : false , openLabel : localize ( 'select' , 'Select' ) , filters : filters } ) ; } export async function selectWorkspaceItem ( context , placeHolder , options ) { let folder ; if ( vscode . workspace . workspaceFolders ) { const folderPicks = await Promise . all ( vscode . workspace . workspaceFolders . map ( ( f ) => { return { label : path . basename ( f . uri . fsPath ) , description : f . uri . fsPath , data : f } ; } ) ) ; folderPicks . push ( { label : localize ( 'azFunc.browse' , '$(file-directory) Browse...' ) , description : '' , data : undefined } ) ; folder = ( await context . ui . showQuickPick ( folderPicks , { placeHolder } ) ) . data ; } if ( folder ) { return folder ; } else { context . telemetry . properties . browse = 'true' ; return ( await context . ui . showOpenDialog ( options ) ) [ 0 ] ; } }