import * as vscode from 'vscode' ; import { Logger } from './logger' ; import { getMarkdownExtensionContributions } from './markdownExtensions' ; import { loadDefaultTelemetryReporter } from './telemetryReporter' ; import { PreviewDocumentContentProvider } from './previewDocumentContentProvider' ; export function activate ( context ) { console . log ( 'Congratulations, Preview Extension Startup' ) ; const telemetryReporter = loadDefaultTelemetryReporter ( ) ; context . subscriptions . push ( telemetryReporter ) ; const contributions = getMarkdownExtensionContributions ( context ) ; context . subscriptions . push ( contributions ) ; const logger = new Logger ( ) ; logger . log ( 'Congratulations, Preview Extension Startup' ) ; const PROVIDER = PreviewDocumentContentProvider . getInstance ( ) ; vscode . workspace . onDidChangeTextDocument ( ( e ) => { if ( ! ! e && ! ! vscode . window . activeTextEditor && e . document === vscode . window . activeTextEditor . document ) { PROVIDER . update ( ) ; } } ) ; vscode . window . onDidChangeTextEditorSelection ( ( e ) => { if ( ! ! e && ! ! e . textEditor && ( e . textEditor === vscode . window . activeTextEditor ) ) { PROVIDER . update ( ) ; } } ) ; const providerDisposable = vscode . Disposable . from ( registerPreviewDocumentContentProvider ( ) ) ; function registerPreviewDocumentContentProvider ( ) { return vscode . workspace . registerTextDocumentContentProvider ( PreviewDocumentContentProvider . previewScheme , PROVIDER ) ; } function sendPreviewCommand ( displayColumn , editor ) { PROVIDER . sendPreviewCommand ( displayColumn , editor ) . catch ( function ( error ) { console . error ( "we got an error: " + error ) ; } ) ; return ; } function sendCloseviewCommand ( ) { return vscode . commands . executeCommand ( "workbench.action.closeActiveEditor" ) . then ( ( ) => { } , ( reason ) => { console . warn ( reason ) ; vscode . window . showErrorMessage ( reason ) ; } ) ; } function getSpiltColumn ( ) { if ( ! vscode . window . activeTextEditor ) { return vscode . ViewColumn . Beside ; } let displayColumn ; switch ( vscode . window . activeTextEditor . viewColumn ) { case vscode . ViewColumn . One : displayColumn = vscode . ViewColumn . Two ; break ; case vscode . ViewColumn . Two : case vscode . ViewColumn . Three : displayColumn = vscode . ViewColumn . Three ; break ; case undefined : displayColumn = vscode . ViewColumn . Beside ; break ; default : displayColumn = vscode . window . activeTextEditor . viewColumn ; break ; } return displayColumn ; } let previewDisposable = vscode . commands . registerCommand ( 'preview.showPreview' , ( ) => { let e = vscode . window . activeTextEditor ; if ( ! e ) { return sendCloseviewCommand ( ) ; } return sendPreviewCommand ( vscode . ViewColumn . Active , e ) ; } ) ; let previewToSideDisposable = vscode . commands . registerCommand ( 'preview.showPreviewToSide' , ( ) => { let e = vscode . window . activeTextEditor ; if ( ! e ) { return sendCloseviewCommand ( ) ; } let displayColumn = getSpiltColumn ( ) ; return sendPreviewCommand ( displayColumn , e ) ; } ) ; context . subscriptions . push ( previewDisposable , previewToSideDisposable , providerDisposable ) ; } export function deactivate ( ) { console . log ( "Preview Extension Shutdown" ) ; }