import * as vscode from 'vscode' ; import * as k8s from 'vscode-kubernetes-tools-api' ; import { Observable } from '../../node_modules/rxjs' ; export async function selectWorkspaceFolder ( placeHolder ? ) { const folders = vscode . workspace . workspaceFolders ; if ( ! folders || folders . length === 0 ) { vscode . window . showErrorMessage ( "This command requires an open folder" ) ; return undefined ; } if ( folders . length === 1 ) { return folders [ 0 ] ; } return await vscode . window . showWorkspaceFolderPick ( { placeHolder : placeHolder } ) ; } export async function selectQuickPick < T extends vscode . QuickPickItem > ( items , options ? ) { if ( items . length === 1 ) { return items [ 0 ] ; } return await vscode . window . showQuickPick ( items , options ) ; } export async function longRunning < T > ( title , action ) { const options = { location : vscode . ProgressLocation . Notification , title : title } ; return await vscode . window . withProgress ( options , ( _ ) => action ( ) ) ; } export interface ProgressUpdate { readonly type : 'update' ; readonly message : string ; } export interface ProgressComplete < T > { readonly type : 'complete' ; readonly value : T ; } export type ProgressStep < T > = ProgressUpdate | ProgressComplete < T > ; export async function longRunningWithMessages < T > ( title , progressSteps ) { const options = { location : vscode . ProgressLocation . Notification , title : title } ; function runAction ( progress , _token ) { const promise = new Promise < T > ( ( resolve , reject ) => { progressSteps . subscribe ( ( progressStep ) => { if ( progressStep . type === 'update' ) { if ( progressStep . message && progressStep . message . length > 0 ) { progress . report ( { message : progressStep . message } ) ; } } else if ( progressStep . type === 'complete' ) { resolve ( progressStep . value ) ; } } , ( error ) => reject ( error ) ) ; } ) ; return promise ; } return await vscode . window . withProgress ( options , runAction ) ; } export async function confirm ( text , confirmLabel ) { const choice = await vscode . window . showWarningMessage ( text , confirmLabel , 'Cancel' ) ; return choice === confirmLabel ; } export async function refreshInstallationExplorer ( ) { await vscode . commands . executeCommand ( "duffle.refreshInstallationExplorer" ) ; } export async function refreshBundleExplorer ( ) { await vscode . commands . executeCommand ( "duffle.refreshBundleExplorer" ) ; } export async function refreshRepoExplorer ( ) { await vscode . commands . executeCommand ( "duffle.refreshRepoExplorer" ) ; } export async function refreshCredentialExplorer ( ) { await vscode . commands . executeCommand ( "duffle.refreshCredentialExplorer" ) ; } export async function refreshKubernetesToolsViews ( ) { const cloudExplorer = await k8s . extension . cloudExplorer . v1 ; if ( cloudExplorer . available ) { cloudExplorer . api . refresh ( ) ; } const clusterExplorer = await k8s . extension . clusterExplorer . v1 ; if ( clusterExplorer . available ) { clusterExplorer . api . refresh ( ) ; } }