Only exec server call in try catch

This commit is contained in:
Matt Bierner
2018-07-16 17:55:00 -07:00
parent 3331d725e5
commit b9bc23bb58

View File

@@ -16,36 +16,29 @@ class TypeScriptFormattingProvider implements vscode.DocumentRangeFormattingEdit
private readonly formattingOptionsManager: FileConfigurationManager
) { }
private async doFormat(
document: vscode.TextDocument,
options: vscode.FormattingOptions,
args: Proto.FormatRequestArgs,
token: vscode.CancellationToken
): Promise<vscode.TextEdit[]> {
await this.formattingOptionsManager.ensureConfigurationOptions(document, options, token);
try {
const response = await this.client.execute('format', args, token);
if (response.body) {
return response.body.map(typeConverters.TextEdit.fromCodeEdit);
}
} catch {
// noop
}
return [];
}
public async provideDocumentRangeFormattingEdits(
document: vscode.TextDocument,
range: vscode.Range,
options: vscode.FormattingOptions,
token: vscode.CancellationToken
): Promise<vscode.TextEdit[]> {
): Promise<vscode.TextEdit[] | undefined> {
const file = this.client.toPath(document.uri);
if (!file) {
return [];
return undefined;
}
await this.formattingOptionsManager.ensureConfigurationOptions(document, options, token);
let edits: Proto.CodeEdit[] | undefined;
try {
const args = typeConverters.Range.toFormattingRequestArgs(file, range);
return this.doFormat(document, options, args, token);
const response = await this.client.execute('format', args, token);
edits = response.body;
} catch {
// noop
}
return (edits || []).map(typeConverters.TextEdit.fromCodeEdit);
}
public async provideOnTypeFormattingEdits(