Fix exthost error and warn logging (#2366)

Previously anything that wasn't "log" such as "warn" would end up doing
`logger[logger.warn]`. Would have caught this if I hadn't used `any`...

Fixes #2364.
This commit is contained in:
Asher 2020-11-26 16:58:34 -06:00 committed by GitHub
parent eca4448877
commit ae65c83cbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2445,10 +2445,10 @@ index 0000000000000000000000000000000000000000..693174ee0d21353c3a08a42fd30eaad1
+} +}
diff --git a/src/vs/server/node/connection.ts b/src/vs/server/node/connection.ts diff --git a/src/vs/server/node/connection.ts b/src/vs/server/node/connection.ts
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..93062cadc627c61e0829c27a72894b81e6a0e039 index 0000000000000000000000000000000000000000..5c3caf4d12cbf9b7228699ec4fa40cb406aa6307
--- /dev/null --- /dev/null
+++ b/src/vs/server/node/connection.ts +++ b/src/vs/server/node/connection.ts
@@ -0,0 +1,171 @@ @@ -0,0 +1,189 @@
+import { field, Logger, logger } from '@coder/logger'; +import { field, Logger, logger } from '@coder/logger';
+import * as cp from 'child_process'; +import * as cp from 'child_process';
+import { VSBuffer } from 'vs/base/common/buffer'; +import { VSBuffer } from 'vs/base/common/buffer';
@ -2459,6 +2459,7 @@ index 0000000000000000000000000000000000000000..93062cadc627c61e0829c27a72894b81
+import { INativeEnvironmentService } from 'vs/platform/environment/common/environment'; +import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
+import { getNlsConfiguration } from 'vs/server/node/nls'; +import { getNlsConfiguration } from 'vs/server/node/nls';
+import { Protocol } from 'vs/server/node/protocol'; +import { Protocol } from 'vs/server/node/protocol';
+import { IExtHostReadyMessage } from 'vs/workbench/services/extensions/common/extensionHostProtocol';
+ +
+export abstract class Connection { +export abstract class Connection {
+ private readonly _onClose = new Emitter<void>(); + private readonly _onClose = new Emitter<void>();
@ -2520,6 +2521,19 @@ index 0000000000000000000000000000000000000000..93062cadc627c61e0829c27a72894b81
+ } + }
+} +}
+ +
+interface DisconnectedMessage {
+ type: 'VSCODE_EXTHOST_DISCONNECTED';
+}
+
+interface ConsoleMessage {
+ type: '__$console';
+ // See bootstrap-fork.js#L135.
+ severity: 'log' | 'warn' | 'error';
+ arguments: any[];
+}
+
+type ExtHostMessage = DisconnectedMessage | ConsoleMessage | IExtHostReadyMessage;
+
+export class ExtensionHostConnection extends Connection { +export class ExtensionHostConnection extends Connection {
+ private process?: cp.ChildProcess; + private process?: cp.ChildProcess;
+ private readonly logger: Logger; + private readonly logger: Logger;
@ -2596,11 +2610,15 @@ index 0000000000000000000000000000000000000000..93062cadc627c61e0829c27a72894b81
+ proc.stderr.setEncoding('utf8').on('data', (d) => this.logger.error(d)); + proc.stderr.setEncoding('utf8').on('data', (d) => this.logger.error(d));
+ } + }
+ +
+ proc.on('message', (event) => { + proc.on('message', (event: ExtHostMessage) => {
+ switch (event && event.type) { + switch (event.type) {
+ case '__$console': + case '__$console':
+ const severity = (<any>this.logger)[event.severity] || 'info'; + const fn = this.logger[event.severity === 'log' ? 'info' : event.severity];
+ (<any>this.logger)[severity]('console', field('arguments', event.arguments)); + if (fn) {
+ fn('console', field('arguments', event.arguments));
+ } else {
+ this.logger.error('Unexpected severity', field('event', event));
+ }
+ break; + break;
+ case 'VSCODE_EXTHOST_DISCONNECTED': + case 'VSCODE_EXTHOST_DISCONNECTED':
+ this.logger.trace('Going offline'); + this.logger.trace('Going offline');