/**
 * collection of functions to show messages with actions in a consistent manner
 */ import * as vscode from 'vscode' ; export const TROUBLESHOOTING_URL = 'https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting' ; function _extractActionTitles ( actions ? ) { return actions ? actions . map ( ( a ) => a . title ) : [ ] ; } const doNothing = ( ) => { } ; export function _handleMessageActions ( actions ? ) { if ( ! actions || actions . length <= 0 ) { return doNothing ; } return ( action ? ) => { if ( ! action ) { return ; } const found = actions . filter ( ( a ) => a . title === action ) ; if ( found . length === 1 ) { found [ 0 ] . action ( ) ; } else { throw Error ( `expect exactly one matched action '${ action }' but found ${ found . length } match(es)` ) ; } } ; } export interface MessageAction { title : string ; action : ( ) => void ; } export function systemErrorMessage ( message , ... actions ) { vscode . window . showErrorMessage ( message , ... _extractActionTitles ( actions ) ) . then ( _handleMessageActions ( actions ) ) ; } export function systemWarningMessage ( message , ... actions ) { vscode . window . showWarningMessage ( message , ... _extractActionTitles ( actions ) ) . then ( _handleMessageActions ( actions ) ) ; } export const showTroubleshootingAction = { title : 'Help' , action : ( ) => vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( TROUBLESHOOTING_URL ) ) , } ;