1
1
import { EventEmitter } from 'node:events' ;
2
2
3
3
import { Transport } from '../utils/transport' ;
4
+ import { partialClone } from '../utils/util' ;
4
5
import { Logger , getLogger } from '../utils/logger' ;
5
6
import { VimValue } from '../types/VimValue' ;
6
7
@@ -22,8 +23,8 @@ const DO_REQUEST = Symbol('DO_REQUEST');
22
23
// i.e. a plugin that detaches will affect all plugins registered on host
23
24
// const EXCLUDED = ['nvim_buf_attach', 'nvim_buf_detach'];
24
25
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
27
28
export class BaseApi extends EventEmitter {
28
29
protected transport : Transport ;
29
30
@@ -49,7 +50,6 @@ export class BaseApi extends EventEmitter {
49
50
50
51
this . setTransport ( transport ) ;
51
52
this . data = data ;
52
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
53
53
this . logger = logger || getLogger ( ) ;
54
54
this . client = client ;
55
55
@@ -73,7 +73,25 @@ export class BaseApi extends EventEmitter {
73
73
[ DO_REQUEST ] = ( name : string , args : any [ ] = [ ] ) : Promise < any > =>
74
74
new Promise ( ( resolve , reject ) => {
75
75
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
+
77
95
if ( err ) {
78
96
reject ( new Error ( `${ name } : ${ err [ 1 ] } ` ) ) ;
79
97
} else {
@@ -89,7 +107,7 @@ export class BaseApi extends EventEmitter {
89
107
// Not possible for ExtType classes since they are only created after transport is ready
90
108
await this . _isReady ;
91
109
92
- this . logger . debug ( `request -> ${ name } ` ) ;
110
+ this . logger . debug ( `request -> ${ name } ` ) ;
93
111
94
112
return this [ DO_REQUEST ] ( name , args ) . catch ( err => {
95
113
// XXX: Get a `*.ts stacktrace. If we re-throw `err` we get a `*.js` trace. tsconfig issue?
0 commit comments