Add support for web TS Server logging over postMessage

For https://github.com/microsoft/TypeScript/pull/39656
This commit is contained in:
Matt Bierner
2020-11-11 17:39:05 -08:00
parent afcfc97316
commit 17c29f0b99

View File

@@ -3,10 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import type * as Proto from '../protocol';
import { TypeScriptServiceConfiguration } from '../utils/configuration';
import { memoize } from '../utils/memoize';
import { TsServerProcess, TsServerProcessKind } from './server';
const localize = nls.loadMessageBundle();
declare const Worker: any;
declare type Worker = any;
@@ -37,6 +43,11 @@ export class WorkerServerProcess implements TsServerProcess {
args: readonly string[],
) {
worker.addEventListener('message', (msg: any) => {
if (msg.data.type === 'log') {
this.output.appendLine(msg.data.body);
return;
}
for (const handler of this._onDataHandlers) {
handler(msg.data);
}
@@ -44,6 +55,11 @@ export class WorkerServerProcess implements TsServerProcess {
worker.postMessage(args);
}
@memoize
private get output(): vscode.OutputChannel {
return vscode.window.createOutputChannel(localize('channelName', 'TypeScript Server Log'));
}
write(serverRequest: Proto.Request): void {
this.worker.postMessage(serverRequest);
}