Supress console.log & others inside the TS Server runtime so that language service plugins don't accidentally use them and kill the server - fixes #31209

This commit is contained in:
Orta Therox 2019-08-01 17:36:09 -04:00
parent 33f362abaf
commit f04c7ed833

View file

@ -970,4 +970,12 @@ namespace ts.server {
if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
ts.sys.tryEnableSourceMapsForHost();
}
// Overwrites the current console messages to instead write to
// the log. This is so that language service plugins which use
// console.log don't break the message passing between tsserver
// and the client
console.log = (msg) => logger.msg(msg, Msg.Info);
console.warn = (msg) => logger.msg(msg, Msg.Err);
console.error = (msg) => logger.msg(msg, Msg.Err);
}