Simplify logging of TS request errors
Fixes #28095 Removes the manual error logging on client requests in favor of doing this automatically in the service client. Also fixes logging of canellation errors
This commit is contained in:
parent
4fce291653
commit
a757842135
13 changed files with 36 additions and 49 deletions
|
@ -56,8 +56,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider
|
|||
tree.childItems.forEach(item => this.walkNavTree(document, item, null, referenceableSpans));
|
||||
}
|
||||
return referenceableSpans.map(span => new ReferencesCodeLens(document.uri, filepath, span));
|
||||
}, (err: any) => {
|
||||
this.client.error(`'navtree' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -223,8 +223,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
|||
}
|
||||
|
||||
return completionItems;
|
||||
}, (err) => {
|
||||
this.client.error(`'completions' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
@ -264,8 +263,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
|||
}
|
||||
|
||||
return item;
|
||||
}, (err) => {
|
||||
this.client.error(`'completionEntryDetails' request failed with error.`, err);
|
||||
}, () => {
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ export default class TypeScriptDefinitionProviderBase {
|
|||
return new Location(resource, new Range(location.start.line - 1, location.start.offset - 1, location.end.line - 1, location.end.offset - 1));
|
||||
}
|
||||
}).filter(x => x !== null) as Location[];
|
||||
}, (error) => {
|
||||
this.client.error(`'${definitionType}' request failed with error.`, error);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -43,8 +43,7 @@ export default class TypeScriptDocumentHighlightProvider implements DocumentHigh
|
|||
});
|
||||
}
|
||||
return [];
|
||||
}, (err) => {
|
||||
this.client.error(`'occurrences' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
|
|||
}
|
||||
}
|
||||
return result;
|
||||
}, (err) => {
|
||||
this.client.error(`'navtree' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
} else {
|
||||
|
@ -65,12 +64,10 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
|
|||
response.body.forEach(item => TypeScriptDocumentSymbolProvider.convertNavBar(resource.uri, 0, foldingMap, result, item));
|
||||
}
|
||||
return result;
|
||||
}, (err) => {
|
||||
this.client.error(`'navbar' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static convertNavBar(resource: Uri, indent: number, foldingMap: ObjectMap<SymbolInformation>, bucket: SymbolInformation[], item: Proto.NavigationBarItem, containerLabel?: string): void {
|
||||
|
|
|
@ -136,8 +136,7 @@ export default class TypeScriptFormattingProvider implements DocumentRangeFormat
|
|||
} else {
|
||||
return [];
|
||||
}
|
||||
}, (err: any) => {
|
||||
this.client.error(`'format' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
});
|
||||
|
@ -195,8 +194,7 @@ export default class TypeScriptFormattingProvider implements DocumentRangeFormat
|
|||
}
|
||||
}
|
||||
return result;
|
||||
}, (err: any) => {
|
||||
this.client.error(`'formatonkey' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,8 +32,7 @@ export default class TypeScriptHoverProvider implements HoverProvider {
|
|||
new Range(data.start.line - 1, data.start.offset - 1, data.end.line - 1, data.end.offset - 1));
|
||||
}
|
||||
return undefined;
|
||||
}, (err) => {
|
||||
this.client.error(`'quickinfo' request failed with error.`, err);
|
||||
}, () => {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -41,8 +41,7 @@ export default class TypeScriptReferenceSupport implements ReferenceProvider {
|
|||
result.push(location);
|
||||
}
|
||||
return result;
|
||||
}, (err) => {
|
||||
this.client.error(`'references' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -49,8 +49,7 @@ export default class TypeScriptRenameProvider implements RenameProvider {
|
|||
});
|
||||
});
|
||||
return result;
|
||||
}, (err) => {
|
||||
this.client.error(`'rename' request failed with error.`, err);
|
||||
}, () => {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -64,8 +64,7 @@ export default class TypeScriptSignatureHelpProvider implements SignatureHelpPro
|
|||
});
|
||||
|
||||
return result;
|
||||
}, (err: any) => {
|
||||
this.client.error(`'signatureHelp' request failed with error.`, err);
|
||||
}, () => {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -77,8 +77,7 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
|
|||
}
|
||||
}
|
||||
return result;
|
||||
}, (err) => {
|
||||
this.client.error(`'navto' request failed with error.`, err);
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -74,9 +74,7 @@ export interface ITypescriptServiceClient {
|
|||
normalizePath(resource: Uri): string | null;
|
||||
asUrl(filepath: string): Uri;
|
||||
|
||||
info(message: string, data?: any): void;
|
||||
warn(message: string, data?: any): void;
|
||||
error(message: string, data?: any): void;
|
||||
|
||||
onProjectLanguageServiceStateChanged: Event<Proto.ProjectLanguageServiceStateEventBody>;
|
||||
onDidBeginInstallTypings: Event<Proto.BeginInstallTypesEventBody>;
|
||||
|
|
|
@ -889,14 +889,20 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
|||
};
|
||||
let result: Promise<any> = Promise.resolve(null);
|
||||
if (expectsResult) {
|
||||
let wasCancelled = false;
|
||||
result = new Promise<any>((resolve, reject) => {
|
||||
requestInfo.callbacks = { c: resolve, e: reject, start: Date.now() };
|
||||
if (token) {
|
||||
token.onCancellationRequested(() => {
|
||||
wasCancelled = true;
|
||||
this.tryCancelRequest(request.seq);
|
||||
resolve(undefined);
|
||||
});
|
||||
}
|
||||
}).catch((err: any) => {
|
||||
if (!wasCancelled) {
|
||||
this.error(`'${command}' request failed with error.`, err);
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
requestInfo.promise = result;
|
||||
|
@ -933,28 +939,26 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
|||
}
|
||||
|
||||
private tryCancelRequest(seq: number): boolean {
|
||||
if (this.requestQueue.tryCancelPendingRequest(seq)) {
|
||||
this.tracer.logTrace(`TypeScript Service: canceled request with sequence number ${seq}`);
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
if (this.requestQueue.tryCancelPendingRequest(seq)) {
|
||||
this.tracer.logTrace(`TypeScript Service: canceled request with sequence number ${seq}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.apiVersion.has222Features() && this.cancellationPipeName) {
|
||||
this.tracer.logTrace(`TypeScript Service: trying to cancel ongoing request with sequence number ${seq}`);
|
||||
try {
|
||||
if (this.apiVersion.has222Features() && this.cancellationPipeName) {
|
||||
this.tracer.logTrace(`TypeScript Service: trying to cancel ongoing request with sequence number ${seq}`);
|
||||
fs.writeFileSync(this.cancellationPipeName + seq, '');
|
||||
return true;
|
||||
} catch (e) {
|
||||
// noop
|
||||
} finally {
|
||||
const p = this.callbacks.fetch(seq);
|
||||
if (p) {
|
||||
p.e(new Error(`Cancelled Request ${seq}`));
|
||||
}
|
||||
}
|
||||
|
||||
this.tracer.logTrace(`TypeScript Service: tried to cancel request with sequence number ${seq}. But request got already delivered.`);
|
||||
return false;
|
||||
} finally {
|
||||
const p = this.callbacks.fetch(seq);
|
||||
if (p) {
|
||||
p.e(new Error(`Cancelled Request ${seq}`));
|
||||
}
|
||||
}
|
||||
|
||||
this.tracer.logTrace(`TypeScript Service: tried to cancel request with sequence number ${seq}. But request got already delivered.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
private dispatchMessage(message: Proto.Message): void {
|
||||
|
|
Loading…
Reference in a new issue