Skip to content

Commit eafed3c

Browse files
mjbvzmeganrogge
authored andcommitted
Add support for web TS Server logging over postMessage
For microsoft/TypeScript#39656
1 parent df06fe8 commit eafed3c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import * as vscode from 'vscode';
7+
import * as nls from 'vscode-nls';
68
import type * as Proto from '../protocol';
79
import { TypeScriptServiceConfiguration } from '../utils/configuration';
10+
import { memoize } from '../utils/memoize';
811
import { TsServerProcess, TsServerProcessKind } from './server';
912

13+
14+
const localize = nls.loadMessageBundle();
15+
1016
declare const Worker: any;
1117
declare type Worker = any;
1218

@@ -37,13 +43,23 @@ export class WorkerServerProcess implements TsServerProcess {
3743
args: readonly string[],
3844
) {
3945
worker.addEventListener('message', (msg: any) => {
46+
if (msg.data.type === 'log') {
47+
this.output.appendLine(msg.data.body);
48+
return;
49+
}
50+
4051
for (const handler of this._onDataHandlers) {
4152
handler(msg.data);
4253
}
4354
});
4455
worker.postMessage(args);
4556
}
4657

58+
@memoize
59+
private get output(): vscode.OutputChannel {
60+
return vscode.window.createOutputChannel(localize('channelName', 'TypeScript Server Log'));
61+
}
62+
4763
write(serverRequest: Proto.Request): void {
4864
this.worker.postMessage(serverRequest);
4965
}

0 commit comments

Comments
 (0)