Skip to content

Commit b70f894

Browse files
author
Orta
authored
Merge pull request microsoft#32668 from orta/fix_31209
Suppress console.log & others inside the TS Server runtime so that language service plugins don't accidentally use them and kill the server
2 parents 984956a + f8b7a05 commit b70f894

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/tsserver/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,4 +982,12 @@ namespace ts.server {
982982
if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
983983
ts.sys.tryEnableSourceMapsForHost();
984984
}
985+
986+
// Overwrites the current console messages to instead write to
987+
// the log. This is so that language service plugins which use
988+
// console.log don't break the message passing between tsserver
989+
// and the client
990+
console.log = (...args) => logger.msg(args.length === 1 ? args[0] : args.join(", "), Msg.Info);
991+
console.warn = (...args) => logger.msg(args.length === 1 ? args[0] : args.join(", "), Msg.Err);
992+
console.error = (...args) => logger.msg(args.length === 1 ? args[0] : args.join(", "), Msg.Err);
985993
}

0 commit comments

Comments
 (0)