import * as vscode from 'vscode' ; export function activate ( context ) { const configuredView = vscode . workspace . getConfiguration ( ) . get ( 'conf.view.showOnWindowOpen' ) ; switch ( configuredView ) { case 'explorer' : vscode . commands . executeCommand ( 'workbench.view.explorer' ) ; break ; case 'search' : vscode . commands . executeCommand ( 'workbench.view.search' ) ; break ; case 'scm' : vscode . commands . executeCommand ( 'workbench.view.scm' ) ; break ; case 'debug' : vscode . commands . executeCommand ( 'workbench.view.debug' ) ; break ; case 'extensions' : vscode . commands . executeCommand ( 'workbench.view.extensions' ) ; break ; } vscode . commands . registerCommand ( 'config.commands.configureViewOnWindowOpen' , async ( ) => { const value = await vscode . window . showQuickPick ( [ 'explorer' , 'search' , 'scm' , 'debug' , 'extensions' ] , { placeHolder : 'Select the view to show when opening a window.' } ) ; if ( vscode . workspace . workspaceFolders ) { const target = await vscode . window . showQuickPick ( [ { label : 'User' , description : 'User Settings' , target : vscode . ConfigurationTarget . Global } , { label : 'Workspace' , description : 'Workspace Settings' , target : vscode . ConfigurationTarget . Workspace } ] , { placeHolder : 'Select the view to show when opening a window.' } ) ; if ( value && target ) { await vscode . workspace . getConfiguration ( ) . update ( 'conf.view.showOnWindowOpen' , value , target . target ) ; } } else { await vscode . workspace . getConfiguration ( ) . update ( 'conf.view.showOnWindowOpen' , value , vscode . ConfigurationTarget . Global ) ; } } ) ; context . subscriptions . push ( vscode . workspace . onDidOpenTextDocument ( e => { const value = vscode . workspace . getConfiguration ( '' , e . uri ) . get ( 'conf.resource.insertEmptyLastLine' ) ; const matches = value ? value [ e . fileName ] : undefined ; if ( matches ) { vscode . window . showInformationMessage ( 'An empty line will be added to the document ' + e . fileName ) ; } } ) ) ; vscode . commands . registerCommand ( 'config.commands.configureEmptyLastLineCurrentFile' , async ( ) => { if ( vscode . window . activeTextEditor ) { const currentDocument = vscode . window . activeTextEditor . document ; const configuration = vscode . workspace . getConfiguration ( '' , currentDocument . uri ) ; const currentValue = configuration . get ( 'conf.resource.insertEmptyLastLine' , { } ) ; const target = vscode . workspace . workspaceFolders ? vscode . ConfigurationTarget . WorkspaceFolder : vscode . ConfigurationTarget . Global ; const value = { ... currentValue , ... { [ currentDocument . fileName ] : true } } ; await configuration . update ( 'conf.resource.insertEmptyLastLine' , value , target ) ; } } ) ; vscode . commands . registerCommand ( 'config.commands.configureEmptyLastLineFiles' , async ( ) => { const value = await vscode . window . showInputBox ( { prompt : 'Provide glob pattern of files to have empty last line.' } ) ; if ( vscode . workspace . workspaceFolders ) { const target = await vscode . window . showQuickPick ( [ { label : 'Application' , description : 'User Settings' , target : vscode . ConfigurationTarget . Global } , { label : 'Workspace' , description : 'Workspace Settings' , target : vscode . ConfigurationTarget . Workspace } , { label : 'Workspace Folder' , description : 'Workspace Folder Settings' , target : vscode . ConfigurationTarget . WorkspaceFolder } ] , { placeHolder : 'Select the target to which this setting should be applied' } ) ; if ( value && target ) { if ( target . target === vscode . ConfigurationTarget . WorkspaceFolder ) { const workspaceFolder = await vscode . window . showWorkspaceFolderPick ( { placeHolder : 'Pick Workspace Folder to which this setting should be applied' } ) ; if ( workspaceFolder ) { const configuration = vscode . workspace . getConfiguration ( '' , workspaceFolder . uri ) ; const currentValue = configuration . get < { } > ( 'conf.resource.insertEmptyLastLine' ) ; const newValue = { ... currentValue , ... { [ value ] : true } } ; await configuration . update ( 'conf.resource.insertEmptyLastLine' , newValue , target . target ) ; } } else { const configuration = vscode . workspace . getConfiguration ( ) ; const currentValue = configuration . get < { } > ( 'conf.resource.insertEmptyLastLine' ) ; const newValue = { ... currentValue , ... ( value ? { [ value ] : true } : { } ) } ; await vscode . workspace . getConfiguration ( ) . update ( 'conf.resource.insertEmptyLastLine' , newValue , target . target ) ; } } } else { const configuration = vscode . workspace . getConfiguration ( ) ; const currentValue = configuration . get < { } > ( 'conf.resource.insertEmptyLastLine' ) ; const newValue = { ... currentValue , ... ( value ? { [ value ] : true } : { } ) } ; await vscode . workspace . getConfiguration ( ) . update ( 'conf.resource.insertEmptyLastLine' , newValue , vscode . ConfigurationTarget . Global ) ; } } ) ; let statusSizeDisposable ; context . subscriptions . push ( vscode . workspace . onDidOpenTextDocument ( e => { if ( statusSizeDisposable ) { statusSizeDisposable . dispose ( ) ; } const showSize = vscode . workspace . getConfiguration ( '' , e ) . get ( 'conf.language.showSize' ) ; if ( showSize ) { statusSizeDisposable = vscode . window . setStatusBarMessage ( `${ e . getText ( ) . length }` ) ; } } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'config.commands.overrideLanguageValue' , async ( ) => { const languageId = await vscode . window . showInputBox ( { placeHolder : 'Enter the language id' } ) ; vscode . workspace . getConfiguration ( '' , { languageId : languageId ! } ) . update ( 'conf.language.showSize' , true , false , true ) ; } ) ) ; context . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( e => { if ( e . affectsConfiguration ( 'conf.resource.insertEmptyLastLine' ) ) { if ( vscode . window . activeTextEditor ) { const currentDocument = vscode . window . activeTextEditor . document ; const value = vscode . workspace . getConfiguration ( '' , currentDocument . uri ) . get ( 'conf.resource.insertEmptyLastLine' ) ; const matches = value [ currentDocument . fileName ] ; if ( matches ) { vscode . window . showInformationMessage ( 'An empty line will be added to the document ' + currentDocument . fileName ) ; } } } if ( e . affectsConfiguration ( 'conf.language.showSize' , vscode . window . activeTextEditor ?. document ) ) { } if ( e . affectsConfiguration ( 'conf.language.showSize' , { languageId : 'typescript' } ) ) { } } ) ) ; }