import { QuickPickItem } from 'vscode' ; import { LoadedNormalisationRule } from './types/normalisation-rule' ; import WindowAdaptor from './adaptors/window' ; interface NormalisationRuleQuickPickItem extends QuickPickItem { picked : boolean ; ruleIndex : number ; } export default class NormalisationRulePicker { constructor ( private readonly windowAdaptor ) { } async show ( rules ) { const items = this . convertToQuickPickItems ( rules ) ; const userSelection = await this . windowAdaptor . showQuickPick ( items ) ; const activeItems = userSelection || items . filter ( item => item . picked ) ; return this . convertToRules ( activeItems ) ; } private convertToQuickPickItems ( rules ) { return rules . map ( ( rule , index ) => ( { label : rule . name || '(no "name" set for this rule)' , picked : rule . active , ruleIndex : index , description : '' } ) ) ; } private convertToRules ( pickedItems ) { return pickedItems . map ( pickedItem => pickedItem . ruleIndex ) ; } }