11import { EventEmitter } from 'node:events' ;
22
33import { Transport } from '../utils/transport' ;
4+ import { partialClone } from '../utils/util' ;
45import { Logger , getLogger } from '../utils/logger' ;
56import { VimValue } from '../types/VimValue' ;
67
@@ -22,8 +23,8 @@ const DO_REQUEST = Symbol('DO_REQUEST');
2223// i.e. a plugin that detaches will affect all plugins registered on host
2324// const EXCLUDED = ['nvim_buf_attach', 'nvim_buf_detach'];
2425
25- // Instead of dealing with multiple inheritance (or lackof), just extend EE
26- // Only the Neovim API class should use EE though
26+ // Instead of dealing with multiple inheritance (or lackof), just extend EventEmitter
27+ // Only the Neovim API class should use EventEmitter though
2728export class BaseApi extends EventEmitter {
2829 protected transport : Transport ;
2930
@@ -49,7 +50,6 @@ export class BaseApi extends EventEmitter {
4950
5051 this . setTransport ( transport ) ;
5152 this . data = data ;
52- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
5353 this . logger = logger || getLogger ( ) ;
5454 this . client = client ;
5555
@@ -73,7 +73,25 @@ export class BaseApi extends EventEmitter {
7373 [ DO_REQUEST ] = ( name : string , args : any [ ] = [ ] ) : Promise < any > =>
7474 new Promise ( ( resolve , reject ) => {
7575 this . transport . request ( name , args , ( err : any , res : any ) => {
76- this . logger . debug ( `response -> ${ name } : ${ res } ` ) ;
76+ if ( this . logger . level === 'debug' ) {
77+ // Avoid noisy logging of entire Buffer/Window/Tabpage.
78+ let logData : any ;
79+ try {
80+ logData =
81+ res && typeof res === 'object'
82+ ? partialClone (
83+ res ,
84+ 2 ,
85+ [ 'logger' , 'transport' , 'client' ] ,
86+ '[Object]'
87+ )
88+ : res ;
89+ } catch {
90+ logData = String ( res ) ;
91+ }
92+ this . logger . debug ( `response -> ${ name } : %O` , logData ) ;
93+ }
94+
7795 if ( err ) {
7896 reject ( new Error ( `${ name } : ${ err [ 1 ] } ` ) ) ;
7997 } else {
@@ -89,7 +107,7 @@ export class BaseApi extends EventEmitter {
89107 // Not possible for ExtType classes since they are only created after transport is ready
90108 await this . _isReady ;
91109
92- this . logger . debug ( `request -> ${ name } ` ) ;
110+ this . logger . debug ( `request -> ${ name } ` ) ;
93111
94112 return this [ DO_REQUEST ] ( name , args ) . catch ( err => {
95113 // XXX: Get a `*.ts stacktrace. If we re-throw `err` we get a `*.js` trace. tsconfig issue?
0 commit comments