import { commands , Disposable , ExtensionContext , extensions } from 'vscode' ; import { GithubRemoteSourceProvider } from './remoteSourceProvider' ; import { GitExtension } from './typings/git' ; import { registerCommands } from './commands' ; import { GithubCredentialProviderManager } from './credentialProvider' ; import { DisposableStore } from './util' ; import { GithubPushErrorHandler } from './pushErrorHandler' ; import { GitBaseExtension } from './typings/git-base' ; import { GithubRemoteSourcePublisher } from './remoteSourcePublisher' ; export function activate ( context ) { context . subscriptions . push ( initializeGitBaseExtension ( ) ) ; context . subscriptions . push ( initializeGitExtension ( ) ) ; } function initializeGitBaseExtension ( ) { const disposables = new DisposableStore ( ) ; const initialize = ( ) => { try { const gitBaseAPI = gitBaseExtension . getAPI ( 1 ) ; disposables . add ( gitBaseAPI . registerRemoteSourceProvider ( new GithubRemoteSourceProvider ( ) ) ) ; } catch ( err ) { console . error ( 'Could not initialize GitHub extension' ) ; console . warn ( err ) ; } } ; const onDidChangeGitBaseExtensionEnablement = ( enabled ) => { if ( ! enabled ) { disposables . dispose ( ) ; } else { initialize ( ) ; } } ; const gitBaseExtension = extensions . getExtension < GitBaseExtension > ( 'vscode.git-base' ) ! . exports ; disposables . add ( gitBaseExtension . onDidChangeEnablement ( onDidChangeGitBaseExtensionEnablement ) ) ; onDidChangeGitBaseExtensionEnablement ( gitBaseExtension . enabled ) ; return disposables ; } function initializeGitExtension ( ) { const disposables = new DisposableStore ( ) ; let gitExtension = extensions . getExtension < GitExtension > ( 'vscode.git' ) ; const initialize = ( ) => { gitExtension ! . activate ( ) . then ( extension => { const onDidChangeGitExtensionEnablement = ( enabled ) => { if ( enabled ) { const gitAPI = extension . getAPI ( 1 ) ; disposables . add ( registerCommands ( gitAPI ) ) ; disposables . add ( new GithubCredentialProviderManager ( gitAPI ) ) ; disposables . add ( gitAPI . registerPushErrorHandler ( new GithubPushErrorHandler ( ) ) ) ; disposables . add ( gitAPI . registerRemoteSourcePublisher ( new GithubRemoteSourcePublisher ( gitAPI ) ) ) ; commands . executeCommand ( 'setContext' , 'git-base.gitEnabled' , true ) ; } else { disposables . dispose ( ) ; } } ; disposables . add ( extension . onDidChangeEnablement ( onDidChangeGitExtensionEnablement ) ) ; onDidChangeGitExtensionEnablement ( extension . enabled ) ; } ) ; } ; if ( gitExtension ) { initialize ( ) ; } else { const listener = extensions . onDidChange ( ( ) => { if ( ! gitExtension && extensions . getExtension < GitExtension > ( 'vscode.git' ) ) { gitExtension = extensions . getExtension < GitExtension > ( 'vscode.git' ) ; initialize ( ) ; listener . dispose ( ) ; } } ) ; disposables . add ( listener ) ; } return disposables ; }