import * as vscode from 'vscode' ; import CommandWrapper from '../command-wrapper' ; import { Command } from '../commands/command' ; import { Logger } from '../types/logger' ; type UriParser = ( uri : string ) => vscode . Uri ; export type CommandType = 'TEXT_EDITOR' | 'GENERAL' ; export interface CommandItem { name : string ; type : CommandType ; command : Command ; } export default class CommandAdaptor { constructor ( private readonly commands , private readonly parseUri , private readonly logger ) { } async executeCommand ( name , uri1 , uri2 , title ) { return this . commands . executeCommand ( name , this . parseUri ( uri1 ) , this . parseUri ( uri2 ) , title ) ; } registerCommand ( cmd ) { const registerer = this . getCommandRegisterer ( cmd . type ) ; const command = new CommandWrapper ( cmd . name , cmd . command , this . logger ) ; return registerer ( cmd . name , command . execute , command ) ; } private getCommandRegisterer ( commandType ) { return commandType === 'TEXT_EDITOR' ? this . commands . registerTextEditorCommand : this . commands . registerCommand ; } }