import * as vscode from "vscode" ; import { display_method } from "./config/util" ; import { GitExtension , Repository } from "./config/git" ; import emojis from "./config/git_emoji_zh" ; export function activate ( context ) { let disposable = vscode . commands . registerCommand ( "extension.gitEmoji" , ( uri ? ) => { const git = getGitExtension ( ) ; if ( ! git ) { vscode . window . showErrorMessage ( "无法加载git插件!请先安装git插件!" ) ; return ; } const method_key = context . globalState . get ( "display_method" , "default" ) ; let items = emojis . map ( display_method [ method_key ] ) ; vscode . window . showQuickPick ( items ) . then ( function ( selected ) { if ( selected ) { vscode . commands . executeCommand ( "workbench.view.scm" ) ; if ( uri ) { let selectedRepository = git . repositories . find ( repository => { return repository . rootUri . path === uri . _rootUri . path ; } ) ; if ( selectedRepository ) { prefixCommit ( selectedRepository , selected . emoji ) ; } } else { for ( let repo of git . repositories ) { prefixCommit ( repo , selected . emoji ) ; } } } } ) ; } ) ; let label_switching = vscode . commands . registerCommand ( "extension.switching" , ( uri ? ) => { const items = [ ] ; for ( const key in display_method ) { items . push ( key ) ; } vscode . window . showQuickPick ( items ) . then ( res => { context . globalState . update ( "display_method" , res ) ; } ) ; } ) ; context . subscriptions . push ( disposable ) ; } function prefixCommit ( repository , prefix ) { repository . inputBox . value !== "" ? ( ( repository . inputBox . value = "" ) , ( repository . inputBox . value = `${ prefix }${ repository . inputBox . value }` ) ) : ( repository . inputBox . value = `${ prefix }${ repository . inputBox . value }` ) ; } function getGitExtension ( ) { const vscodeGit = vscode . extensions . getExtension < GitExtension > ( "vscode.git" ) ; const gitExtension = vscodeGit && vscodeGit . exports ; return gitExtension && gitExtension . getAPI ( 1 ) ; } export function deactivate ( ) { }