import { VimMode , HyperspaceCoordinates } from '../neovim/types' ; import { call , on , request } from './messaging/worker-client' ; import * as bufferSearch from '../services/buffer-search' ; import getWindowMetadata from './metadata' ; import { GitStatus } from './git' ; import * as git from './git' ; import nvim from './neovim-api' ; import '../services/mru-buffers' ; import '../services/watch-reload' ; const actions = new Map < string , ( args : any ) => void > ( ) ; const state = { instanceIsActive : true , } ; nvim . onStateChange ( ( nextState ) => call . nvimStateUpdate ( nextState ) ) ; git . onStatus ( ( status ) => call . gitStatus ( status ) ) ; git . onBranch ( ( onBranch ) => call . gitBranch ( onBranch ) ) ; on . nvimOption ( ( opt ) => nvim . readonlyOptions [ opt ] ) ; on . nvimGetHighlightByName ( ( name , isRgb ? ) => nvim . getHighlightByName ( name , isRgb ) ) ; on . showNeovimMessage ( request . showNeovimMessage ) ; on . showStatusBarMessage ( call . showStatusBarMessage ) ; on . instanceActiveStatus ( ( instanceIsActive ) => Object . assign ( state , { instanceIsActive } ) ) ; on . bufferSearch ( async ( file , query ) => bufferSearch . fuzzy ( file , query ) ) ; on . bufferSearchVisible ( async ( query ) => bufferSearch . fuzzyVisible ( query ) ) ; on . nvimJumpTo ( ( coords ) => nvim . jumpTo ( coords . line , coords . column , coords . path ) ) ; on . nvimExpr ( async ( expr ) => nvim . eval ( expr ) ) ; on . nvimFeedkeys ( ( keys , mode ) => nvim . feedKeys ( keys , mode , false ) ) ; on . nvimCall ( async ( name , args ) => nvim . call ( name , args ) ) ; on . nvimCommand ( async ( command ) => { try { await nvim . command ( command ) ; } catch ( e ) { console . error ( `Error running nvimCommand instance.ts: '${ e }'` ) ; } } ) ; on . nvimGetVar ( async ( key ) => Reflect . get ( nvim . g , key ) ) ; on . nvimGetKeymap ( async ( ) => nvim . getAndParseKeymap ( 'n' ) ) ; on . nvimGetColorByName ( async ( name ) => nvim . getColorByName ( name ) ) ; on . setNvimMode ( ( mode ) => Object . assign ( nvim . state , { mode } ) ) ; on . getBufferInfo ( async ( ) => nvim . listBuffersWithInfo ( ) ) ; on . getGitInfo ( async ( ) => git . getGitInfo ( ) ) ; on . getState ( async ( ) => ( { ... nvim . state } ) ) ; on . getWindowMetadata ( async ( ) => getWindowMetadata ( ) ) ; on . nvimSaveCursor ( async ( ) => ( await nvim . window ) . cursor ) ; on . nvimRestoreCursor ( async ( position ) => ( ( await nvim . window ) . cursor = [ position [ 0 ] , position [ 1 ] ] ) ) ; on . nvimHighlightSearchPattern ( async ( pattern , id ? ) => nvim . highlightSearchPattern ( pattern , id ) ) ; on . nvimRemoveHighlightSearch ( async ( id , pattern ? ) => nvim . removeHighlightSearch ( id , pattern ) ) ; on . onAction ( async ( name ) => { if ( ! actions . has ( name ) ) actions . set ( name , ( ... a ) => call . actionCalled ( name , a ) ) ; const cb = actions . get ( name ) ! ; nvim . onAction ( name , cb ) ; } ) ;