import { window , commands , TextEditor } from 'vscode' ; import { showErrorMessage , insertText , formatVar } from '../index' ; import { handleCursorInsert } from '../insertVariable' ; const { activeTextEditor , onDidChangeActiveTextEditor } = window ; let currentEditor ; export const insertLogStatement = context => { currentEditor = activeTextEditor ; onDidChangeActiveTextEditor ( editor => ( currentEditor = editor ) ) ; const insert = commands . registerTextEditorCommand ( 'consoleLog.insertLogStatement' , ( ) => handle ( context ) ) ; context . subscriptions . push ( insert ) ; } ; const handle = context => { const editor = window . activeTextEditor ; if ( ! editor ) { showErrorMessage ( ) ; return ; } const { selection } = editor ; const selectVariable = editor . document . getText ( selection ) ; if ( selectVariable ) { commands . executeCommand ( 'editor.action.insertLineAfter' ) . then ( ( ) => { const lineNumber = selection . end . line + 2 ; const logText = formatVar ( selectVariable , lineNumber ) ; insertText ( logText ) ; } ) ; } else { handleCursorInsert ( ) ; } } ;