import vscode = require ( 'vscode' ) ; let workspaceState ; export function getFromWorkspaceState ( key , defaultValue ? ) { if ( ! workspaceState ) { return defaultValue ; } return workspaceState . get ( key , defaultValue ) ; } export function updateWorkspaceState ( key , value ) { if ( ! workspaceState ) { return Promise . resolve ( ) ; } return workspaceState . update ( key , value ) ; } export function setWorkspaceState ( state ) { workspaceState = state ; } export function getWorkspaceState ( ) { return workspaceState ; } export function resetWorkspaceState ( ) { resetStateQuickPick ( workspaceState , updateWorkspaceState ) ; } export function getMementoKeys ( state ) { if ( ! state ) { return [ ] ; } if ( ( state as any ) . _value ) { const keys = Object . keys ( ( state as any ) . _value ) ; return keys . filter ( ( key ) => state . get ( key ) !== undefined ) ; } return [ ] ; } async function resetStateQuickPick ( state , updateFn ) { const items = await vscode . window . showQuickPick ( getMementoKeys ( state ) , { canPickMany : true , placeHolder : 'Select the keys to reset.' } ) ; resetItemsState ( items ! , updateFn ) ; } export function resetItemsState ( items , updateFn ) { if ( ! items ) { return ; } items . forEach ( ( item ) => updateFn ( item , undefined ) ) ; }