提交 b9bc23bb 编写于 作者: M Matt Bierner

Only exec server call in try catch

上级 3331d725
......@@ -16,36 +16,29 @@ class TypeScriptFormattingProvider implements vscode.DocumentRangeFormattingEdit
private readonly formattingOptionsManager: FileConfigurationManager
) { }
private async doFormat(
public async provideDocumentRangeFormattingEdits(
document: vscode.TextDocument,
range: vscode.Range,
options: vscode.FormattingOptions,
args: Proto.FormatRequestArgs,
token: vscode.CancellationToken
): Promise<vscode.TextEdit[]> {
): Promise<vscode.TextEdit[] | undefined> {
const file = this.client.toPath(document.uri);
if (!file) {
return undefined;
}
await this.formattingOptionsManager.ensureConfigurationOptions(document, options, token);
let edits: Proto.CodeEdit[] | undefined;
try {
const args = typeConverters.Range.toFormattingRequestArgs(file, range);
const response = await this.client.execute('format', args, token);
if (response.body) {
return response.body.map(typeConverters.TextEdit.fromCodeEdit);
}
edits = response.body;
} catch {
// noop
}
return [];
}
public async provideDocumentRangeFormattingEdits(
document: vscode.TextDocument,
range: vscode.Range,
options: vscode.FormattingOptions,
token: vscode.CancellationToken
): Promise<vscode.TextEdit[]> {
const file = this.client.toPath(document.uri);
if (!file) {
return [];
}
const args = typeConverters.Range.toFormattingRequestArgs(file, range);
return this.doFormat(document, options, args, token);
return (edits || []).map(typeConverters.TextEdit.fromCodeEdit);
}
public async provideOnTypeFormattingEdits(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册