import { spawn } from 'child_process' ; import path from 'path' ; import debounce from 'lodash/debounce' ; import { shellEnv , isDev , nvimCommand } from 'src/utils' ; import type { ChildProcessWithoutNullStreams } from 'child_process' ; const vvSourceCommand = ( appPath ? ) => appPath ? `source ${ path . join ( appPath , isDev ( './' , '../' ) , 'bin/vv.vim' ) }` : 'source bin/vv.vim' ; let nvimProcess ; const startNvimProcess = ( { args = [ ] , cwd , appPath , } = { } ) : ChildProcessWithoutNullStreams => { const env = shellEnv ( ) ; const nvimArgs = [ '--embed' , '--cmd' , vvSourceCommand ( appPath ) , ... args ] ; nvimProcess = spawn ( nvimCommand ( env ) , nvimArgs , { cwd , env } ) ; let errorStr = '' ; nvimProcess . stderr . pipe ( process . stdout ) ; nvimProcess . stderr . on ( 'data' , ( data ) => { errorStr += data . toString ( ) ; debounce ( ( ) => { if ( errorStr ) console . error ( errorStr ) ; errorStr = '' ; } , 10 ) ( ) ; } ) ; return nvimProcess ; } ; export default startNvimProcess ;