import * as vscode from 'vscode' ; let myStatusBarItem ; export function activate ( { subscriptions } ) { const myCommandId = 'sample.showSelectionCount' ; subscriptions . push ( vscode . commands . registerCommand ( myCommandId , ( ) => { const n = getNumberOfSelectedLines ( vscode . window . activeTextEditor ) ; vscode . window . showInformationMessage ( `Yeah, ${ n } line(s) selected... Keep going!` ) ; } ) ) ; myStatusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right , 100 ) ; myStatusBarItem . command = myCommandId ; subscriptions . push ( myStatusBarItem ) ; subscriptions . push ( vscode . window . onDidChangeActiveTextEditor ( updateStatusBarItem ) ) ; subscriptions . push ( vscode . window . onDidChangeTextEditorSelection ( updateStatusBarItem ) ) ; updateStatusBarItem ( ) ; } function updateStatusBarItem ( ) { const n = getNumberOfSelectedLines ( vscode . window . activeTextEditor ) ; if ( n > 0 ) { myStatusBarItem . text = `$(megaphone) ${ n } line(s) selected` ; myStatusBarItem . show ( ) ; } else { myStatusBarItem . hide ( ) ; } } function getNumberOfSelectedLines ( editor ) { let lines = 0 ; if ( editor ) { lines = editor . selections . reduce ( ( prev , curr ) => prev + ( curr . end . line - curr . start . line ) , 0 ) ; } return lines ; }