mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Add error handler for reader
This commit is contained in:
@@ -328,7 +328,9 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
|
||||
private logTrace(message: string, data?: any): void {
|
||||
this.logger.logLevel('Trace', message, data);
|
||||
if (this.trace !== Trace.Off) {
|
||||
this.logger.logLevel('Trace', message, data);
|
||||
}
|
||||
}
|
||||
|
||||
public logTelemetry(eventName: string, properties?: { [prop: string]: string }) {
|
||||
@@ -464,13 +466,14 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
let value = process.env.TSS_DEBUG;
|
||||
if (value) {
|
||||
let port = parseInt(value);
|
||||
const port = parseInt(value);
|
||||
if (!isNaN(port)) {
|
||||
this.info(`TSServer started in debug mode using port ${port}`);
|
||||
options.execArgv = [`--debug=${port}`];
|
||||
}
|
||||
}
|
||||
let args: string[] = [];
|
||||
|
||||
const args: string[] = [];
|
||||
if (this.apiVersion.has206Features()) {
|
||||
args.push('--useSingleInferredProject');
|
||||
if (workspace.getConfiguration().get<boolean>('typescript.disableAutomaticTypeAcquisition', false)) {
|
||||
@@ -540,9 +543,12 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
this.serviceExited(true);
|
||||
});
|
||||
this.reader = new Reader<Proto.Response>(childProcess.stdout, (msg) => {
|
||||
this.dispatchMessage(msg);
|
||||
});
|
||||
|
||||
this.reader = new Reader<Proto.Response>(
|
||||
childProcess.stdout,
|
||||
(msg) => { this.dispatchMessage(msg); },
|
||||
error => { this.error('ReaderError', error); });
|
||||
|
||||
this._onReady.resolve();
|
||||
resolve(childProcess);
|
||||
this.serviceStarted(resendModels);
|
||||
@@ -759,7 +765,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
});
|
||||
this.callbacks = Object.create(null);
|
||||
if (restart) {
|
||||
let diff = Date.now() - this.lastStart;
|
||||
const diff = Date.now() - this.lastStart;
|
||||
this.numberRestarts++;
|
||||
let startService = true;
|
||||
if (this.numberRestarts > 5) {
|
||||
@@ -902,17 +908,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
for (let i = 0; i < this.requestQueue.length; i++) {
|
||||
if (this.requestQueue[i].request.seq === seq) {
|
||||
this.requestQueue.splice(i, 1);
|
||||
if (this.trace !== Trace.Off) {
|
||||
this.logTrace(`TypeScript Service: canceled request with sequence number ${seq}`);
|
||||
}
|
||||
this.logTrace(`TypeScript Service: canceled request with sequence number ${seq}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.apiVersion.has222Features() && this.cancellationPipeName) {
|
||||
if (this.trace !== Trace.Off) {
|
||||
this.logTrace(`TypeScript Service: trying to cancel ongoing request with sequence number ${seq}`);
|
||||
}
|
||||
this.logTrace(`TypeScript Service: trying to cancel ongoing request with sequence number ${seq}`);
|
||||
try {
|
||||
fs.writeFileSync(this.cancellationPipeName + seq, '');
|
||||
return true;
|
||||
@@ -921,17 +923,15 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
}
|
||||
|
||||
if (this.trace !== Trace.Off) {
|
||||
this.logTrace(`TypeScript Service: tried to cancel request with sequence number ${seq}. But request got already delivered.`);
|
||||
}
|
||||
this.logTrace(`TypeScript Service: tried to cancel request with sequence number ${seq}. But request got already delivered.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
private dispatchMessage(message: Proto.Message): void {
|
||||
try {
|
||||
if (message.type === 'response') {
|
||||
let response: Proto.Response = <Proto.Response>message;
|
||||
let p = this.callbacks[response.request_seq];
|
||||
const response: Proto.Response = message as Proto.Response;
|
||||
const p = this.callbacks[response.request_seq];
|
||||
if (p) {
|
||||
this.traceResponse(response, p.start);
|
||||
delete this.callbacks[response.request_seq];
|
||||
@@ -943,7 +943,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
}
|
||||
} else if (message.type === 'event') {
|
||||
let event: Proto.Event = <Proto.Event>message;
|
||||
const event: Proto.Event = <Proto.Event>message;
|
||||
this.traceEvent(event);
|
||||
if (event.event === 'syntaxDiag') {
|
||||
this.host.syntaxDiagnosticsReceived(event as Proto.DiagnosticEvent);
|
||||
|
||||
@@ -96,7 +96,11 @@ export class Reader<T> {
|
||||
private readonly buffer: ProtocolBuffer;
|
||||
private nextMessageLength: number;
|
||||
|
||||
public constructor(readable: stream.Readable, callback: ICallback<T>) {
|
||||
public constructor(
|
||||
readable: stream.Readable,
|
||||
callback: ICallback<T>,
|
||||
private readonly onError: (error: any) => void = () => ({})
|
||||
) {
|
||||
this.readable = readable;
|
||||
this.buffer = new ProtocolBuffer();
|
||||
this.callback = callback;
|
||||
@@ -107,21 +111,25 @@ export class Reader<T> {
|
||||
}
|
||||
|
||||
private onLengthData(data: Buffer): void {
|
||||
this.buffer.append(data);
|
||||
while (true) {
|
||||
if (this.nextMessageLength === -1) {
|
||||
this.nextMessageLength = this.buffer.tryReadContentLength();
|
||||
try {
|
||||
this.buffer.append(data);
|
||||
while (true) {
|
||||
if (this.nextMessageLength === -1) {
|
||||
this.nextMessageLength = this.buffer.tryReadContentLength();
|
||||
if (this.nextMessageLength === -1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const msg = this.buffer.tryReadContent(this.nextMessageLength);
|
||||
if (msg === null) {
|
||||
return;
|
||||
}
|
||||
this.nextMessageLength = -1;
|
||||
const json = JSON.parse(msg);
|
||||
this.callback(json);
|
||||
}
|
||||
const msg = this.buffer.tryReadContent(this.nextMessageLength);
|
||||
if (msg === null) {
|
||||
return;
|
||||
}
|
||||
this.nextMessageLength = -1;
|
||||
let json = JSON.parse(msg);
|
||||
this.callback(json);
|
||||
} catch (e) {
|
||||
this.onError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user