Closed saidelike closed 3 months ago
console.info
and console.debug
have the same problem as console.log
.
console.error
and console.warn
don't have that problem.
console.error
andconsole.warn
don't have that problem.
Those write to stderr, not stdout, so they don't interfere with the RPC channel.
expected behavior: Calling console.log() from the node plugin should just log.
So our "monkey patching" of console.log
isn't working? https://github.com/neovim/node-client/issues/202#issuecomment-1959963711
So our "monkey patching" of
console.log
isn't working? #202 (comment)
That's my guess too.
const client = (await plugin.nvim) as NeovimClient; const ret = client.isApiReady; console.warn("isApiReady ", ret); // true console.log("This is sent to neovim");
Does the demo code in the readme also trigger the issue for you?
I don't see anywhere in our code where we're patching console.log
, so I think this hasn't worked for awhile. Unless winston does it implicitly (but doesn't seem so: https://github.com/winstonjs/winston/issues/309).
https://github.com/neovim/node-client/commit/2d4744757da98c977ac0dadfcc4298c68c50533f removed "sandboxing" and looks like it accidentally also removed the console.log
patching:
// Redirect console calls into logger
Object.keys(console).forEach((k: keyof Console) => {
if (k === 'log') {
sandbox.console.log = createDebugFunction(filename);
} else if (k in logger) {
sandbox.console[k] = logger[k];
}
});
Can you see if this patch fixes the issue?
diff --git a/packages/neovim/src/utils/logger.ts b/packages/neovim/src/utils/logger.ts
index 8461e96b222f..e3f7580eccdb 100644
--- a/packages/neovim/src/utils/logger.ts
+++ b/packages/neovim/src/utils/logger.ts
@@ -31,6 +31,19 @@ function setupWinstonLogger(): Logger {
logger.add(new winston.transports.Console({ silent: true }));
}
+ // Monkey-patch `console` so that it does not write to the RPC (stdio) channel.
+ Object.keys(console).forEach((k: keyof Console) => {
+ (console as any)[k] = function () {
+ (logger as any)[k === 'log' ? 'info' : k].apply(logger, arguments);
+ };
+ });
+
return logger;
}
Can you try https://github.com/neovim/node-client/pull/332 ?
0.5.1 was released, can you confirm it fixes your issue @saidelike
Nice I can confirm it works now!
problem
Calling console.log() from the node plugin sends the data to nvim process. Because of this, it actually crashes the nvim process.
expected behavior
Calling console.log() from the node plugin should just log.
details
for instance with the code:
I attach to nvim and set a breakpoint on the following line https://github.com/neovim/neovim/blob/a4290f462ed7dc81e17b09bd27877b106b24b6bd/src/nvim/msgpack_rpc/channel.c#L304
for instance I use this breakpoint on Windows. we can see below that nvim receives the data that we try to log with
console.log
. Also note that it doesn't receive the data that we log withconsole.warn
:At the end the problem I was describing in https://github.com/neovim/neovim/issues/23781#issuecomment-1971464708 was due to me using
console.log
...