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

Use await

上级 d6caa2d4
......@@ -75,28 +75,30 @@ export class TypeScriptFormattingProvider implements DocumentRangeFormattingEdit
if (!filepath) {
return [];
}
await this.formattingOptionsManager.ensureFormatOptions(document, options, token);
const args: Proto.FormatOnKeyRequestArgs = {
file: filepath,
line: position.line + 1,
offset: position.character + 1,
key: ch
};
await this.formattingOptionsManager.ensureFormatOptions(document, options, token);
return this.client.execute('formatonkey', args, token).then((response): TextEdit[] => {
let edits = response.body;
let result: TextEdit[] = [];
try {
const response = await this.client.execute('formatonkey', args, token);
const edits = response.body;
const result: TextEdit[] = [];
if (!edits) {
return result;
}
for (const edit of edits) {
let textEdit = this.codeEdit2SingleEditOperation(edit);
let range = textEdit.range;
const textEdit = this.codeEdit2SingleEditOperation(edit);
const range = textEdit.range;
// Work around for https://github.com/Microsoft/TypeScript/issues/6700.
// Check if we have an edit at the beginning of the line which only removes white spaces and leaves
// an empty line. Drop those edits
if (range.start.character === 0 && range.start.line === range.end.line && textEdit.newText === '') {
let lText = document.lineAt(range.start.line).text;
const lText = document.lineAt(range.start.line).text;
// If the edit leaves something on the line keep the edit (note that the end character is exclusive).
// Keep it also if it removes something else than whitespace
if (lText.trim().length > 0 || lText.length > range.end.character) {
......@@ -107,9 +109,10 @@ export class TypeScriptFormattingProvider implements DocumentRangeFormattingEdit
}
}
return result;
}, () => {
return [];
});
} catch {
// noop
}
return [];
}
private codeEdit2SingleEditOperation(edit: Proto.CodeEdit): TextEdit {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册